-
Notifications
You must be signed in to change notification settings - Fork 190
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
Open
vaibhavk1992
wants to merge
39
commits into
apache:main
Choose a base branch
from
vaibhavk1992:test-4
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
dfea6a4
single commit
vaibhavk1992 b75bc7c
adding delta kernel
vaibhavk1992 16134b3
adding the test file
vaibhavk1992 3929e95
adding workable code for iteration over data
vaibhavk1992 c6379b5
adding Kernel 4.0 code
vaibhavk1992 6deb5f7
adding the working code with xtable that check getcurrenttable
vaibhavk1992 05d9984
Merge branch 'main' into test-4
vaibhavk1992 c7ba4b9
adding the dependecies
vaibhavk1992 0ff36a5
adding getcurrentsnapshot code
vaibhavk1992 18ab9d6
spotless fix
vaibhavk1992 e906091
spotless fix 2
vaibhavk1992 e00241c
spotless fix 2
vaibhavk1992 3fdfd31
fixed partitioned test case
vaibhavk1992 e0102e3
setting junit parallel execution to true
vaibhavk1992 381722a
testInsertsUpsertsAndDeletes test case addition,internal datatype add…
vaibhavk1992 809bfe8
added the fix for table basepath listing wrong paths
vaibhavk1992 40172f2
added the fix for table basepath listing wrong paths
vaibhavk1992 e0b7829
adding all tests
vaibhavk1992 9ac022a
adding refactored code
vaibhavk1992 73f33b6
spotless fix
vaibhavk1992 bee3e8a
fix change extraction
the-other-tim-brown e75bb55
adding the commitbacklog test cases changes
vaibhavk1992 21044af
Merge branch 'apache:main' into test-4
vaibhavk1992 e212f52
adding a test case testConvertFromDeltaPartitionFormat
vaibhavk1992 988cda1
adding a test case testConvertFromDeltaPartitionFormat
vaibhavk1992 1705ce4
adding the KernelPartitionExtractor test under kernel
vaibhavk1992 8f81109
commiting schema extractor and stats extrator
vaibhavk1992 49ebf21
adding unit test cases with the request changes on the PR
vaibhavk1992 70fe0e3
spotless fix
vaibhavk1992 fba7e0e
spotless fix
vaibhavk1992 bb4dc4e
Merge branch 'main' into test-4
vaibhavk1992 6b1be2d
adding haddop common in xtable service POM
vaibhavk1992 2f46699
changed map type to java and removed print commands
vaibhavk1992 70469fb
changed map type to java and removed print commands
vaibhavk1992 ae61a28
removing hadoop common from xtable service
vaibhavk1992 a6f86ac
fixing POM
vaibhavk1992 cd30bab
resolving some minor comments from review
vaibhavk1992 cecf300
changing constructor for Datafile extractor
vaibhavk1992 253de3f
add exclusion hadoop-client-runtime in POM
vaibhavk1992 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
xtable-core/src/main/java/org/apache/xtable/delta/DeltaKernelConversionSourceProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * 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.delta; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
|
|
||
| import io.delta.kernel.defaults.engine.DefaultEngine; | ||
| import io.delta.kernel.engine.Engine; | ||
|
|
||
| import org.apache.xtable.conversion.ConversionSourceProvider; | ||
| import org.apache.xtable.conversion.SourceTable; | ||
| import org.apache.xtable.kernel.DeltaKernelConversionSource; | ||
|
|
||
| public class DeltaKernelConversionSourceProvider extends ConversionSourceProvider<Long> { | ||
| @Override | ||
| public DeltaKernelConversionSource getConversionSourceInstance(SourceTable sourceTable) { | ||
| Configuration hadoopConf = new Configuration(); | ||
vaibhavk1992 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Engine engine = DefaultEngine.create(hadoopConf); | ||
| // DeltaTable deltaTable = DeltaT/able.forPath(sourceTable.getBasePath()); | ||
| return DeltaKernelConversionSource.builder() | ||
| .tableName(sourceTable.getName()) | ||
| .basePath(sourceTable.getBasePath()) | ||
| .engine(engine) | ||
| .build(); | ||
| } | ||
| } | ||
119 changes: 119 additions & 0 deletions
119
xtable-core/src/main/java/org/apache/xtable/delta/DeltaKernelSchemaExtractor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| /* | ||
| * 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.delta; | ||
|
|
||
| import java.util.*; | ||
|
|
||
| import io.delta.kernel.types.DataType; | ||
| import io.delta.kernel.types.IntegerType; | ||
| import io.delta.kernel.types.StringType; | ||
| import io.delta.kernel.types.StructType; | ||
|
|
||
| import org.apache.xtable.collectors.CustomCollectors; | ||
| import org.apache.xtable.model.schema.InternalField; | ||
| import org.apache.xtable.model.schema.InternalSchema; | ||
| import org.apache.xtable.model.schema.InternalType; | ||
| import org.apache.xtable.schema.SchemaUtils; | ||
|
|
||
| public class DeltaKernelSchemaExtractor { | ||
|
|
||
| private static final String DELTA_COLUMN_MAPPING_ID = "delta.columnMapping.id"; | ||
| private static final DeltaKernelSchemaExtractor INSTANCE = new DeltaKernelSchemaExtractor(); | ||
| private static final Map<InternalSchema.MetadataKey, Object> | ||
| DEFAULT_TIMESTAMP_PRECISION_METADATA = | ||
| Collections.singletonMap( | ||
| InternalSchema.MetadataKey.TIMESTAMP_PRECISION, InternalSchema.MetadataValue.MICROS); | ||
|
|
||
| public static DeltaKernelSchemaExtractor getInstance() { | ||
| return INSTANCE; | ||
| } | ||
|
|
||
| public InternalSchema toInternalSchema_v2(StructType structType) { | ||
vaibhavk1992 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return toInternalSchema_v2(structType, null, false, null); | ||
| } | ||
|
|
||
| String trimmedTypeName = ""; | ||
|
|
||
| private InternalSchema toInternalSchema_v2( | ||
| DataType dataType, String parentPath, boolean nullable, String comment) { | ||
|
|
||
| Map<InternalSchema.MetadataKey, Object> metadata = null; | ||
| List<InternalField> fields = null; | ||
| InternalType type = null; | ||
| if (dataType instanceof IntegerType) { | ||
| type = InternalType.INT; | ||
| trimmedTypeName = "integer"; | ||
| } | ||
| if (dataType instanceof StringType) { | ||
| type = InternalType.STRING; | ||
| trimmedTypeName = "string"; | ||
| } | ||
| if (dataType instanceof StructType) { | ||
| // Handle StructType | ||
| StructType structType = (StructType) dataType; | ||
| // your logic here | ||
|
|
||
| fields = | ||
| structType.fields().stream() | ||
| .filter( | ||
| field -> | ||
| !field | ||
| .getMetadata() | ||
| .contains(DeltaPartitionExtractor.DELTA_GENERATION_EXPRESSION)) | ||
| .map( | ||
| field -> { | ||
| Integer fieldId = | ||
| field.getMetadata().contains(DELTA_COLUMN_MAPPING_ID) | ||
| ? Long.valueOf(field.getMetadata().getLong(DELTA_COLUMN_MAPPING_ID)) | ||
| .intValue() | ||
| : null; | ||
| String fieldComment = | ||
| field.getMetadata().contains("comment") | ||
| ? field.getMetadata().getString("comment") | ||
| : null; | ||
| InternalSchema schema = | ||
| toInternalSchema_v2( | ||
| field.getDataType(), | ||
| SchemaUtils.getFullyQualifiedPath(parentPath, field.getName()), | ||
| field.isNullable(), | ||
| fieldComment); | ||
| return InternalField.builder() | ||
| .name(field.getName()) | ||
| .fieldId(fieldId) | ||
| .parentPath(parentPath) | ||
| .schema(schema) | ||
| .defaultValue( | ||
| field.isNullable() ? InternalField.Constants.NULL_DEFAULT_VALUE : null) | ||
| .build(); | ||
| }) | ||
| .collect(CustomCollectors.toList(structType.fields().size())); | ||
| type = InternalType.RECORD; | ||
| trimmedTypeName = "struct"; | ||
| } | ||
|
|
||
| return InternalSchema.builder() | ||
| .name(trimmedTypeName) | ||
| .dataType(type) | ||
| .comment(comment) | ||
| .isNullable(nullable) | ||
| .metadata(metadata) | ||
| .fields(fields) | ||
| .build(); | ||
| } | ||
| } | ||
104 changes: 104 additions & 0 deletions
104
xtable-core/src/main/java/org/apache/xtable/delta/DeltaKernelTableExtractor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /* | ||
| * 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.delta; | ||
|
|
||
| import java.time.Instant; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import lombok.Builder; | ||
|
|
||
| import io.delta.kernel.*; | ||
| import io.delta.kernel.engine.Engine; | ||
|
|
||
| import org.apache.xtable.model.InternalTable; | ||
| import org.apache.xtable.model.schema.InternalField; | ||
| import org.apache.xtable.model.schema.InternalPartitionField; | ||
| import org.apache.xtable.model.schema.InternalSchema; | ||
| import org.apache.xtable.model.schema.InternalType; | ||
| 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 | ||
| io.delta.kernel.types.StructType schema = snapshot.getSchema(); | ||
|
|
||
| System.out.println("Kernelschema: " + schema); | ||
vaibhavk1992 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| InternalSchema internalSchema = schemaExtractor.toInternalSchema_v2(schema); | ||
| // io.delta.kernel.types.StructType schema = snapshot.getSchema(); | ||
| //// InternalSchema internalSchema = schemaExtractor.toInternalSchema_v2(schema); | ||
| // InternalSchema internalSchema = | ||
| // schemaExtractor.toInternalSchema(snapshot.getSchema()); | ||
|
|
||
| // Get partition columns | ||
| System.out.println("Partition columns: " + internalSchema); | ||
| List<String> partitionColumnNames = snapshot.getPartitionColumnNames(); | ||
| List<InternalPartitionField> partitionFields = new ArrayList<>(); | ||
| for (String columnName : partitionColumnNames) { | ||
| InternalField sourceField = | ||
| InternalField.builder() | ||
| .name(columnName) | ||
| .schema( | ||
| InternalSchema.builder() | ||
| .name(columnName) | ||
| .dataType(InternalType.STRING) // Assuming string type for partition columns | ||
| .build()) | ||
| .build(); | ||
|
|
||
| // Create the partition field with the source field | ||
| partitionFields.add(InternalPartitionField.builder().sourceField(sourceField).build()); | ||
| } | ||
|
|
||
| DataLayoutStrategy dataLayoutStrategy = | ||
| partitionFields.isEmpty() | ||
| ? DataLayoutStrategy.FLAT | ||
| : DataLayoutStrategy.HIVE_STYLE_PARTITION; | ||
|
|
||
| // Get the timestamp | ||
| long timestamp = snapshot.getTimestamp(engine) * 1000; // Convert to milliseconds | ||
| System.out.println("InternalTable basepath" + basePath); | ||
| 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) { | ||
| throw new RuntimeException("Failed to extract table information using Delta Kernel", e); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.