From 37a8e6024716e8dbb1cd1c0610c3a022b887c355 Mon Sep 17 00:00:00 2001 From: Yucheng Du Date: Tue, 1 Dec 2026 02:32:31 -0800 Subject: [PATCH] GH-55877: [C++] Fix Parquet pruning for mixed-type is_in filters --- cpp/src/arrow/compute/expression.cc | 14 +++++++++++++- cpp/src/arrow/compute/expression_test.cc | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/cpp/src/arrow/compute/expression.cc b/cpp/src/arrow/compute/expression.cc index cd952055666c..00bcc5364c7e 100644 --- a/cpp/src/arrow/compute/expression.cc +++ b/cpp/src/arrow/compute/expression.cc @@ -1307,7 +1307,19 @@ struct Inequality { std::string func_name = Comparison::GetName(guarantee.cmp); DCHECK_NE(func_name, "na"); - std::vector args{options->value_set, guarantee.bound}; + // Set lookup first casts the value set to the input type. Comparing the + // original values to the bound can discard matches (e.g. double to float). + const auto* input_type = is_in_call->arguments[0].type(); + Datum comparable = options->value_set; + if (!comparable.type()->Equals(*input_type)) { + auto casted = Cast(comparable, input_type); + if (!casted.ok()) { + // Set lookup can cast the input to the set type instead. + return std::nullopt; + } + comparable = *std::move(casted); + } + std::vector args{std::move(comparable), guarantee.bound}; ARROW_ASSIGN_OR_RAISE(Datum filter_mask, CallFunction(func_name, args)); FilterOptions filter_options(null_selection); ARROW_ASSIGN_OR_RAISE(Datum simplified_value_set, diff --git a/cpp/src/arrow/compute/expression_test.cc b/cpp/src/arrow/compute/expression_test.cc index e123411a3c7a..6d0efded936a 100644 --- a/cpp/src/arrow/compute/expression_test.cc +++ b/cpp/src/arrow/compute/expression_test.cc @@ -2230,6 +2230,28 @@ TEST(Expression, SimplifyThenExecute) { AssertDatumsEqual(evaluated, simplified_evaluated, /*verbose=*/true); } +TEST(Expression, SimplifyIsInWithDifferentValueSetType) { + auto is_in = [](std::shared_ptr set_type, std::string values) { + return call("is_in", {field_ref("f32")}, + SetLookupOptions{ArrayFromJSON(set_type, values)}); + }; + auto lower_bound = greater_equal(field_ref("f32"), literal(0.1f)); + + // Set lookup rounds the double and parses the string to the float column type. + Simplify{is_in(float64(), "[0.0, 0.1]")} + .WithGuarantee(lower_bound) + .Expect(is_in(float64(), "[0.1]")); + Simplify{is_in(utf8(), R"(["0.0", "0.1"])")} + .WithGuarantee(lower_bound) + .Expect(is_in(utf8(), R"(["0.1"])")); + + // This integer cannot be safely cast to float32. Set lookup casts the input + // to the set type instead. + Simplify{is_in(int64(), "[16777217]")} + .WithGuarantee(greater_equal(field_ref("f32"), literal(16777216.0f))) + .ExpectUnchanged(); +} + TEST(Expression, SimplifyIsInThenExecute) { auto input = RecordBatchFromJSON(kBoringSchema, R"([ {"i64": 2, "i32": 5},