-
Notifications
You must be signed in to change notification settings - Fork 68
feat: blob v2 descriptor read support #548
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
Merged
+413
−6
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
152 changes: 152 additions & 0 deletions
152
lance-spark-base_2.12/src/test/java/org/lance/spark/utils/BlobUtilsTest.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,152 @@ | ||
| /* | ||
| * 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 org.lance.spark.utils; | ||
|
|
||
| import org.apache.arrow.vector.types.pojo.ArrowType; | ||
| import org.apache.arrow.vector.types.pojo.Field; | ||
| import org.apache.arrow.vector.types.pojo.FieldType; | ||
| import org.apache.spark.sql.types.DataTypes; | ||
| import org.apache.spark.sql.types.Metadata; | ||
| import org.apache.spark.sql.types.MetadataBuilder; | ||
| import org.apache.spark.sql.types.StructField; | ||
| import org.apache.spark.sql.types.StructType; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| public class BlobUtilsTest { | ||
|
|
||
| @Test | ||
| public void testBlobV2FieldWithArrowExtensionName() { | ||
| assertTrue(BlobUtils.isBlobV2SparkField(blobV2Field())); | ||
| } | ||
|
|
||
| @Test | ||
| public void testBlobV2FieldNullSafety() { | ||
| assertFalse(BlobUtils.isBlobV2SparkField(null)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testV1Field() { | ||
| assertTrue(BlobUtils.isBlobSparkField(blobV1Field())); | ||
| } | ||
|
|
||
| @Test | ||
| public void testBlobV2ArrowFieldRejectsUnrelated() { | ||
| Field f = | ||
| new Field( | ||
| "payload", | ||
| new FieldType(true, ArrowType.Binary.INSTANCE, null, Collections.emptyMap()), | ||
| null); | ||
| assertFalse(BlobUtils.isBlobV2ArrowField(f)); | ||
| assertFalse(BlobUtils.isBlobV2ArrowField(null)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testHasBlobV2FieldsInSchema() { | ||
| StructType schema = | ||
| new StructType( | ||
| new StructField[] { | ||
| field("id", DataTypes.IntegerType), blobV2Field(), | ||
| }); | ||
| assertTrue(BlobUtils.hasBlobV2Fields(schema)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDescriptorStructShape() { | ||
| StructType s = BlobUtils.BLOB_DESCRIPTOR_STRUCT; | ||
| assertEquals(5, s.fields().length); | ||
| assertEquals(DataTypes.ShortType, s.apply("kind").dataType()); | ||
| assertEquals(DataTypes.LongType, s.apply("position").dataType()); | ||
| assertEquals(DataTypes.LongType, s.apply("size").dataType()); | ||
| assertEquals(DataTypes.LongType, s.apply("blob_id").dataType()); | ||
| assertEquals(DataTypes.StringType, s.apply("blob_uri").dataType()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testBlobV2DescriptorSchemaRewrite() { | ||
| StructType schema = | ||
| new StructType( | ||
| new StructField[] { | ||
| field("id", DataTypes.IntegerType), blobV2Field(), | ||
| }); | ||
| StructType rewritten = BlobUtils.applyBlobV2DescriptorSchema(schema); | ||
| assertEquals(DataTypes.IntegerType, rewritten.apply("id").dataType()); | ||
| assertEquals(BlobUtils.BLOB_DESCRIPTOR_STRUCT, rewritten.apply("payload").dataType()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testV1FieldsPreservedInRewrite() { | ||
| StructType schema = | ||
| new StructType( | ||
| new StructField[] { | ||
| field("id", DataTypes.IntegerType), blobV1Field(), | ||
| }); | ||
| StructType rewritten = BlobUtils.applyBlobV2DescriptorSchema(schema); | ||
| assertEquals(DataTypes.BinaryType, rewritten.apply("payload").dataType()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testUnloadedDescriptorStructRecognizedAsBlobV2() { | ||
| Field f = | ||
| new Field( | ||
| "payload", | ||
| new FieldType(true, ArrowType.Struct.INSTANCE, null, Collections.emptyMap()), | ||
| Arrays.asList( | ||
| intChild("kind"), | ||
| intChild("position"), | ||
| intChild("size"), | ||
| intChild("blob_id"), | ||
| utf8Child("blob_uri"))); | ||
| assertTrue(BlobUtils.isBlobV2ArrowField(f)); | ||
| assertFalse(BlobUtils.isBlobArrowField(f)); | ||
| } | ||
|
|
||
| private static Field intChild(String name) { | ||
| return new Field( | ||
| name, | ||
| new FieldType(true, new ArrowType.Int(64, false), null, Collections.emptyMap()), | ||
| null); | ||
| } | ||
|
|
||
| private static Field utf8Child(String name) { | ||
| return new Field( | ||
| name, new FieldType(true, ArrowType.Utf8.INSTANCE, null, Collections.emptyMap()), null); | ||
| } | ||
|
|
||
| private static StructField field(String name, org.apache.spark.sql.types.DataType dt) { | ||
| return new StructField(name, dt, true, Metadata.empty()); | ||
| } | ||
|
|
||
| private static StructField blobV2Field() { | ||
| Metadata md = | ||
| new MetadataBuilder() | ||
| .putString(BlobUtils.ARROW_EXTENSION_NAME_KEY, BlobUtils.ARROW_EXTENSION_BLOB_V2) | ||
| .build(); | ||
| return new StructField("payload", DataTypes.BinaryType, true, md); | ||
| } | ||
|
|
||
| private static StructField blobV1Field() { | ||
| Metadata md = | ||
| new MetadataBuilder() | ||
| .putString(BlobUtils.LANCE_ENCODING_BLOB_KEY, BlobUtils.LANCE_ENCODING_BLOB_VALUE) | ||
| .build(); | ||
| return new StructField("payload", DataTypes.BinaryType, true, md); | ||
| } | ||
| } |
Oops, something went wrong.
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.
Does it make sense to store position / size or would it be better to store the _rowaddr? When we read this the former means we need to open an objectstore reader and request the bytes, if we use
_rowaddrthen we can use the lance-native tools to call liketake_blobsI think which handles coalesced reads / etc.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.
Sorry for the late response here Dan. Got sidetracked with some other work.
Row addresses should already be exposed on the same row along side the descriptor as a metadata column.
lance-spark/lance-spark-base_2.12/src/main/java/org/lance/spark/LanceDataset.java
Lines 99 to 104 in 20345de
I think adding it to the struct would be redundant, and kind of blur the the line between row identity, and storage layout.