forked from delta-io/delta
-
Notifications
You must be signed in to change notification settings - Fork 0
[WIP][KERNEL][VARIANT] Add basic read in delta kernel #2
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
Closed
Closed
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d322fb4
minimal support
richardc-db 5dea4fe
test
richardc-db 2df6702
cross compile
richardc-db d9edb9a
style
richardc-db 5ecf46d
fix compile
richardc-db 2ffa859
cross compile spark test dep for kernel defaults
richardc-db e409b95
init no tests yet
richardc-db 00a3bb5
fix reads
richardc-db ebfe49f
changename
richardc-db bb21809
use get child instead
richardc-db 9a0bc09
fix compile
richardc-db fee5be7
fix
richardc-db 400e229
changes
richardc-db 65f51f1
use defaultvariantvalue
richardc-db 45f0b3a
rebase
richardc-db ddc75dc
switch to variant coalesce expression
richardc-db 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
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
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
25 changes: 25 additions & 0 deletions
25
kernel/kernel-api/src/main/java/io/delta/kernel/data/VariantValue.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,25 @@ | ||
/* | ||
* Copyright (2024) The Delta Lake Project Authors. | ||
* | ||
* Licensed 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 io.delta.kernel.data; | ||
|
||
/** | ||
* Abstraction to represent a single Variant value in a {@link ColumnVector}. | ||
*/ | ||
public interface VariantValue { | ||
byte[] getValue(); | ||
|
||
byte[] getMetadata(); | ||
} |
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
70 changes: 70 additions & 0 deletions
70
kernel/kernel-api/src/main/java/io/delta/kernel/internal/util/VariantUtils.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,70 @@ | ||
/* | ||
* Copyright (2024) The Delta Lake Project Authors. | ||
* | ||
* Licensed 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 io.delta.kernel.internal.util; | ||
|
||
import java.util.Arrays; | ||
|
||
import io.delta.kernel.client.ExpressionHandler; | ||
import io.delta.kernel.data.ColumnVector; | ||
import io.delta.kernel.data.ColumnarBatch; | ||
import io.delta.kernel.expressions.*; | ||
import io.delta.kernel.types.*; | ||
|
||
public class VariantUtils { | ||
public static ColumnarBatch withVariantColumns( | ||
ExpressionHandler expressionHandler, | ||
ColumnarBatch dataBatch) { | ||
for (int i = 0; i < dataBatch.getSchema().length(); i++) { | ||
StructField field = dataBatch.getSchema().at(i); | ||
if (!(field.getDataType() instanceof StructType) && | ||
!(field.getDataType() instanceof ArrayType) && | ||
!(field.getDataType() instanceof MapType) && | ||
(field.getDataType() != VariantType.VARIANT || | ||
dataBatch.getColumnVector(i).getDataType() == VariantType.VARIANT)) { | ||
continue; | ||
} | ||
|
||
ExpressionEvaluator evaluator = expressionHandler.getEvaluator( | ||
// Field here is variant type if its actually a variant. | ||
// TODO: probably better to pass in the schema as an argument | ||
// so the schema is enforced at the expression level. Need to pass in a literal | ||
// schema | ||
new StructType().add(field), | ||
new ScalarExpression( | ||
"variant_coalesce", | ||
Arrays.asList(new Column(field.getName())) | ||
), | ||
VariantType.VARIANT | ||
); | ||
|
||
// TODO: don't need to pass in the entire batch. | ||
ColumnVector variantCol = evaluator.eval(dataBatch); | ||
// TODO: make a more efficient way to do this. | ||
dataBatch = | ||
dataBatch.withDeletedColumnAt(i).withNewColumn(i, field, variantCol); | ||
} | ||
return dataBatch; | ||
} | ||
|
||
private static ColumnVector[] getColumnBatchVectors(ColumnarBatch batch) { | ||
ColumnVector[] res = new ColumnVector[batch.getSchema().length()]; | ||
for (int i = 0; i < batch.getSchema().length(); i++) { | ||
res[i] = batch.getColumnVector(i); | ||
} | ||
return res; | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
kernel/kernel-api/src/main/java/io/delta/kernel/types/VariantType.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,31 @@ | ||
/* | ||
* Copyright (2024) The Delta Lake Project Authors. | ||
* | ||
* Licensed 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 io.delta.kernel.types; | ||
|
||
import io.delta.kernel.annotation.Evolving; | ||
|
||
/** | ||
* A logical variant type. | ||
* @since 4.0.0 | ||
*/ | ||
@Evolving | ||
public class VariantType extends BasePrimitiveType { | ||
public static final VariantType VARIANT = new VariantType(); | ||
|
||
private VariantType() { | ||
super("variant"); | ||
} | ||
} |
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.
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.
This may need a design decision. Is there a better interface we could provide that hides the complexity of the knowing
metadata
format?(... rough idea ... - haven't thought about all details)
VariantValue.getInt(String path) -> return integer
.