rdblue commented on a change in pull request #398: Push down StringStartsWith
in Spark IcebergSource
URL: https://github.com/apache/incubator-iceberg/pull/398#discussion_r318196009
##########
File path:
parquet/src/main/java/org/apache/iceberg/parquet/ParquetMetricsRowGroupFilter.java
##########
@@ -339,6 +341,47 @@ public Boolean or(Boolean leftResult, Boolean
rightResult) {
return ROWS_MIGHT_MATCH;
}
+ @Override
+ @SuppressWarnings("unchecked")
+ public <T> Boolean startsWith(BoundReference<T> ref, Literal<T> lit) {
+ int id = ref.fieldId();
+
+ Long valueCount = valueCounts.get(id);
+ if (valueCount == null) {
+ // the column is not present and is all nulls
+ return ROWS_CANNOT_MATCH;
+ }
+
+ Statistics<Binary> colStats = (Statistics<Binary>) stats.get(id);
+ if (colStats != null && !colStats.isEmpty()) {
+ if (!colStats.hasNonNullValue()) {
+ return ROWS_CANNOT_MATCH;
+ }
+
+ Binary prefixAsBinary =
Binary.fromConstantByteBuffer(lit.toByteBuffer());
+
+ PrimitiveComparator<Binary> comparator =
PrimitiveComparator.UNSIGNED_LEXICOGRAPHICAL_BINARY_COMPARATOR;
+
+ Binary lower = colStats.genericGetMin();
+ // truncate lower bound so that its length in bytes is not greater
than the length of prefix
+ int lowerLength = Math.min(prefixAsBinary.length(), lower.length());
+ int lowerCmp = comparator.compare(lower.slice(0, lowerLength),
prefixAsBinary);
Review comment:
I just looked at Parquet and I think it is going to be cheaper to use
`toByteBuffer().slice(...)` instead of `slice(...)` because the slice
implementation for most of the `Binary` implementations calls
`getBytesUnsafe()` that returns a `byte[]` and usually copies data.
Another minor point is that I think it would be better to use Iceberg's
comparators instead of Parquet's comparators to ensure we have the same
behavior everywhere. So I think this should be updated to convert the binary to
a byte buffer, slice that, and then compare the two using Iceberg's
`Comparators.unsignedBytes()`.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]