Skip to content
Open
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
dbe3c19
update methods and testS
TimothyW553 Nov 12, 2025
ac042af
delete workspace
TimothyW553 Nov 12, 2025
9ca1793
delete
TimothyW553 Nov 12, 2025
e3fcc41
change to catalogtable
TimothyW553 Nov 11, 2025
776ed69
add tests
TimothyW553 Nov 12, 2025
418b9bd
fmt
TimothyW553 Nov 12, 2025
e926066
test fix
TimothyW553 Nov 13, 2025
d443640
storage props
TimothyW553 Nov 14, 2025
d1684da
merge props
TimothyW553 Nov 17, 2025
0ca9b4c
address comments
TimothyW553 Nov 17, 2025
ee36547
remove private method test
TimothyW553 Nov 18, 2025
906643b
null check for storage properties
TimothyW553 Nov 18, 2025
71c62f3
Restore UC connection utils after rebase
TimothyW553 Dec 2, 2025
e524c60
clean up...
TimothyW553 Dec 2, 2025
b79ff29
Restore UC connection info utils and add SparkUnityCatalogUtils suite
TimothyW553 Dec 2, 2025
816e596
Update tests
TimothyW553 Dec 2, 2025
a5d745a
spark
TimothyW553 Dec 2, 2025
9d313c9
Clean up test utils and refactor
TimothyW553 Dec 2, 2025
1ba9177
revert DeltaSQLConfV2.scala
TimothyW553 Dec 2, 2025
c6d7e67
remove npe tests
TimothyW553 Dec 2, 2025
fc614cb
remove more npe
TimothyW553 Dec 2, 2025
2d333d3
Centralize utils
TimothyW553 Dec 4, 2025
7dc4549
fmt
TimothyW553 Dec 4, 2025
b2e39c8
FMT
TimothyW553 Dec 4, 2025
0423386
Address comments - remove unecessary wrappers and add logging
TimothyW553 Dec 4, 2025
7717995
Address comments - remove unecessary wrappers and add logging
TimothyW553 Dec 4, 2025
9cad0ba
Add wrapper for map
TimothyW553 Dec 4, 2025
a294801
use SharedSparkSession
TimothyW553 Dec 4, 2025
f43a198
fix tests
TimothyW553 Dec 4, 2025
d4f0c0f
fix tests
TimothyW553 Dec 4, 2025
0a58d48
annotate constant params
TimothyW553 Dec 5, 2025
94303b3
annotate constant params
TimothyW553 Dec 5, 2025
4275b56
Rename and follow naming conventions
TimothyW553 Dec 8, 2025
ad25296
Rename and follow naming conventions
TimothyW553 Dec 8, 2025
254b3f5
update context
TimothyW553 Dec 9, 2025
07f3b5b
rename base utils
TimothyW553 Dec 10, 2025
2bee750
Update tests
TimothyW553 Dec 2, 2025
64e5cda
Clean up test utils and refactor
TimothyW553 Dec 2, 2025
bb9fe06
Centralize utils
TimothyW553 Dec 4, 2025
1615a27
FMT
TimothyW553 Dec 4, 2025
c069296
Address comments - remove unecessary wrappers and add logging
TimothyW553 Dec 4, 2025
f4dab6c
Address comments - remove unecessary wrappers and add logging
TimothyW553 Dec 4, 2025
8588477
fix tests
TimothyW553 Dec 4, 2025
20c631b
annotate constant params
TimothyW553 Dec 5, 2025
f032bc4
Rename and follow naming conventions
TimothyW553 Dec 8, 2025
15ddabf
Rename and follow naming conventions
TimothyW553 Dec 8, 2025
ca28e0d
wireframe
TimothyW553 Dec 9, 2025
984e458
rename to UCManagedTableSnapshotManager
TimothyW553 Dec 10, 2025
63e0f90
reword javadocs
TimothyW553 Dec 10, 2025
094db22
[Kernel-Spark][DSv2] Implement UCManagedSnapshotManager operations us…
TimothyW553 Dec 9, 2025
10da4a2
annotate constants
TimothyW553 Dec 9, 2025
043f3c1
scala and java tests
TimothyW553 Dec 10, 2025
2767fec
scala and java tests
TimothyW553 Dec 10, 2025
0c22e3a
Remove engine construction and update to being passed in as a param
TimothyW553 Dec 10, 2025
7a36ab2
Remove tests for impl
TimothyW553 Dec 10, 2025
197efc8
unformat
TimothyW553 Dec 11, 2025
7f40d83
remove impl oops
TimothyW553 Dec 11, 2025
0b58868
constructor
TimothyW553 Dec 11, 2025
310e096
implementation
TimothyW553 Dec 11, 2025
1c121cf
Add catalogCommits to getActiveCommitAtTime
TimothyW553 Dec 11, 2025
9304c55
fix import
TimothyW553 Dec 11, 2025
0264690
integration tests
TimothyW553 Dec 11, 2025
fbfdb22
integration tests
TimothyW553 Dec 11, 2025
ba00cab
Update tests
TimothyW553 Dec 11, 2025
c7657f7
Update tests
TimothyW553 Dec 11, 2025
2e381b4
revert accidental fmt
TimothyW553 Dec 11, 2025
68aa424
fix earliest version from delta
TimothyW553 Dec 11, 2025
a7b46bb
fix earliest version from delta
TimothyW553 Dec 11, 2025
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
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ lazy val sparkV1Filtered = (project in file("spark-v1-filtered"))
lazy val sparkV2 = (project in file("kernel-spark"))
.dependsOn(sparkV1Filtered)
.dependsOn(kernelDefaults)
.dependsOn(kernelUnityCatalog % "compile->compile;test->test")
.dependsOn(goldenTables % "test")
.settings(
name := "delta-spark-v2",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Copyright (2025) The Delta Lake Project Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.delta.kernel.spark.snapshot.unitycatalog;

import static java.util.Objects.requireNonNull;

import io.delta.kernel.CommitRange;
import io.delta.kernel.Snapshot;
import io.delta.kernel.engine.Engine;
import io.delta.kernel.internal.DeltaHistoryManager;
import io.delta.kernel.internal.SnapshotImpl;
import io.delta.kernel.internal.files.ParsedCatalogCommitData;
import io.delta.kernel.spark.exception.VersionNotFoundException;
import io.delta.kernel.spark.snapshot.DeltaSnapshotManager;
import io.delta.kernel.unitycatalog.UCCatalogManagedClient;
import java.util.List;
import java.util.Optional;

/**
* Snapshot manager for Unity Catalog managed tables.
*
* <p>Used for tables with the catalog-managed commit feature enabled. Unity Catalog serves as the
* source of truth for the table's commit history.
*/
public class UCManagedTableSnapshotManager implements DeltaSnapshotManager {

private final UCCatalogManagedClient ucCatalogManagedClient;
private final String tableId;
private final String tablePath;
private final Engine engine;

/**
* Creates a new UCManagedTableSnapshotManager.
*
* @param ucCatalogManagedClient the UC client for catalog-managed operations
* @param tableInfo the UC table information (tableId, tablePath, etc.)
* @param engine the Kernel engine for table operations
*/
public UCManagedTableSnapshotManager(
UCCatalogManagedClient ucCatalogManagedClient, UCTableInfo tableInfo, Engine engine) {
this.ucCatalogManagedClient =
requireNonNull(ucCatalogManagedClient, "ucCatalogManagedClient is null");
requireNonNull(tableInfo, "tableInfo is null");
this.tableId = tableInfo.getTableId();
this.tablePath = tableInfo.getTablePath();
this.engine = requireNonNull(engine, "engine is null");
}

@Override
public Snapshot loadLatestSnapshot() {
return ucCatalogManagedClient.loadSnapshot(
engine,
tableId,
tablePath,
Optional.empty() /* versionOpt */,
Optional.empty() /* timestampOpt */);
}

@Override
public Snapshot loadSnapshotAt(long version) {
return ucCatalogManagedClient.loadSnapshot(
engine, tableId, tablePath, Optional.of(version), Optional.empty() /* timestampOpt */);
}

/**
* Finds the active commit at a specific timestamp.
*
* <p>For UC-managed tables, this loads the latest snapshot and uses {@link
* DeltaHistoryManager#getActiveCommitAtTimestamp} to resolve the timestamp to a commit.
*/
@Override
public DeltaHistoryManager.Commit getActiveCommitAtTime(
long timestampMillis,
boolean canReturnLastCommit,
boolean mustBeRecreatable,
boolean canReturnEarliestCommit) {
SnapshotImpl snapshot = (SnapshotImpl) loadLatestSnapshot();
List<ParsedCatalogCommitData> catalogCommits = snapshot.getLogSegment().getAllCatalogCommits();
return DeltaHistoryManager.getActiveCommitAtTimestamp(
engine,
snapshot,
snapshot.getLogPath(),
timestampMillis,
mustBeRecreatable,
canReturnLastCommit,
canReturnEarliestCommit,
catalogCommits);
}

/**
* Checks if a specific version exists and is accessible.
*
* <p>For UC-managed tables, all ratified commits are available, so the earliest version is
* typically 0. This method validates that the requested version is within the valid range.
*/
@Override
public void checkVersionExists(long version, boolean mustBeRecreatable, boolean allowOutOfRange)
throws VersionNotFoundException {
// Load latest to get the current version bounds
Snapshot latestSnapshot = loadLatestSnapshot();
long latestVersion = latestSnapshot.getVersion();

// For UC tables, earliest recreatable version is 0 (all ratified commits are available)
long earliestVersion = 0;

if (version < earliestVersion || ((version > latestVersion) && !allowOutOfRange)) {
throw new VersionNotFoundException(version, earliestVersion, latestVersion);
}
}

@Override
public CommitRange getTableChanges(Engine engine, long startVersion, Optional<Long> endVersion) {
return ucCatalogManagedClient.loadCommitRange(
engine,
tableId,
tablePath,
Optional.of(startVersion) /* startVersionOpt */,
Optional.empty() /* startTimestampOpt */,
endVersion /* endVersionOpt */,
Optional.empty() /* endTimestampOpt */);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/**
* Utility class for extracting Unity Catalog table information from Spark catalog metadata.
*
* <p>This class isolates Spark dependencies, allowing {@link UCManagedSnapshotManager} to be
* <p>This class isolates Spark dependencies, allowing {@link UCManagedTableSnapshotManager} to be
* created without Spark if table info is provided directly via {@link UCTableInfo}.
*/
public final class UCUtils {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright (2025) The Delta Lake Project Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.delta.kernel.spark.snapshot.unitycatalog;

import static org.junit.jupiter.api.Assertions.*;

import io.delta.kernel.defaults.engine.DefaultEngine;
import io.delta.kernel.engine.Engine;
import io.delta.kernel.unitycatalog.InMemoryUCClient;
import io.delta.kernel.unitycatalog.UCCatalogManagedClient;
import org.apache.hadoop.conf.Configuration;
import org.junit.jupiter.api.Test;

/**
* Unit tests for {@link UCManagedTableSnapshotManager}.
*
* <p>These tests focus on constructor validation and basic instantiation. Integration tests for
* actual functionality are in {@code UCManagedTableSnapshotManagerSuite}.
*/
public class UCManagedTableSnapshotManagerTest {

private static final String TEST_TABLE_ID = "test_uc_table_id";
private static final String TEST_TABLE_PATH = "/test/path/to/table";
private static final String TEST_UC_URI = "https://uc.example.com";
private static final String TEST_UC_TOKEN = "test_token";

private UCTableInfo createTestTableInfo() {
return new UCTableInfo(TEST_TABLE_ID, TEST_TABLE_PATH, TEST_UC_URI, TEST_UC_TOKEN);
}

private UCCatalogManagedClient createTestClient() {
InMemoryUCClient ucClient = new InMemoryUCClient("test_metastore");
return new UCCatalogManagedClient(ucClient);
}

private Engine createTestEngine() {
return DefaultEngine.create(new Configuration());
}

@Test
public void testConstructor_NullClient_ThrowsNPE() {
UCTableInfo tableInfo = createTestTableInfo();
Engine engine = createTestEngine();

NullPointerException exception =
assertThrows(
NullPointerException.class,
() -> new UCManagedTableSnapshotManager(null, tableInfo, engine));
assertEquals("ucCatalogManagedClient is null", exception.getMessage());
}

@Test
public void testConstructor_NullTableInfo_ThrowsNPE() {
UCCatalogManagedClient client = createTestClient();
Engine engine = createTestEngine();

NullPointerException exception =
assertThrows(
NullPointerException.class,
() -> new UCManagedTableSnapshotManager(client, null, engine));
assertEquals("tableInfo is null", exception.getMessage());
}

@Test
public void testConstructor_NullEngine_ThrowsNPE() {
UCCatalogManagedClient client = createTestClient();
UCTableInfo tableInfo = createTestTableInfo();

NullPointerException exception =
assertThrows(
NullPointerException.class,
() -> new UCManagedTableSnapshotManager(client, tableInfo, null));
assertEquals("engine is null", exception.getMessage());
}

@Test
public void testConstructor_ValidInputs_CreatesManager() {
UCCatalogManagedClient client = createTestClient();
UCTableInfo tableInfo = createTestTableInfo();
Engine engine = createTestEngine();

UCManagedTableSnapshotManager manager =
new UCManagedTableSnapshotManager(client, tableInfo, engine);

assertNotNull(manager);
}
}
Loading
Loading