felipecrv commented on code in PR #43256:
URL: https://github.com/apache/arrow/pull/43256#discussion_r1693569517
##########
cpp/src/arrow/compute/expression.cc:
##########
@@ -1242,8 +1271,74 @@ struct Inequality {
/*insert_implicit_casts=*/false, &exec_context);
}
+ /// Simplify an `is_in` value set against an inequality guarantee.
+ ///
+ /// Simplifying an `is_in` predicate involves filtering out any values from
+ /// the value set that cannot possibly be found given the guarantee. For
+ /// example, if we have the predicate 'x is_in [1, 2, 3, 4]' and the
guarantee
+ /// 'x > 2', then the simplified predicate 'x is_in [3, 4]' is equivalent.
+ /// This can be done efficiently if the value set is sorted and unique by
+ /// binary searching the inequality gound and slicing the value set
+ /// accordingly.
+ ///
+ /// \pre `guarantee` is non-nullable
+ /// \pre `value_set` is non-empty
+ /// \return a simplified value set, or a bool if the simplification results
in
+ /// a boolean literal predicate.
+ static Result<std::variant<std::shared_ptr<Array>, bool>>
SimplifyIsInValueSet(
+ const Inequality& guarantee, std::shared_ptr<Array> value_set) {
+ DCHECK_GT(value_set->length(), 0);
+
+ auto compare = [&guarantee, &value_set](size_t i) ->
Result<Comparison::type> {
+ ARROW_ASSIGN_OR_RAISE(std::shared_ptr<Scalar> scalar,
value_set->GetScalar(i));
Review Comment:
This makes this function very slow. You should probably template
`SimplifyIsInValueSet` by the `ArrowType` and use `ArrowType::c_type`
comparisons here.
And at the call to `SimplifyIsInValueSet` you will be switching on the type
of the value and calling this with the appropriate type.
--
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]