snmvaughan commented on code in PR #7820:
URL: https://github.com/apache/datafusion-comet/pull/7820#discussion_r4773929805


##########
native/core/src/parquet/field_resolver.rs:
##########
@@ -299,12 +337,49 @@ impl<'a> FieldResolver<'a> {
     /// nested conversion validates every requested field in 
[`Self::resolve_all`].
     pub(crate) fn file_claims(&self) -> DataFusionResult<Vec<FieldClaim>> {
         let mut claims = vec![FieldClaim::Unchanged; self.file.len()];
+        let mut selected = Vec::new();
         for requested in 0..self.requested.len() {
-            self.record_claims(&mut claims, requested, 
self.select(requested)?);
+            let selection = self.select(requested)?;
+            self.record_claims(&mut claims, requested, selection);
+            if self.fail_on_field_requested_more_than_once {
+                selected.push(selection.file());
+            }
+        }
+        if let Some((requested_fields, parquet_field)) = 
self.requested_more_than_once(&selected) {
+            return Err(requested_more_than_once_error(
+                &requested_fields,
+                &parquet_field,
+            ));
         }
         Ok(claims)
     }
 
+    /// The requested fields and the file field of 
`PARQUET_FIELD_REQUESTED_MORE_THAN_ONCE`, both
+    /// quoted, when two requested fields select the same file field and this 
resolver fails on
+    /// it, as Spark's `checkNoFieldRequestedMoreThanOnce` does once it has 
clipped every requested
+    /// field of the group. `selected` holds the file field each requested 
field reads, in request
+    /// order. It names the first file field that a second requested field 
selects and every
+    /// requested field that selects it, in request order.
+    fn requested_more_than_once(&self, selected: &[Option<usize>]) -> 
Option<(String, String)> {

Review Comment:
   Done as you describe, in e8e95b6ac. `check_requested_once(requested, file, 
selected)` is a free function in `field_resolver.rs` over the file field each 
requested field selects. `check_nested_conversion` calls it with 
`FieldMatches::selected()`, and the root check in `check_file_conversions` 
builds `selected` from `select(i)?.file()` over the required roots; both call 
it only when the option is on.
   
   `FieldResolver::new` lost the parameter, so `create` and the test helpers 
lost the hard-coded `false`. `FieldMatches` lost `requested_more_than_once`, 
and `file_claims` is back to selecting and recording claims. The resolver tests 
now run both ways of resolving a group (`resolve_all`, and one `select` per 
root) through the same function and compare the errors.
   



##########
native/core/src/parquet/parquet_support.rs:
##########
@@ -555,8 +563,11 @@ fn parquet_convert_struct_to_struct(
 ) -> DataFusionResult<(ArrayRef, bool)> {
     match (from_type, to_type) {
         (DataType::Struct(from_fields), DataType::Struct(to_fields)) => {
-            let from_indices =
-                match_struct_fields(from_fields, to_fields, 
parquet_options)?.into_owned();
+            let matches = match_struct_fields(from_fields, to_fields, 
parquet_options)?;
+            // The plan-time check raises this first. Raise it here too, 
before converting any
+            // value, as Spark does before it reads any.
+            matches.check_requested_once()?;
+            let from_indices = matches.into_owned();

Review Comment:
   You are right, it was unreachable. Apart from the scalar conversion of a 
column default, which has no file field to request twice, 
`parquet_convert_struct_to_struct` runs only through a `CometCastColumnExpr`. 
The adapter builds one for a struct, list or map column only after 
`check_field_conversion` has accepted it, so `check_nested_conversion` has 
already raised the error at open. (Variant columns skip that check, but their 
two fields cannot select the same file field.) When the flag is on, the footer 
step also runs `check_file_conversions` for every file before that, and no test 
reached the runtime call.
   
   Removed in e8e95b6ac. `resolve_all` no longer computes the verdict, or 
allocates the `taken` vector, for every struct of every batch.
   



-- 
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]

Reply via email to