-
Notifications
You must be signed in to change notification settings - Fork 183
Delta Kernel Draft PR #729
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
base: main
Are you sure you want to change the base?
Changes from all commits
dfea6a4
b75bc7c
16134b3
3929e95
c6379b5
6deb5f7
05d9984
c7ba4b9
0ff36a5
18ab9d6
e906091
e00241c
3fdfd31
e0102e3
381722a
809bfe8
40172f2
e0b7829
9ac022a
73f33b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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>--> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
@@ -713,7 +713,7 @@ | |
</executions> | ||
<configuration> | ||
<skip>${skipUTs}</skip> | ||
<redirectTestOutputToFile>true</redirectTestOutputToFile> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,6 +110,19 @@ | |
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.delta</groupId> | ||
<artifactId>delta-kernel-api</artifactId> | ||
<version>4.0.0</version> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can live this file as is right? |
||
* 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( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* 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 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 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(); | ||
if (dataFilePath.startsWith(tableBasePath)) { | ||
return dataFilePath; | ||
} | ||
return tableBasePath + Path.SEPARATOR + dataFilePath; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why comment this?