Skip to content

Commit 3a195e8

Browse files
refactor: remove redundant short IN list type check
Query planning converts the column and IN-list values to the same type before this rule runs. Remove the extra type check while keeping the requirement that list values are constants. Update the test to convert Int32 list values to the Int64 column type before checking both IN and NOT IN.
1 parent 084ce26 commit 3a195e8

2 files changed

Lines changed: 7 additions & 9 deletions

File tree

‎datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5172,11 +5172,12 @@ mod tests {
51725172
}
51735173

51745174
#[test]
5175-
fn simplify_short_inlist_mismatched_literals() {
5176-
// c3 is Int64; these Int32 literals have not been coerced.
5177-
let expr = in_list(col("c3"), vec![lit(1_i32), lit(2_i32)], false);
5178-
let expected = col("c3").eq(lit(1_i32)).or(col("c3").eq(lit(2_i32)));
5179-
assert_eq!(simplify(expr), expected);
5175+
fn simplify_short_inlist_coerced_literals() {
5176+
for negated in [false, true] {
5177+
let expr = in_list(col("c3"), vec![lit(1_i32), lit(2_i32)], negated);
5178+
let expected = in_list(col("c3"), vec![lit(1_i64), lit(2_i64)], negated);
5179+
assert_eq!(simplify(coerce(expr)), expected);
5180+
}
51805181
}
51815182

51825183
#[test]

‎datafusion/optimizer/src/simplify_expressions/inlist_simplifier.rs‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ impl<'a> ShortenInListSimplifier<'a> {
4848
| DataType::Float32
4949
| DataType::Float64
5050
| DataType::FixedSizeBinary(1 | 2 | 4 | 8 | 16)
51-
) && list.iter().all(|expr| {
52-
expr.as_literal()
53-
.is_some_and(|value| value.data_type() == data_type)
54-
})
51+
) && list.iter().all(|expr| expr.as_literal().is_some())
5552
}
5653
}
5754

0 commit comments

Comments
 (0)