Skip to content

fix: replace default-allow cast unwrap with closed-by-default allowlist#6

Open
discord9 wants to merge 22 commits into
GreptimeTeam:mainfrom
discord9:fix/lossy-unwrap-cast-comparisons-gt
Open

fix: replace default-allow cast unwrap with closed-by-default allowlist#6
discord9 wants to merge 22 commits into
GreptimeTeam:mainfrom
discord9:fix/lossy-unwrap-cast-comparisons-gt

Conversation

@discord9

@discord9 discord9 commented Jun 9, 2026

Copy link
Copy Markdown

Ports apache#21908 to GreptimeTeam/datafusion.\n\nSummary:\n- Replaces default-allow comparison cast unwrapping with a closed-by-default allowlist.\n- Requires literal round-trip safety before unwrapping.\n- Covers timestamp/integer/binary/string/dictionary/decimal allowlist behavior and updates logical/physical unwrap tests plus SLT expectations.\n\nValidation:\n- cargo fmt --all -- --check\n- cargo test -p datafusion-expr-common --lib test_comparison_unwrap\n- cargo test -p datafusion-optimizer --lib unwrap_cast\n- cargo test -p datafusion-physical-expr --lib unwrap_cast

discord9 added 22 commits June 9, 2026 11:39
Signed-off-by: discord9 <discord9@163.com>
Signed-off-by: discord9 <discord9@163.com>
Signed-off-by: discord9 <discord9@163.com>
Signed-off-by: discord9 <discord9@163.com>
Signed-off-by: discord9 <discord9@163.com>
Signed-off-by: discord9 <discord9@163.com>
Signed-off-by: discord9 <discord9@163.com>
Signed-off-by: discord9 <discord9@163.com>
Signed-off-by: discord9 <discord9@163.com>
Signed-off-by: discord9 <discord9@163.com>
Signed-off-by: discord9 <discord9@163.com>
Replace default-allow cast unwrapping with an explicit allowlist in
is_supported_comparison_unwrap_cast. Only verified-safe type pairs are
allowed; the literal must also round-trip exactly.

Allowed families:
- Timestamp widening (same timezone, same-or-finer precision)
- Integer widening (same-sign, unsigned->larger signed, identity)
- Binary widening (FixedSizeBinary->Binary, identity)
- Integer->String (Eq/NotEq/IsDistinctFrom only; string ordering
  differs from integer ordering for inequalities)
- Dictionary/String family (any direction, round-trip catches
  truncation)
- Decimal widening (int-digits not reduced, scale not reduced)
- Integer->Decimal (when p-s >= integer digit count)
- Date32<->Int32, Date64<->Int64 (same bit width)

Explicitly blocked:
- String->Integer (multiple strings map to same int)
- Integer narrowing
- Signed->unsigned
- Timestamp cross-timezone
- Decimal narrowing
- Decimal->Integer (truncates fractional part)

try_cast_string_literal renamed to try_cast_string_like_literal
and uses ScalarValue::cast_to for int<->string consistency.
is_integer_string_safe takes op for inequality gate.

Tests updated in casts.rs, optimizer, physical simplifier, and SLT.
Signed-off-by: discord9 <discord9@163.com>
Signed-off-by: discord9 <discord9@163.com>
Signed-off-by: discord9 <discord9@163.com>
Signed-off-by: discord9 <discord9@163.com>
Signed-off-by: discord9 <discord9@163.com>
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.

1 participant