Skip to content
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
dfea6a4
single commit
vaibhavk1992 Apr 25, 2025
b75bc7c
adding delta kernel
vaibhavk1992 May 16, 2025
16134b3
adding the test file
vaibhavk1992 May 19, 2025
3929e95
adding workable code for iteration over data
vaibhavk1992 May 26, 2025
c6379b5
adding Kernel 4.0 code
vaibhavk1992 Jun 11, 2025
6deb5f7
adding the working code with xtable that check getcurrenttable
vaibhavk1992 Jun 24, 2025
05d9984
Merge branch 'main' into test-4
vaibhavk1992 Jun 30, 2025
c7ba4b9
adding the dependecies
vaibhavk1992 Jun 30, 2025
0ff36a5
adding getcurrentsnapshot code
vaibhavk1992 Jul 19, 2025
18ab9d6
spotless fix
vaibhavk1992 Jul 19, 2025
e906091
spotless fix 2
vaibhavk1992 Jul 19, 2025
e00241c
spotless fix 2
vaibhavk1992 Jul 19, 2025
3fdfd31
fixed partitioned test case
vaibhavk1992 Jul 26, 2025
e0102e3
setting junit parallel execution to true
vaibhavk1992 Jul 28, 2025
381722a
testInsertsUpsertsAndDeletes test case addition,internal datatype add…
vaibhavk1992 Aug 5, 2025
809bfe8
added the fix for table basepath listing wrong paths
vaibhavk1992 Aug 7, 2025
40172f2
added the fix for table basepath listing wrong paths
vaibhavk1992 Aug 7, 2025
e0b7829
adding all tests
vaibhavk1992 Aug 27, 2025
9ac022a
adding refactored code
vaibhavk1992 Aug 27, 2025
73f33b6
spotless fix
vaibhavk1992 Aug 27, 2025
bee3e8a
fix change extraction
the-other-tim-brown Oct 5, 2025
e75bb55
adding the commitbacklog test cases changes
vaibhavk1992 Oct 7, 2025
21044af
Merge branch 'apache:main' into test-4
vaibhavk1992 Oct 7, 2025
e212f52
adding a test case testConvertFromDeltaPartitionFormat
vaibhavk1992 Oct 13, 2025
988cda1
adding a test case testConvertFromDeltaPartitionFormat
vaibhavk1992 Oct 13, 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
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<module>xtable-utilities</module>
<module>xtable-aws</module>
<module>xtable-hive-metastore</module>
<module>xtable-service</module>
<!-- <module>xtable-service</module>-->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why comment this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be added back, any reason why you had to comment this out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, xtable-service was giving build failures. As xtable-service is independent of the delta kernel changes. Can we just review the delta kernel changes as of now? I just want to get my changes validated once and anyhow the final version of delta kernel changes would have xtable-service module too.

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vaibhavk1992 I think if you rebase with latest main branch you shouldn't see those failures.

</modules>

<properties>
Expand Down Expand Up @@ -713,7 +713,7 @@
</executions>
<configuration>
<skip>${skipUTs}</skip>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why revert this?

<redirectTestOutputToFile>false</redirectTestOutputToFile>
<trimStackTrace>false</trimStackTrace>
<forkedProcessExitTimeoutInSeconds>120</forkedProcessExitTimeoutInSeconds>
</configuration>
Expand Down
13 changes: 13 additions & 0 deletions xtable-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.delta</groupId>
<artifactId>delta-kernel-api</artifactId>
<version>4.0.0</version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a properly in the root pom called <delta.kernel.version>4.0.0</delta.kernel.version>, instead of using the hardcoded value?

Also curious how you ended up choosing delta kernel version, is there some specific version that needs to align with delta lake version we have in the repo?

</dependency>

<dependency>
<groupId>io.delta</groupId>
<artifactId>delta-kernel-defaults</artifactId>
<version>4.0.0</version>
</dependency>


<!-- Hadoop dependencies -->
<dependency>
<groupId>org.apache.hadoop</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class DeltaPartitionExtractor {
// For timestamp partition fields, actual partition column names in delta format will be of type
// generated & and with a name like `delta_partition_col_{transform_type}_{source_field_name}`.
private static final String DELTA_PARTITION_COL_NAME_FORMAT = "xtable_partition_col_%s_%s";
static final String DELTA_GENERATION_EXPRESSION = "delta.generationExpression";
public static final String DELTA_GENERATION_EXPRESSION = "delta.generationExpression";
private static final List<ParsedGeneratedExpr.GeneratedExprType> GRANULARITIES =
Arrays.asList(
ParsedGeneratedExpr.GeneratedExprType.YEAR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@

package org.apache.xtable.delta;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
Expand All @@ -41,22 +37,10 @@
import org.apache.xtable.model.schema.InternalType;
import org.apache.xtable.schema.SchemaUtils;

/**
* Converts between Delta and InternalTable schemas. Some items to be aware of:
*
* <ul>
* <li>Delta schemas are represented as Spark StructTypes which do not have enums so the enum
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can live this file as is right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vaibhavk1992 let's remove the changes to this file. They don't seem necessary

* types are lost when converting from XTable to Delta Lake representations
* <li>Delta does not have a fixed length byte array option so {@link InternalType#FIXED} is
* simply translated to a {@link org.apache.spark.sql.types.BinaryType}
* <li>Similarly, {@link InternalType#TIMESTAMP_NTZ} is translated to a long in Delta Lake
* </ul>
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class DeltaSchemaExtractor {
private static final String DELTA_COLUMN_MAPPING_ID = "delta.columnMapping.id";
private static final DeltaSchemaExtractor INSTANCE = new DeltaSchemaExtractor();
// Timestamps in Delta are microsecond precision by default
private static final Map<InternalSchema.MetadataKey, Object>
DEFAULT_TIMESTAMP_PRECISION_METADATA =
Collections.singletonMap(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* 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.util.Collections;
import java.util.List;
import java.util.Map;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;

import scala.collection.JavaConverters;

import io.delta.kernel.Table;
import io.delta.kernel.defaults.engine.DefaultEngine;
import io.delta.kernel.engine.Engine;
import io.delta.kernel.internal.actions.AddFile;
import io.delta.kernel.internal.actions.RemoveFile;

import org.apache.xtable.exception.NotSupportedException;
import org.apache.xtable.model.schema.InternalField;
import org.apache.xtable.model.schema.InternalPartitionField;
import org.apache.xtable.model.stat.ColumnStat;
import org.apache.xtable.model.stat.FileStats;
import org.apache.xtable.model.storage.FileFormat;
import org.apache.xtable.model.storage.InternalDataFile;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class DeltaKernelActionsConverter {
private static final DeltaKernelActionsConverter INSTANCE = new DeltaKernelActionsConverter();

public static DeltaKernelActionsConverter getInstance() {
return INSTANCE;
}

public InternalDataFile convertAddActionToInternalDataFile(
AddFile addFile,
Table table,
FileFormat fileFormat,
List<InternalPartitionField> partitionFields,
List<InternalField> fields,
boolean includeColumnStats,
DeltaKernelPartitionExtractor partitionExtractor,
DeltaKernelStatsExtractor fileStatsExtractor,
Map<String, String> partitionValues) {
FileStats fileStats = fileStatsExtractor.getColumnStatsForFile(addFile, fields);
List<ColumnStat> columnStats =
includeColumnStats ? fileStats.getColumnStats() : Collections.emptyList();
long recordCount = fileStats.getNumRecords();
// The immutable map from Java to Scala is not working, need to

scala.collection.mutable.Map<String, String> scalaMap =
JavaConverters.mapAsScalaMap(partitionValues);

return InternalDataFile.builder()
.physicalPath(getFullPathToFile(addFile.getPath(), table))
.fileFormat(fileFormat)
.fileSizeBytes(addFile.getSize())
.lastModified(addFile.getModificationTime())
.partitionValues(partitionExtractor.partitionValueExtraction(scalaMap, partitionFields))
.columnStats(columnStats)
.recordCount(recordCount)
.build();
}

public InternalDataFile convertRemoveActionToInternalDataFile(
RemoveFile removeFile,
Table table,
FileFormat fileFormat,
List<InternalPartitionField> partitionFields,
DeltaKernelPartitionExtractor partitionExtractor,
Map<String, String> partitionValues) {
scala.collection.mutable.Map<String, String> scalaMap =
JavaConverters.mapAsScalaMap(partitionValues);

return InternalDataFile.builder()
.physicalPath(getFullPathToFile(removeFile.getPath(), table))
.fileFormat(fileFormat)
.partitionValues(partitionExtractor.partitionValueExtraction(scalaMap, partitionFields))
.build();
}

public FileFormat convertToFileFormat(String provider) {
if (provider.equals("parquet")) {
return FileFormat.APACHE_PARQUET;
} else if (provider.equals("orc")) {
return FileFormat.APACHE_ORC;
}
throw new NotSupportedException(
String.format("delta file format %s is not recognized", provider));
}

static String getFullPathToFile(String dataFilePath, Table table) {
Configuration hadoopConf = new Configuration();
Engine myEngine = DefaultEngine.create(hadoopConf);
String tableBasePath = table.getPath(myEngine);
;
// String tableBasePath = snapshot.dataPath().toUri().toString();
Comment on lines +116 to +117
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be cleaned up?

if (dataFilePath.startsWith(tableBasePath)) {
return dataFilePath;
}
return tableBasePath + Path.SEPARATOR + dataFilePath;
}
}
Loading