|
| 1 | +/* |
| 2 | + * Copyright (2025) The Delta Lake Project Authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package io.delta.kernel.spark.snapshot.unitycatalog; |
| 17 | + |
| 18 | +import static java.util.Objects.requireNonNull; |
| 19 | + |
| 20 | +import io.delta.kernel.CommitRange; |
| 21 | +import io.delta.kernel.Snapshot; |
| 22 | +import io.delta.kernel.defaults.engine.DefaultEngine; |
| 23 | +import io.delta.kernel.engine.Engine; |
| 24 | +import io.delta.kernel.internal.DeltaHistoryManager; |
| 25 | +import io.delta.kernel.spark.exception.VersionNotFoundException; |
| 26 | +import io.delta.kernel.spark.snapshot.DeltaSnapshotManager; |
| 27 | +import io.delta.kernel.unitycatalog.UCCatalogManagedClient; |
| 28 | +import java.util.Optional; |
| 29 | +import org.apache.hadoop.conf.Configuration; |
| 30 | + |
| 31 | +/** |
| 32 | + * Snapshot manager for Unity Catalog managed tables. |
| 33 | + * |
| 34 | + * <p>This implementation delegates to {@link UCCatalogManagedClient} for all snapshot and commit |
| 35 | + * operations, leveraging UC's ratified commits as the source of truth. |
| 36 | + */ |
| 37 | +public class UCManagedSnapshotManager implements DeltaSnapshotManager { |
| 38 | + |
| 39 | + private final UCCatalogManagedClient ucCatalogManagedClient; |
| 40 | + private final String tableId; |
| 41 | + private final String tablePath; |
| 42 | + private final Engine engine; |
| 43 | + |
| 44 | + /** |
| 45 | + * Creates a new UCManagedSnapshotManager. |
| 46 | + * |
| 47 | + * @param ucCatalogManagedClient the UC client for catalog-managed operations |
| 48 | + * @param tableInfo the UC table information (tableId, tablePath, etc.) |
| 49 | + * @param hadoopConf Hadoop configuration for filesystem operations |
| 50 | + */ |
| 51 | + public UCManagedSnapshotManager( |
| 52 | + UCCatalogManagedClient ucCatalogManagedClient, |
| 53 | + UCTableInfo tableInfo, |
| 54 | + Configuration hadoopConf) { |
| 55 | + this.ucCatalogManagedClient = |
| 56 | + requireNonNull(ucCatalogManagedClient, "ucCatalogManagedClient is null"); |
| 57 | + requireNonNull(tableInfo, "tableInfo is null"); |
| 58 | + this.tableId = tableInfo.getTableId(); |
| 59 | + this.tablePath = tableInfo.getTablePath(); |
| 60 | + this.engine = DefaultEngine.create(requireNonNull(hadoopConf, "hadoopConf is null")); |
| 61 | + } |
| 62 | + |
| 63 | + @Override |
| 64 | + public Snapshot loadLatestSnapshot() { |
| 65 | + // TODO: Implement in snapshotmanager-impl stack |
| 66 | + throw new UnsupportedOperationException( |
| 67 | + "UCManagedSnapshotManager.loadLatestSnapshot not yet implemented"); |
| 68 | + } |
| 69 | + |
| 70 | + @Override |
| 71 | + public Snapshot loadSnapshotAt(long version) { |
| 72 | + // TODO: Implement in snapshotmanager-impl stack |
| 73 | + throw new UnsupportedOperationException( |
| 74 | + "UCManagedSnapshotManager.loadSnapshotAt not yet implemented"); |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public DeltaHistoryManager.Commit getActiveCommitAtTime( |
| 79 | + long timestampMillis, |
| 80 | + boolean canReturnLastCommit, |
| 81 | + boolean mustBeRecreatable, |
| 82 | + boolean canReturnEarliestCommit) { |
| 83 | + // TODO: Implement in snapshotmanager-impl stack |
| 84 | + throw new UnsupportedOperationException( |
| 85 | + "UCManagedSnapshotManager.getActiveCommitAtTime not yet implemented"); |
| 86 | + } |
| 87 | + |
| 88 | + @Override |
| 89 | + public void checkVersionExists(long version, boolean mustBeRecreatable, boolean allowOutOfRange) |
| 90 | + throws VersionNotFoundException { |
| 91 | + // TODO: Implement in snapshotmanager-impl stack |
| 92 | + throw new UnsupportedOperationException( |
| 93 | + "UCManagedSnapshotManager.checkVersionExists not yet implemented"); |
| 94 | + } |
| 95 | + |
| 96 | + @Override |
| 97 | + public CommitRange getTableChanges(Engine engine, long startVersion, Optional<Long> endVersion) { |
| 98 | + // TODO: Implement in snapshotmanager-impl stack |
| 99 | + throw new UnsupportedOperationException( |
| 100 | + "UCManagedSnapshotManager.getTableChanges not yet implemented"); |
| 101 | + } |
| 102 | +} |
0 commit comments