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


##########
native/core/src/parquet/schema_adapter.rs:
##########
@@ -1605,11 +1618,25 @@ pub(crate) const NANOS_TIMESTAMP_KEY: &str = 
"comet.parquet.nanos_timestamp";
 
 /// Check only requested columns, using the same resolver and conversion rules 
as projection
 /// adaptation. Return the first deferred failure, but continue to let 
open-time errors win.
+///
+/// When `options` fails on a file field requested more than once, this also 
checks the required
+/// roots for one, after the per-column checks, as Spark checks its requested 
schema once it has
+/// clipped every field of it. Nested groups are checked by the per-column 
checks. Comet does not
+/// yet check the shape of a root field that loses its file column 
(apache/datafusion-comet#7207),
+/// so for a root conflict whose losing field has the wrong shape, Spark 
reports the shape and
+/// this reports the field requested twice.
 pub(crate) fn check_file_conversions(
     required: SchemaRef,
     physical: SchemaRef,
     options: SparkParquetOptions,
 ) -> DataFusionResult<Option<RejectOnNonEmpty>> {
+    let roots = options.fail_on_field_requested_more_than_once.then(|| {
+        (
+            Arc::clone(&physical),
+            options.case_sensitive,
+            options.use_field_id,
+        )
+    });
     let adapter = SparkPhysicalExprAdapterFactory::new(options, None)
         .create(Arc::clone(&required), physical)?;

Review Comment:
   Done in e8e95b6ac: `check_file_conversions` reads the three flags into 
locals before `options` moves, and clones `physical` into `create`, so the 
tuple is gone.
   



##########
spark/src/main/scala/org/apache/comet/serde/SparkFixes.scala:
##########
@@ -81,6 +81,24 @@ private[comet] object SparkFixes {
       case (major, minor, _) => major > 4 || (major == 4 && minor >= 3)
     }
 
+  /**
+   * SPARK-60262: a Parquet read fails with 
PARQUET_FIELD_REQUESTED_MORE_THAN_ONCE when two
+   * requested fields of a struct, or of the top-level schema, resolve to the 
same Parquet field.
+   * That happens when `spark.sql.parquet.fieldId.read.enabled` is on and one 
field is matched by
+   * id and another by name, or two fields have the same id. Earlier releases 
read without an
+   * error: the parquet-mr reader gives one of the two fields NULL, and the 
vectorized reader
+   * leaves one of the two vectors unwritten.
+   */
+  def failsOnFieldRequestedMoreThanOnce(sparkVersion: String): Boolean =
+    // On branch-4.0, branch-4.1, branch-4.2, branch-4.3 and master, and in 
the 4.0.5, 4.1.4, 4.2.1
+    // and 4.3.0 releases, the same releases as the three fixes above.
+    Utils.majorMinorPatchVersion(sparkVersion).exists {
+      case (4, 0, patch) => patch >= 5
+      case (4, 1, patch) => patch >= 4
+      case (4, 2, patch) => patch >= 1
+      case (major, minor, _) => major > 4 || (major == 4 && minor >= 3)
+    }

Review Comment:
   Done in 5931859bc. `SparkFixes.failsOnFieldRequestedMoreThanOnce` and its 
two tests are gone. `CometNativeScan` now asks 
`ShimParquetErrors.failsOnFieldRequestedMoreThanOnce`, which is `false` in 
`spark-3.x` and 
`SparkThrowableHelper.isValidErrorClass("PARQUET_FIELD_REQUESTED_MORE_THAN_ONCE")`
 in `spark-4.x`. The flag is on exactly when `ShimSparkErrorConverter` can 
build the exception, and a build that carries the fix under an older version 
string gets it too.
   
   `SparkErrorConverterSuite` has two new tests. One pins the shim to the 
release table for plain releases and is skipped for snapshots and other builds. 
The other checks that the converter wraps the `SparkRuntimeException` in 
`FAILED_READ_FILE.NO_HINT` when Spark has the class. That is the shim case that 
CI cannot reach, since it is skipped on the releases CI builds against. I ran 
both on 3.5.9, 4.0.4, 4.0.5, 4.1.3, 4.1.4, 4.2.0 and 4.2.1: the flag is on for 
exactly 4.0.5, 4.1.4 and 4.2.1, and the converter test passes on those three.
   



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