Skip to content

fix: reject plain Parquet fixed-length binary columns read as strings - #7839

Open
ningsiyuan1024 wants to merge 5 commits into
apache:mainfrom
ningsiyuan1024:fix/parquet-7815
Open

ningsiyuan1024 wants to merge 5 commits into
apache:mainfrom
ningsiyuan1024:fix/parquet-7815

Conversation

@ningsiyuan1024

@ningsiyuan1024 ningsiyuan1024 commented Dec 3, 2026 •

Copy link
Copy Markdown

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?

The plain Parquet reader rejects this conversion by default. The Iceberg reader opts into rendering fixed-width UUIDs as strings. The same rule applies to struct fields and list elements.

How are these changes tested?

All 107 native schema-adapter tests passed. On Spark 4.1.1, I compared Spark and Comet on 3-byte and 16-byte Parquet fields with spark.sql.parquet.binaryAsString both on and off. All eight STRING reads raised FAILED_READ_FILE.PARQUET_COLUMN_DATA_TYPE_MISMATCH (SQLSTATE KD001). All eight BINARY reads returned the original bytes.

On an Iceberg 1.11.0 table, Spark and Comet returned the same UUID at the top level, inside a struct, and inside a list. The executed plan confirmed the native Iceberg scan. These runs used the rebuilt JNI library with a cached Comet JVM snapshot. The extracted Scala regression compiled. The full Maven suite did not run because the offline cache lacked maven-remote-resources-plugin:1.7.0.

We defined the requirements and acceptance criteria. OpenAI Codex was responsible for execution, including implementing the changes and running the tests.

@comphead comphead left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +481 to +486
if options.reject_fixed_binary_as_string
&& matches!(physical_type, DataType::FixedSizeBinary(_))
&& target_type.is_string()
{
return false;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tracing the callers, @comphead. In f5c9ec9 the plain reader rejects this conversion by default, and the Iceberg scan opts into UUID rendering. All 107 schema-adapter tests passed. I also checked the overlap with #6246. If that lands first, this branch will need to reconcile the shared type check and physical type name.

}

#[tokio::test]
async fn fixed_binary_string_read_depends_on_scan_type() -> Result<(), DataFusionError> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f5c9ec9 adds struct-field and list-element cases for both the plain and Iceberg options. I also read a real Iceberg 1.11.0 table with Spark 4.1.1: the top-level, struct and list UUIDs matched the Spark reference, and the executed plan contained CometIcebergNativeScanExec.

}

test("native scan rejects fixed-length binary requested as string with binaryAsString off") {
withSQLConf(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Scala regression now loops over both binaryAsString values. In 16 Spark/Comet reads across 3-byte and 16-byte fixtures, all eight STRING reads raised the same schema mismatch (SQLSTATE KD001), and all eight BINARY reads returned the original bytes. The extracted Scala case compiled; the full Maven suite did not run because the offline cache lacked the remote-resources plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Match Spark’s Parquet conversion error for fixed-length binary read as STRING with binaryAsString disabled

2 participants