cool9850311 opened a new pull request, #27810: URL: https://github.com/apache/datafusion/pull/27810
## Which issue does this PR close? <!-- No issue is open for this; it follows up on a review comment. --> - Follow-up to https://github.com/apache/datafusion/pull/27474#discussion_r4708000035. ## Rationale for this change A comparison against a dictionary-encoded column keeps its `CAST` on the column whenever the comparison's common type differs from the dictionary's value type, so the predicate cannot be pushed into pruning or evaluated on the dictionary keys. Two cases reach that today. The one #27474 introduced is a `DECIMAL(p, s)` column with `s >= 19`, which takes a `Decimal256` common type against an integer literal: ```sql -- d is Dictionary(Int32, Decimal128(38, 24)) > explain select d from t where d in (4, 5); Filter: CAST(t.d AS Decimal256(44, 24)) = Decimal256(4.0…) OR … ``` The other predates it: an integer dictionary column against an integer literal takes the wider integer as its common type, so `i = 5` on a `Dictionary(Int32, Int32)` column runs `CAST(i AS Int64) = 5`. In both cases the literal has an exact preimage in the column's value type, and only the dictionary wrapper stops `try_cast_literal_to_type` from producing it. ## What changes are included in this PR? `try_cast_dictionary` gains one arm: when the target is a `Dictionary` whose value type differs from the literal's type, the literal is converted to that value type with `try_cast_numeric_literal` before being wrapped, and the conversion's own exactness rules decide whether the rewrite happens at all. A dictionary whose value type is a *different string type* is still not converted, since only the numeric conversion is attempted; the rustdoc on `try_cast_literal_to_type` is reworded to say so. ## What is the testing strategy for this PR? Nothing in the tree goes red without this change, so the tests are new: - `casts.rs`: `test_try_cast_to_dictionary_type_converts_the_value_type` for the literal conversion itself (including a literal the value type has no room for, and the unchanged string case) and `test_cast_predicate_preimage_dictionary_decimal256_literal` for the preimage the predicate rewrite uses, which also pins that the source dictionary key is preserved. - `simplify_expr.slt`: the `Decimal128(38, 24)` dictionary column. - `dictionary.slt`: the integer dictionary column. With the new arm removed, those two unit tests fail alone and both `.slt` files report a plan mismatch. ## Are there any user-facing changes? Plans change: the `CAST` disappears from the two cases above. No public API signature changes; `try_cast_literal_to_type` returns a value for inputs where it used to return `None`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
