gaborkaszab commented on code in PR #16582:
URL: https://github.com/apache/iceberg/pull/16582#discussion_r3333468984
##########
api/src/main/java/org/apache/iceberg/PartitionStatisticsScan.java:
##########
@@ -42,6 +42,17 @@ public interface PartitionStatisticsScan {
*/
PartitionStatisticsScan filter(Expression filter);
+ /**
+ * Create a new scan from this that will configure whether column name
matches in filter
+ * expressions are case-sensitive.
Review Comment:
Done
##########
core/src/main/java/org/apache/iceberg/BasePartitionStatisticsScan.java:
##########
@@ -77,16 +93,43 @@ public CloseableIterable<PartitionStatistics> scan() {
Types.StructType partitionType = Partitioning.partitionType(table);
Schema schema = PartitionStatistics.schema(partitionType,
TableUtil.formatVersion(table));
- Schema readSchema =
- projection == null ? schema : TypeUtil.select(schema,
TypeUtil.getProjectedIds(projection));
+ Schema readSchema = readSchema(schema);
FileFormat fileFormat = FileFormat.fromFileName(statsFile.get().path());
Preconditions.checkNotNull(
fileFormat != null, "Unable to determine format of file: %s",
statsFile.get().path());
- return InternalData.read(fileFormat,
table.io().newInputFile(statsFile.get().path()))
- .project(readSchema)
- .setRootType(BasePartitionStatistics.class)
- .build();
+ CloseableIterable<PartitionStatistics> result =
+ InternalData.read(fileFormat,
table.io().newInputFile(statsFile.get().path()))
+ .project(readSchema)
+ .setRootType(BasePartitionStatistics.class)
+ .build();
+
+ if (filter != Expressions.alwaysTrue()) {
+ Evaluator evaluator = new Evaluator(readSchema.asStruct(), filter,
caseSensitive);
+ result = CloseableIterable.filter(result, evaluator::eval);
+ }
+
+ return result;
+ }
+
+ /**
+ * Resolves the schema to read. When a projection is set, all columns
referenced by the filter are
+ * added to the result not just the projected fields.
+ */
+ private Schema readSchema(Schema schema) {
+ if (projection == null) {
+ return schema;
+ }
+
+ Set<Integer> requiredFieldIds = Sets.newHashSet();
Review Comment:
Well, either could be fine: requested IDs through projection, pus the
required one to evaluate the filter.
##########
core/src/main/java/org/apache/iceberg/BasePartitionStatisticsScan.java:
##########
@@ -77,16 +93,43 @@ public CloseableIterable<PartitionStatistics> scan() {
Types.StructType partitionType = Partitioning.partitionType(table);
Schema schema = PartitionStatistics.schema(partitionType,
TableUtil.formatVersion(table));
- Schema readSchema =
- projection == null ? schema : TypeUtil.select(schema,
TypeUtil.getProjectedIds(projection));
+ Schema readSchema = readSchema(schema);
FileFormat fileFormat = FileFormat.fromFileName(statsFile.get().path());
Preconditions.checkNotNull(
fileFormat != null, "Unable to determine format of file: %s",
statsFile.get().path());
- return InternalData.read(fileFormat,
table.io().newInputFile(statsFile.get().path()))
- .project(readSchema)
- .setRootType(BasePartitionStatistics.class)
- .build();
+ CloseableIterable<PartitionStatistics> result =
+ InternalData.read(fileFormat,
table.io().newInputFile(statsFile.get().path()))
+ .project(readSchema)
+ .setRootType(BasePartitionStatistics.class)
+ .build();
+
+ if (filter != Expressions.alwaysTrue()) {
+ Evaluator evaluator = new Evaluator(readSchema.asStruct(), filter,
caseSensitive);
+ result = CloseableIterable.filter(result, evaluator::eval);
+ }
+
+ return result;
+ }
+
+ /**
+ * Resolves the schema to read. When a projection is set, all columns
referenced by the filter are
+ * added to the result not just the projected fields.
+ */
+ private Schema readSchema(Schema schema) {
+ if (projection == null) {
+ return schema;
+ }
+
+ Set<Integer> requiredFieldIds = Sets.newHashSet();
+
+ requiredFieldIds.addAll(TypeUtil.getProjectedIds(projection));
Review Comment:
No, because projection is done via field IDs not field names. The input for
that is a Schema of fields, where we use the field IDs.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]