Implementation:Lance format Lance Java DynamicContextProvider
| Knowledge Sources | |
|---|---|
| Domains | Java_SDK, Dataset_Management |
| Last Updated | 2026-02-08 19:33 GMT |
Overview
Description
The DynamicContextProvider interface defines a contract for supplying dynamic per-request context to Lance namespace operations. Implementations can generate context (such as authentication headers or request tracing metadata) based on the specific operation being performed and the target object.
For RestNamespace integrations, context keys prefixed with headers. are automatically converted to HTTP headers by stripping the prefix. For example, the key "headers.Authorization" becomes the Authorization HTTP header. Keys without this prefix are ignored for HTTP headers but may be used for other purposes.
The provider is called synchronously before each namespace operation and implementations must be thread-safe as multiple operations may execute concurrently.
Usage
Implement DynamicContextProvider to inject authentication tokens, request IDs, or other per-request metadata into namespace operations. Pass the provider during namespace initialization. This is essential for secured deployments where tokens must be refreshed per request.
Code Reference
Source Location
java/src/main/java/org/lance/namespace/DynamicContextProvider.java
Signature
public interface DynamicContextProvider {
Map<String, String> provideContext(String operation, String objectId);
}
Import
import org.lance.namespace.DynamicContextProvider;
I/O Contract
| Parameter | Type | Required | Description |
|---|---|---|---|
| operation | String |
Yes | The namespace operation name (e.g., "list_tables", "describe_table", "create_namespace")
|
| objectId | String |
Yes | The object identifier in delimited form (e.g., "workspace$table_name")
|
| Return | Type | Description |
|---|---|---|
| provideContext() | Map<String, String> |
Context key-value pairs. Keys with "headers." prefix become HTTP headers. Must not return null; return empty map if no context is needed.
|
Usage Examples
// Implement a context provider with auth and tracing headers
public class MyContextProvider implements DynamicContextProvider {
@Override
public Map<String, String> provideContext(String operation, String objectId) {
Map<String, String> context = new HashMap<>();
context.put("headers.Authorization", "Bearer " + getAuthToken());
context.put("headers.X-Request-Id", UUID.randomUUID().toString());
return context;
}
}
// Use with DirectoryNamespace
DynamicContextProvider provider = new MyContextProvider();
Map<String, String> properties = Map.of("root", "/path/to/data");
DirectoryNamespace namespace = new DirectoryNamespace();
namespace.initialize(properties, allocator, provider);
// Use with RestNamespace
Map<String, String> restProps = Map.of("uri", "https://api.example.com");
RestNamespace restNamespace = new RestNamespace();
restNamespace.initialize(restProps, provider);
Related Pages
- Lance_format_Lance_Java_RestAdapter -- REST adapter that exposes namespace backends via REST API
- Lance_format_Lance_Java_NamespaceStorageOptions -- Storage options provider backed by namespace operations
- Lance_format_Lance_Java_StorageOptionsProvider -- Interface for cloud storage credential provisioning