Repository navigation
fix: reject plain Parquet fixed-length binary columns read as strings - #7839
ningsiyuan1024 wants to merge 2 commits into
Conversation
comphead
left a comment
There was a problem hiding this comment.
The rejection matches Spark. In ParquetVectorUpdaterFactory.getUpdater on 3.5.8, 4.0.1 and 4.1.1 the FIXED_LEN_BYTE_ARRAY branch has no StringType case, so the column falls through to constructConvertNotSupportedException with the physical type name and sparkType.catalogString(). spark.sql.parquet.binaryAsString only affects BINARY in ParquetToSparkSchemaConverter, so ignoring it is correct. Nested leaves go through check_nested_conversion into the same spark_has_updater, so structs, lists and maps are covered. The comments are about the flag default, how this lines up with #6246, and two untested shapes.
| if options.reject_fixed_binary_as_string | ||
| && matches!(physical_type, DataType::FixedSizeBinary(_)) | ||
| && target_type.is_string() | ||
| { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
The flag defaults to the lenient behavior, so Spark's behavior applies only where get_options sets it. I grepped SparkParquetOptions::new at this head and the only production callers are get_options in parquet_exec.rs and iceberg_scan.rs (line 275), the rest are tests and benches. Inverting the flag, for example render_fixed_binary_as_uuid set in iceberg_scan.rs, makes Spark's behavior the default for any future plain Parquet entry point and puts the exception next to the only code that needs it. The Iceberg half of the Rust test below would then set the flag instead of relying on the default.
#6246 adds a binary_as_string gated check of the same FixedSizeBinary to string pair at the top of spark_has_updater, and the same FIXED_LEN_BYTE_ARRAY arm in parquet_primitive_name. The two agree on behavior, but they will conflict textually. Once this PR is in, that check is redundant for the plain scan because this flag is always set there, so whichever lands second should drop its copy.
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn fixed_binary_string_read_depends_on_scan_type() -> Result<(), DataFusionError> { |
There was a problem hiding this comment.
This covers only a top-level column. The nested path is a separate recursion (check_nested_conversion), so a struct field and a list element holding FixedSizeBinary read as Utf8 deserve one assertion each, for example with check_conversion as the tests near line 4328 do. The Iceberg side matters for nested too, since a nested UUID must stay accepted with the flag off. I did not run this.
| } | ||
|
|
||
| test("native scan rejects fixed-length binary requested as string with binaryAsString off") { | ||
| withSQLConf( |
There was a problem hiding this comment.
The test pins PARQUET_BINARY_AS_STRING to false, but the PR's whole point is that Spark rejects the pair whatever that setting says (it only changes BINARY schema inference). Looping over Seq(false, true) locks that in and exercises the interaction with #6246, which gates a related check on binaryAsString. The test name would then drop the with binaryAsString off suffix. I did not run this.
Which issue does this PR close?
Closes #7815.
Rationale for this change
With an explicit STRING read schema, Spark rejects an unannotated FIXED_LEN_BYTE_ARRAY. Comet emitted an unstructured cast error for three bytes and silently formatted sixteen bytes as a UUID.
What changes are included in this PR?
Reject this conversion in the plain Parquet scan and report the Spark schema-mismatch condition with the physical type. Keep the Iceberg UUID conversion available.
How are these changes tested?
The native schema adapter suite passed all 106 tests. On Spark 4.1.1 with the Dec 2 ASF Comet JVM snapshot and the native library built from this commit, both widths raised FAILED_READ_FILE.PARQUET_COLUMN_DATA_TYPE_MISMATCH with SQLSTATE KD001 and the same underlying exception as Spark. BINARY reads returned identical bytes. A real Iceberg 1.11.0 table returned the same three UUIDs from Spark and CometIcebergNativeScanExec. The patch also includes Scala regression coverage.
We defined the requirements and acceptance criteria. OpenAI Codex was responsible for execution, including implementing the changes and running the tests.