rich7420 commented on code in PR #6246: URL: https://github.com/apache/datafusion-comet/pull/6246#discussion_r4733472129
########## docs/source/contributor-guide/spark_configs_support.md: ########## @@ -151,3 +157,70 @@ Comet bugs were uncovered by the original audit. The `try_to_timestamp` policy t use the default `query` mode to enforce both result correctness and execution within the Comet pipeline. Tests for expressions with known fallback paths continue to use `query spark_answer_only`. + +### `spark.sql.parquet.binaryAsString` + +**Source.** When enabled, Spark infers unannotated Parquet `BINARY` columns as +`StringType`. Parquet files written by Spark carry Spark schema metadata, so this +configuration does not change the types inferred for those files. The inference in +`ParquetToSparkSchemaConverter` and the `BINARY` cases of `ParquetFilters` are the same in every +Spark version listed above. + +**Comet status.** Comet honors the configuration in the native Parquet scan. When it is +enabled, the scan plans every top-level string column as Arrow `Binary`. Columns that arrow-rs reads +as `Binary` are decoded to valid UTF-8 at the scan boundary using Spark-compatible replacement +semantics. arrow-rs validates UTF-8 only for Parquet columns with the `UTF8` annotation. Reading +malformed unannotated bytes directly as Arrow `Utf8` would create an invalid string array, which is +undefined behavior. +Spark's schema doesn't say which file columns carry the `UTF8` annotation, so the expression adapter +decides per file: where arrow-rs reads the column as `Utf8`, it reads the column directly, without +the cast to `Binary` and back. This includes JSON-annotated `BINARY` columns and unannotated columns +that an embedded `ARROW:schema` types as `Utf8`. Both are read without UTF-8 validation, as they are +with the configuration off. The default `false` value continues to return unannotated +`BINARY` columns as `BinaryType`. + +**Filter pushdown.** While the configuration is enabled, the scan rewrites `=`, `IN` and +`IS [NOT] NULL` on a top-level string column to compare raw bytes, so `value = 'one'` becomes +`value = X'6F6E65'`. A valid value decodes to itself, and a malformed one to a string containing +`U+FFFD`, so for a literal without `U+FFFD` the rewritten filter keeps exactly the rows the +original keeps. Other filters on these columns compare the decoded value, because decoding can +reorder values: `"a\x80"` sorts below `"aƩ"` as bytes, but `"a\uFFFD"` sorts above it. That covers +ranges, `LIKE`, function calls and literals containing `U+FFFD`. They filter rows when +`spark.comet.parquet.rowFilterPushdown.enabled` is on, but cannot use the column's statistics for +pruning when arrow-rs reads it as `Binary`. For example, arrow-rs maps Parquet `ENUM` to `Binary`, +so a range such as `value < 'two'` can skip fewer row groups with the configuration on than with +it off. + +Where arrow-rs reads the column as `Utf8`, the expression adapter replaces the decoded +value with the column and compares the column with a string literal directly, so every filter +prunes as it does with the configuration off. Spark's `Filter` above the scan re-evaluates every +data filter, so results don't depend on what is pushed. Join and TopK dynamic filters accept only +integer keys, so they never reach these columns. Review Comment: `RuntimeFilterSchemaAdapterFactory` also checks every projected column. With the configuration on, a string column that arrow-rs reads as `Utf8` adapts to a cast to `Binary`, so the join or TopK filter no longer prunes that file. Could this paragraph mention that? ########## docs/source/user-guide/latest/parquet.md: ########## @@ -212,6 +212,14 @@ page-index, and bloom-filter pruning happen regardless of this flag whenever Spa `spark.sql.parquet.filterPushdown` is on, except for filters that compare `FLOAT` or `DOUBLE` values, which do not prune while this flag is on (see [Floating-point Number Comparison](compatibility/floating-point.md)). +With `spark.sql.parquet.binaryAsString=true`, filters on a top-level string column prune as usual +when Comet reads it as Arrow `Utf8`, as it does for strings written by Spark. When Comet reads +the column as Arrow `Binary`, as it normally does for Parquet `ENUM` and unannotated `BINARY`, +`IS [NOT] NULL` can still prune, as can `=` and `IN` when their literals contain no `U+FFFD`. +Ranges and `LIKE` compare decoded strings and cannot use the column's statistics to skip row +groups. A range such as `value < 'two'` on an `ENUM` column can therefore read more row groups +with the setting on than with it off. Review Comment: Thanks for opening #7783. Could this sentence link it, like the other issue links on this page? -- 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]
