This is an automated email from the ASF dual-hosted git repository.

timbrown pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-xtable.git


The following commit(s) were added to refs/heads/main by this push:
     new 8e583674 Remove redundant getSnapshotAt calls per commit (#791)
8e583674 is described below

commit 8e583674151aa341010154b7cc7066f098e3cded
Author: Rishi Reddy Bokka <[email protected]>
AuthorDate: Fri Feb 20 18:44:15 2026 -0500

    Remove redundant getSnapshotAt calls per commit (#791)
    
    * Removed redundant delta calls
    
    * remove redundant deltalog call
    
    Co-authored-by: Kevin Liu <[email protected]>
    
    * Add Javadoc and input validation to DeltaTableExtractor.table(Snapshot, 
String)
    
    ---------
    
    Co-authored-by: Kevin Liu <[email protected]>
---
 .../apache/xtable/delta/DeltaConversionSource.java |  8 +++-----
 .../apache/xtable/delta/DeltaTableExtractor.java   | 23 ++++++++++++++++++++++
 2 files changed, 26 insertions(+), 5 deletions(-)

diff --git 
a/xtable-core/src/main/java/org/apache/xtable/delta/DeltaConversionSource.java 
b/xtable-core/src/main/java/org/apache/xtable/delta/DeltaConversionSource.java
index bb40a315..7fc8ea7b 100644
--- 
a/xtable-core/src/main/java/org/apache/xtable/delta/DeltaConversionSource.java
+++ 
b/xtable-core/src/main/java/org/apache/xtable/delta/DeltaConversionSource.java
@@ -85,16 +85,14 @@ public class DeltaConversionSource implements 
ConversionSource<Long> {
 
   @Override
   public InternalTable getCurrentTable() {
-    DeltaLog deltaLog = DeltaLog.forTable(sparkSession, basePath);
     Snapshot snapshot = deltaLog.snapshot();
-    return getTable(snapshot.version());
+    return tableExtractor.table(snapshot, tableName);
   }
 
   @Override
   public InternalSnapshot getCurrentSnapshot() {
-    DeltaLog deltaLog = DeltaLog.forTable(sparkSession, basePath);
     Snapshot snapshot = deltaLog.snapshot();
-    InternalTable table = getTable(snapshot.version());
+    InternalTable table = tableExtractor.table(snapshot, tableName);
     return InternalSnapshot.builder()
         .table(table)
         .partitionedDataFiles(getInternalDataFiles(snapshot, 
table.getReadSchema()))
@@ -104,9 +102,9 @@ public class DeltaConversionSource implements 
ConversionSource<Long> {
 
   @Override
   public TableChange getTableChangeForCommit(Long versionNumber) {
-    InternalTable tableAtVersion = tableExtractor.table(deltaLog, tableName, 
versionNumber);
     List<Action> actionsForVersion = 
getChangesState().getActionsForVersion(versionNumber);
     Snapshot snapshotAtVersion = deltaLog.getSnapshotAt(versionNumber, 
Option.empty());
+    InternalTable tableAtVersion = tableExtractor.table(snapshotAtVersion, 
tableName);
     FileFormat fileFormat =
         
actionsConverter.convertToFileFormat(snapshotAtVersion.metadata().format().provider());
 
diff --git 
a/xtable-core/src/main/java/org/apache/xtable/delta/DeltaTableExtractor.java 
b/xtable-core/src/main/java/org/apache/xtable/delta/DeltaTableExtractor.java
index 731b5c30..8f1f1d06 100644
--- a/xtable-core/src/main/java/org/apache/xtable/delta/DeltaTableExtractor.java
+++ b/xtable-core/src/main/java/org/apache/xtable/delta/DeltaTableExtractor.java
@@ -44,6 +44,19 @@ public class DeltaTableExtractor {
 
   public InternalTable table(DeltaLog deltaLog, String tableName, Long 
version) {
     Snapshot snapshot = deltaLog.getSnapshotAt(version, Option.empty());
+    return table(snapshot, tableName);
+  }
+
+  /**
+   * Builds an {@link InternalTable} from a pre-resolved Delta {@link 
Snapshot}.
+   *
+   * @param snapshot a valid, non-null snapshot with metadata and schema 
present
+   * @param tableName name of the table
+   * @return the internal representation of the table at the snapshot's version
+   * @throws IllegalStateException if the snapshot or its metadata/schema is 
null
+   */
+  public InternalTable table(Snapshot snapshot, String tableName) {
+    requireMetadata(snapshot, tableName);
     InternalSchema schema = 
schemaExtractor.toInternalSchema(snapshot.metadata().schema());
     List<InternalPartitionField> partitionFields =
         DeltaPartitionExtractor.getInstance()
@@ -65,4 +78,14 @@ public class DeltaTableExtractor {
         .latestMetadataPath(snapshot.deltaLog().logPath().toString())
         .build();
   }
+
+  private static void requireMetadata(Snapshot snapshot, String tableName) {
+    if (snapshot == null || snapshot.metadata() == null || 
snapshot.metadata().schema() == null) {
+      throw new IllegalStateException(
+          "Missing metadata/schema for table: "
+              + tableName
+              + " at version: "
+              + (snapshot != null ? snapshot.version() : "unknown"));
+    }
+  }
 }

Reply via email to