snmvaughan opened a new pull request, #7820: URL: https://github.com/apache/datafusion-comet/pull/7820
## Which issue does this PR close? Closes #7819. ## Rationale for this change [SPARK-60262](https://issues.apache.org/jira/browse/SPARK-60262) (apache/spark#59510) is in Spark 4.0.5, 4.1.4, 4.2.1 and 4.3.0. With `spark.sql.parquet.fieldId.read.enabled=true`, `ParquetReadSupport` now fails the read with `PARQUET_FIELD_REQUESTED_MORE_THAN_ONCE` when two requested fields of one group, the root or a struct, resolve to the same Parquet field. That covers a field matched by id plus one matched by name, and two fields with the same id. Earlier releases read without an error. Comet's native scan resolves these fields itself (#7196). It gave the file column to the id match and NULL to the name match, so on a Spark with SPARK-60262 Spark fails the read where Comet returned rows. The `Parquet field claims` tests compare Comet with Spark's own read, so on such a Spark most of them fail in that read, before Comet runs. The conflict depends on the file's own schema, so scan planning cannot see it, and nothing in the plan tells Comet which behavior applies. Comet picks it by Spark version, as #7171 and #7522 do for other Spark fixes. ## What changes are included in this PR? - `SparkFixes.failsOnFieldRequestedMoreThanOnce` holds the version check: 4.0.5+, 4.1.4+, 4.2.1+ and 4.3+, the same releases as the other fixes there. - `NativeScanCommon.fail_on_field_requested_more_than_once` carries it to the native scan. `CometNativeScan` sets it when field-id reads are on and the check holds, and it reaches `SparkParquetOptions` through `init_datasource_exec`. - `FieldResolver` finds the first file field that a second requested field selects, and every requested field that selects it, in request order. Spark does the same in `checkNoFieldRequestedMoreThanOnce` once it has clipped every requested field of the group, so the error is raised at the point where Spark raises it: - A nested group records it in `FieldMatches`, and `check_nested_conversion` raises it after the sibling verdicts. A rejection of a field's shape still comes first, as in Spark, where clipping a struct over a primitive column fails with "is not a group". A deferred leaf rejection, which Spark raises only while it decodes, comes after it. The runtime struct conversion raises it before it converts a value. - The root is checked against the required roots in `check_file_conversions`, after the per-column checks. The scan's own adapter resolves against every root of the data schema, which Spark's pruned requested schema does not hold, so it never raises it. The footer step runs `check_file_conversions` for every file when the option is on. - `SparkError::ParquetFieldRequestedMoreThanOnce` and the Spark 4.x `ShimSparkErrorConverter` build Spark's `SparkRuntimeException` from its error class with Spark's three parameters, because `QueryExecutionErrors.parquetFieldRequestedMoreThanOnceError` is not in the Spark versions Comet builds against. It is wrapped in `FAILED_READ_FILE.NO_HINT` like the duplicate field id error next to it. - `CometNativeReaderSuite`: `whenSparkReads` runs a comparison with Spark only when Spark can read the file. When Spark fails with the new error, the test checks that Comet fails with the same message instead, from the native reader or, where the test expects a fallback, from Spark. The tests of a losing container and of a single-column projection over repeated ids need no change: Spark fails them earlier with its own error, or does not see the conflict. - `parquet.md` describes the behavior by release. ## How are these changes tested? - Rust unit tests in `field_resolver.rs` follow Spark's own tests for the error: an id match and a name match in either order and in a case-sensitive read, two fields with one id around an unrelated field, every requester named in request order, no error for fields that select different or no file fields, backticks doubled in the message, and the precedence of a selection error over this one. Tests in `schema_adapter.rs` cover the order of a nested group's errors (shape first, deferred leaf after) and a root check that uses only the required roots. - `error.rs` checks the new error's full message against Spark's template, and its JSON parameters, error class and exception class. - `SparkFixesSuite` pins the version boundaries of the new check with the other three that share its releases. - `CometNativeReaderSuite` (184 tests) passes on Spark 3.5.9, 4.0.4, 4.0.5, 4.1.3, 4.1.4, 4.2.0 and 4.2.1, run on this change before it was rebased onto `main` at `785e96170`. On 4.0.5, 4.1.4 and 4.2.1, which have SPARK-60262, the tests whose requested schema holds both fields read the file with Spark first, and the log of the 4.2.1 run holds Spark's `SparkRuntimeException` and Comet's native error for the same fields, which `whenSparkReads` compares. 3.5.9 needs `whenSparkReads` to capture the error in a `var`, because `withSQLConf` returns `Unit` before Spark 4.0, and its run used that form. - Before the rebase: `cargo test` for the native workspace passed apart from the five `parquet::objectstore::http_metrics` tests, which bind a loopback listener and could not do so where they ran, `cargo fmt --all -- --check` and `cargo clippy --all-targets --workspace -- -D warnings` were clean, and the scalafix check (`-Pspark-4.1 clean compile test-compile scalafix:scalafix -Psemanticdb -Dscalafix.mode=CHECK`) passed. - After the rebase onto `main` at `785e96170`: `cargo fmt --all -- --check` is clean, `cargo check --all-targets` passes for `datafusion-comet` and `datafusion-comet-common`, and the Scala `test-compile`, with scalastyle and spotless, passes on the default profile and on `-Pspark-3.5`. The tests have not run since the rebase, so this PR's CI is their first run on top of current `main`. -- 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]
