adriangb commented on code in PR #20854:
URL: https://github.com/apache/datafusion/pull/20854#discussion_r2926464080
##########
datafusion/datasource-parquet/src/row_filter.rs:
##########
@@ -519,6 +562,149 @@ fn leaf_indices_for_roots(
.collect()
}
+/// Resolves struct field access to specific Parquet leaf column indices
+///
+/// For every `StructFieldAccess`, finds the leaf columns in the Parquet schema
+/// whose path matches the struct root name + field path. This avoids reading
all
+/// leaves of a struct when only specific fields are needed
+fn resolve_struct_field_leaves(
+ accesses: &[StructFieldAccess],
+ file_schema: &Schema,
+ schema_descr: &SchemaDescriptor,
+) -> Vec<usize> {
+ let mut leaf_indices = Vec::new();
+
+ for access in accesses {
+ let root_name = file_schema.field(access.root_index).name();
+ let prefix = std::iter::once(root_name.as_str())
+ .chain(access.field_path.iter().map(|p| p.as_str()))
+ .collect::<Vec<_>>();
+
+ for leaf_idx in 0..schema_descr.num_columns() {
+ let col = schema_descr.column(leaf_idx);
+ let col_path = col.path().parts();
+
+ // A leaf matches if its path starts with our prefix.
+ // e.g., prefix=["s", "value"] matches leaf path ["s", "value"]
+ // prefix=["s", "outer"] matches ["s", "outer", "inner"]
+
+ // a leaf matches iff its path starts with our prefix
+ // for example: prefix=["s", "value"] matches leaf path ["s",
"value"]
+ // prefix=["s", "outer"] matches ["s", "outer",
"inner"]
+ let leaf_matches_path = col_path.len() >= prefix.len()
+ && col_path.iter().zip(prefix.iter()).all(|(a, b)| a == b);
+
+ if leaf_matches_path {
+ leaf_indices.push(leaf_idx);
+ }
+ }
+ }
+
+ leaf_indices
+}
+
+/// Builds a filter schema that includes only the fields actually accessed by
the
+/// filter expression.
+///
+/// For regular (non-struct) columns, the full field type is used.
+/// For struct columns accessed via `get_field`, a pruned struct type is
created
Review Comment:
Okay interesting. I would have thought that `ProjectionMask::leaves`
returned a flat column, not a nested struct. Thanks for explaining 😄
--
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]