the-other-tim-brown commented on code in PR #729:
URL: https://github.com/apache/incubator-xtable/pull/729#discussion_r2565567891


##########
pom.xml:
##########
@@ -615,6 +616,20 @@
                 <artifactId>jettison</artifactId>
                 <version>1.5.4</version>
             </dependency>
+            <dependency>
+                <groupId>io.delta</groupId>
+                <artifactId>delta-kernel-api</artifactId>
+                <version>${delta.kernel.version}</version>
+                <scope>provided</scope>

Review Comment:
   We'll want these to be the default compile scope. I think that will make it 
easier than requiring users to provide their own version at runtime.



##########
xtable-core/src/main/java/org/apache/xtable/kernel/DeltaKernelTableExtractor.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.xtable.kernel;
+
+import java.time.Instant;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import lombok.Builder;
+
+import io.delta.kernel.Snapshot;
+import io.delta.kernel.Table;
+import io.delta.kernel.engine.Engine;
+import io.delta.kernel.types.StructField;
+import io.delta.kernel.types.StructType;
+
+import org.apache.xtable.exception.SchemaExtractorException;
+import org.apache.xtable.model.InternalTable;
+import org.apache.xtable.model.schema.InternalPartitionField;
+import org.apache.xtable.model.schema.InternalSchema;
+import org.apache.xtable.model.storage.DataLayoutStrategy;
+import org.apache.xtable.model.storage.TableFormat;
+
+/**
+ * Extracts {@link InternalTable} canonical representation of a table at a 
point in time for Delta.
+ */
+@Builder
+public class DeltaKernelTableExtractor {
+  @Builder.Default
+  private static final DeltaKernelSchemaExtractor schemaExtractor =
+      DeltaKernelSchemaExtractor.getInstance();
+
+  private final String basePath;
+
+  public InternalTable table(
+      Table deltaKernelTable, Snapshot snapshot, Engine engine, String 
tableName, String basePath) {
+    try {
+      // Get schema from Delta Kernel's snapshot
+      StructType schema = snapshot.getSchema();
+      InternalSchema internalSchema = schemaExtractor.toInternalSchema(schema);
+      // Get partition columns
+      StructType fullSchema = snapshot.getSchema(); // The full table schema
+      List<String> partitionColumns = snapshot.getPartitionColumnNames();
+      List<StructField> partitionFieldSchemas =
+          fullSchema.fields().stream()
+              .filter(field -> partitionColumns.contains(field.getName()))
+              .collect(Collectors.toList());
+      StructType partitionSchema = new StructType(partitionFieldSchemas);
+
+      List<InternalPartitionField> partitionFields =
+          DeltaKernelPartitionExtractor.getInstance()
+              .convertFromDeltaPartitionFormat(internalSchema, 
partitionSchema);
+
+      DataLayoutStrategy dataLayoutStrategy =
+          !partitionFields.isEmpty()
+              ? DataLayoutStrategy.HIVE_STYLE_PARTITION
+              : DataLayoutStrategy.FLAT;
+
+      // Get the timestamp
+      long timestamp = snapshot.getTimestamp(engine);
+      return InternalTable.builder()
+          .tableFormat(TableFormat.DELTA)
+          .basePath(basePath)
+          .name(tableName)
+          .layoutStrategy(dataLayoutStrategy)
+          .partitioningFields(partitionFields)
+          .readSchema(internalSchema)
+          .latestCommitTime(Instant.ofEpochMilli(timestamp))
+          .latestMetadataPath(basePath + "/_delta_log")
+          .build();
+    } catch (Exception e) {

Review Comment:
   If this is just some general catch-all, my recommendation is to remove it. 
If this is supposed to catch some specific exception from the schema 
extraction, let's catch that particular exception.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to