-
Notifications
You must be signed in to change notification settings - Fork 2k
[Kernel-Spark][DSv2] Implement UCManagedSnapshotManager operations using UCCatalogManagedClient #5677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TimothyW553
wants to merge
68
commits into
delta-io:master
Choose a base branch
from
TimothyW553:stack/snapshotmanager-implementation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[Kernel-Spark][DSv2] Implement UCManagedSnapshotManager operations using UCCatalogManagedClient #5677
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 ac042af
delete workspace
TimothyW553 9ca1793
delete
TimothyW553 e3fcc41
change to catalogtable
TimothyW553 776ed69
add tests
TimothyW553 418b9bd
fmt
TimothyW553 e926066
test fix
TimothyW553 d443640
storage props
TimothyW553 d1684da
merge props
TimothyW553 0ca9b4c
address comments
TimothyW553 ee36547
remove private method test
TimothyW553 906643b
null check for storage properties
TimothyW553 71c62f3
Restore UC connection utils after rebase
TimothyW553 e524c60
clean up...
TimothyW553 b79ff29
Restore UC connection info utils and add SparkUnityCatalogUtils suite
TimothyW553 816e596
Update tests
TimothyW553 a5d745a
spark
TimothyW553 9d313c9
Clean up test utils and refactor
TimothyW553 1ba9177
revert DeltaSQLConfV2.scala
TimothyW553 c6d7e67
remove npe tests
TimothyW553 fc614cb
remove more npe
TimothyW553 2d333d3
Centralize utils
TimothyW553 7dc4549
fmt
TimothyW553 b2e39c8
FMT
TimothyW553 0423386
Address comments - remove unecessary wrappers and add logging
TimothyW553 7717995
Address comments - remove unecessary wrappers and add logging
TimothyW553 9cad0ba
Add wrapper for map
TimothyW553 a294801
use SharedSparkSession
TimothyW553 f43a198
fix tests
TimothyW553 d4f0c0f
fix tests
TimothyW553 0a58d48
annotate constant params
TimothyW553 94303b3
annotate constant params
TimothyW553 4275b56
Rename and follow naming conventions
TimothyW553 ad25296
Rename and follow naming conventions
TimothyW553 254b3f5
update context
TimothyW553 07f3b5b
rename base utils
TimothyW553 2bee750
Update tests
TimothyW553 64e5cda
Clean up test utils and refactor
TimothyW553 bb9fe06
Centralize utils
TimothyW553 1615a27
FMT
TimothyW553 c069296
Address comments - remove unecessary wrappers and add logging
TimothyW553 f4dab6c
Address comments - remove unecessary wrappers and add logging
TimothyW553 8588477
fix tests
TimothyW553 20c631b
annotate constant params
TimothyW553 f032bc4
Rename and follow naming conventions
TimothyW553 15ddabf
Rename and follow naming conventions
TimothyW553 ca28e0d
wireframe
TimothyW553 984e458
rename to UCManagedTableSnapshotManager
TimothyW553 63e0f90
reword javadocs
TimothyW553 094db22
[Kernel-Spark][DSv2] Implement UCManagedSnapshotManager operations us…
TimothyW553 10da4a2
annotate constants
TimothyW553 043f3c1
scala and java tests
TimothyW553 2767fec
scala and java tests
TimothyW553 0c22e3a
Remove engine construction and update to being passed in as a param
TimothyW553 7a36ab2
Remove tests for impl
TimothyW553 197efc8
unformat
TimothyW553 7f40d83
remove impl oops
TimothyW553 0b58868
constructor
TimothyW553 310e096
implementation
TimothyW553 1c121cf
Add catalogCommits to getActiveCommitAtTime
TimothyW553 9304c55
fix import
TimothyW553 0264690
integration tests
TimothyW553 fbfdb22
integration tests
TimothyW553 ba00cab
Update tests
TimothyW553 c7657f7
Update tests
TimothyW553 2e381b4
revert accidental fmt
TimothyW553 68aa424
fix earliest version from delta
TimothyW553 a7b46bb
fix earliest version from delta
TimothyW553 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
.../main/java/io/delta/kernel/spark/snapshot/unitycatalog/UCManagedTableSnapshotManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 */); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...t/java/io/delta/kernel/spark/snapshot/unitycatalog/UCManagedTableSnapshotManagerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.