Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class SparkTable implements Table, SupportsRead {
private final Column[] columns;
private final Transform[] partitionTransforms;
private final Optional<CatalogTable> catalogTable;
private final TableContext tableContext;

/**
* Creates a SparkTable from a filesystem path without a catalog table.
Expand All @@ -67,7 +68,7 @@ public class SparkTable implements Table, SupportsRead {
* @throws NullPointerException if identifier or tablePath is null
*/
public SparkTable(Identifier identifier, String tablePath) {
this(identifier, tablePath, Collections.emptyMap(), Optional.empty());
this(identifier, tablePath, Collections.emptyMap(), Optional.empty(), TableContext.empty());
}

/**
Expand All @@ -79,7 +80,12 @@ public SparkTable(Identifier identifier, String tablePath) {
* @throws NullPointerException if identifier or tablePath is null
*/
public SparkTable(Identifier identifier, String tablePath, Map<String, String> options) {
this(identifier, tablePath, options, Optional.empty());
this(identifier, tablePath, options, Optional.empty(), TableContext.empty());
}

public SparkTable(
Identifier identifier, String tablePath, Map<String, String> options, TableContext context) {
this(identifier, tablePath, options, Optional.empty(), context);
}

/**
Expand All @@ -92,11 +98,20 @@ public SparkTable(Identifier identifier, String tablePath, Map<String, String> o
* @param options user-provided options to override catalog properties
*/
public SparkTable(Identifier identifier, CatalogTable catalogTable, Map<String, String> options) {
this(identifier, catalogTable, options, TableContext.empty());
}

public SparkTable(
Identifier identifier,
CatalogTable catalogTable,
Map<String, String> options,
TableContext tableContext) {
this(
identifier,
getDecodedPath(requireNonNull(catalogTable, "catalogTable is null").location()),
options,
Optional.of(catalogTable));
Optional.of(catalogTable),
tableContext);
}

/**
Expand All @@ -115,9 +130,11 @@ private SparkTable(
Identifier identifier,
String tablePath,
Map<String, String> userOptions,
Optional<CatalogTable> catalogTable) {
Optional<CatalogTable> catalogTable,
TableContext tableContext) {
this.identifier = requireNonNull(identifier, "identifier is null");
this.catalogTable = catalogTable;
this.tableContext = requireNonNull(tableContext, "tableContext is null");
// Merge options: file system options from catalog + user options (user takes precedence)
// This follows the same pattern as DeltaTableV2 in delta-spark
Map<String, String> merged = new HashMap<>();
Expand Down Expand Up @@ -197,6 +214,10 @@ public Optional<CatalogTable> getCatalogTable() {
return catalogTable;
}

public TableContext tableContext() {
return tableContext;
}

@Override
public String name() {
return identifier.name();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.delta.kernel.spark.table;

import static java.util.Objects.requireNonNull;

import io.delta.kernel.spark.unity.UnityCatalogClientFactory;
import java.util.Optional;

/**
* Encapsulates optional metadata associated with a {@link SparkTable}.
*
* <p>The context is intentionally lightweight; it currently carries Unity Catalog client state when
* available and can be extended with additional table-specific wiring over time.
*/
public final class TableContext {

private final Optional<UnityCatalogClientFactory.UnityCatalogClient> unityCatalogClient;

private TableContext(Optional<UnityCatalogClientFactory.UnityCatalogClient> unityCatalogClient) {
this.unityCatalogClient =
requireNonNull(unityCatalogClient, "unityCatalogClient optional must be non-null");
}

public static TableContext empty() {
return new TableContext(Optional.empty());
}

public static TableContext withUnityCatalogClient(
UnityCatalogClientFactory.UnityCatalogClient unityCatalogClient) {
requireNonNull(unityCatalogClient, "unityCatalogClient is null");
return new TableContext(Optional.of(unityCatalogClient));
}

public Optional<UnityCatalogClientFactory.UnityCatalogClient> unityCatalogClient() {
return unityCatalogClient;
}
}
Loading
Loading