-
Notifications
You must be signed in to change notification settings - Fork 254
chore: various refactoring changes for iceberg [iceberg] #2680
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
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2680 +/- ##
============================================
+ Coverage 56.12% 58.31% +2.18%
- Complexity 976 1457 +481
============================================
Files 119 166 +47
Lines 11743 14130 +2387
Branches 2251 2395 +144
============================================
+ Hits 6591 8240 +1649
- Misses 4012 4690 +678
- Partials 1140 1200 +60 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
native/core/Cargo.toml
Outdated
| hdfs-sys = {version = "0.3", optional = true, features = ["hdfs_3_3"]} | ||
| opendal = { version ="0.54.1", optional = true, features = ["services-hdfs"] } | ||
| uuid = "1.0" | ||
| opendal = { version ="0.54.0", optional = true, features = ["services-hdfs"] } |
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.
is there a reason for this change? Comet could still choose to use 0.54.1 since it is semver compatible
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.
Looks like this happened due to rebasing. Reverted.
andygrove
left a comment
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.
LGTM. Thanks @parthchandra
common/src/main/java/org/apache/comet/parquet/IcebergCometNativeBatchReader.java
Show resolved
Hide resolved
common/src/main/java/org/apache/comet/parquet/IcebergCometNativeBatchReader.java
Show resolved
Hide resolved
| filteredSchema = filteredSchema.add(sparkFields[i]); | ||
| } | ||
| } | ||
| sparkSchema = filteredSchema; |
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.
Is it possible that the filtering done here may lead to ArrayIndexOutOfBoundsException at https://github.com/parthchandra/datafusion-comet/blob/d73bcbab9f80836d7229207f309283942501e9ab/common/src/main/java/org/apache/comet/parquet/NativeBatchReader.java#L985 ?
Now the sparkSchema may have less fields than before I see no new logic to protect the .fields()[i] call there.
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.
Yes, you're right. This is not entirely correct. Let me fix this.
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.
Yup. Fixed to match the fields by name.
| import org.apache.spark.sql.types.StructType; | ||
|
|
||
| /** | ||
| * A specialized NativeBatchReader for Iceberg that accepts ParquetMetadata as a JSON string. This |
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.
accepts ParquetMetadata as a JSON string - actually it accepts byte[] parquetMetadataBytes at https://github.com/apache/datafusion-comet/pull/2680/files#diff-e57878f6cd8036999500de5719f8f4bbe28e1ed5dcb79a02ad7d7eb206f37473R44, i.e. not a String but bytes.
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.
Thank you for catching this. The first version I did used JSON, but this is more efficient.
|
@parthchandra You said |
Oops. I had pushed to the wrong branch :(. Corrected. |
martin-g
left a comment
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 need unit tests for the new classes ?
| } | ||
|
|
||
| // String timeZoneId = conf.get("spark.sql.session.timeZone"); | ||
| String timeZoneId = "UTC"; |
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.
Is this intentional ?
If it is then either move the comment below one line up or add a new comment why timeZoneId should be also always UTC. The commented out conf.get("spark.sql.session.timeZone"); could be removed too.
| DataType dataType = null; | ||
| int sparkSchemaIndex = -1; | ||
| for (int j = 0; j < sparkFields.length; j++) { | ||
| if (sparkFields[j].name().equals(field.getName())) { |
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.
Should this equality check take into account spark.sql.caseSensitive ?
If it is sensitive then it could be optimized by storing the sparkFields in a Map<String, Field> and lookup by name here instead of looping over them for each field
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.
Done
| i < preInitializedReaders.length && preInitializedReaders[i] != null; | ||
| int finalI = i; | ||
| boolean existsInFileSchema = | ||
| fileFields.stream().anyMatch(f -> f.getName().equals(sparkFields[finalI].name())); |
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.
Should this equality check take into account spark.sql.caseSensitive ?
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.
Yes, it should. Fixed
| Path path = new Path(new URI(filePath)); | ||
| try (FileReader fileReader = | ||
| new FileReader( | ||
| CometInputFile.fromPath(path, conf), footer, readOptions, cometReadOptions, metrics)) { |
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 is the footer not passed anymore ? This way it will be re-read at https://github.com/parthchandra/datafusion-comet/blob/d8cd7b78c3509b2ec147d4991e0664d1a63febc1/common/src/main/java/org/apache/comet/parquet/FileReader.java#L201-L203
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.
Got removed accidentally. Thanks for catching this!
| this.sparkSchema = requiredSchema; | ||
| } | ||
|
|
||
| /** Initialize the reader using FileInfo instead of PartitionedFile. */ |
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.
| /** Initialize the reader using FileInfo instead of PartitionedFile. */ | |
| /** Initialize the reader using FileInfo instead of PartitionedFile. */ | |
| @Override |
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 is not an override. The parent init method has a different signature.
| ConstantColumnReader reader = | ||
| new ConstantColumnReader(nonPartitionFields[i], capacity, useDecimal128); | ||
| columnReaders[i] = reader; | ||
| if (preInitializedReaders != null && preInitializedReaders[i] != null) { |
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.
| if (preInitializedReaders != null && preInitializedReaders[i] != null) { | |
| if (preInitializedReaders != null && i < preInitializedReaders.length && preInitializedReaders[i] != null) { |
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.
Done
| int columnIndex = getColumnIndexFromParquetColumn(column); | ||
| if (columnIndex == -1 | ||
| || preInitializedReaders == null | ||
| || preInitializedReaders[columnIndex] == null) { |
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 probably needs a check for boundaries before trying to access this index.
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.
Done
| return fileSize; | ||
| } | ||
|
|
||
| public URI pathUri() throws Exception { |
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.
| public URI pathUri() throws Exception { | |
| public URI pathUri() throws URISyntaxException { |
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.
Done
Functionality is mostly covered by Comet tests and running Iceberg tests with Comet enabled. |
|
Merged. Thanks @martin-g, @andygrove . |
Which issue does this PR close?
Part of the changes needed for #2060
Mostly does cleanup of the
native_iceberg_compatAPIs so the they do not have Parquet classes. As a plus provides a utility class to allow ParquetMetadata to be serialized and deserialized to/from the Thrift format. This will also be useful in passing ParquetMetadata from JVM to native (for all native scan implementations). Currently the native scans end up reading Parquet metadata again (even though it has already been read in the JVM side) and this can be a costly operation in object stores.