bkmgit commented on a change in pull request #11882: URL: https://github.com/apache/arrow/pull/11882#discussion_r772827256
########## File path: cpp/src/arrow/compute/kernels/scalar_compare_test.cc ########## @@ -1850,5 +1846,439 @@ TEST(TestMaxElementWiseMinElementWise, CommonTemporal) { ResultWith(ScalarFromJSON(date64(), "86400000"))); } +template <typename ArrowType> +static void ValidateBetween(BetweenOptions options, const Datum& val, const Datum& lhs, + const Datum& rhs, const Datum& expected) { + ASSERT_OK_AND_ASSIGN( + Datum result, + CallFunction(BetweenOperatorToFunctionName(options.op), {val, lhs, rhs})); + AssertArraysEqual(*expected.make_array(), *result.make_array(), + /*verbose=*/true); +} + +template <typename ArrowType> +static void ValidateBetween(BetweenOptions options, const Datum& val, const Datum& lhs, + const Datum& rhs, const char* expected_str) { + auto expected = ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), expected_str); + ValidateBetween<ArrowType>(options, val, lhs, rhs, expected); +} + +template <typename ArrowType> +static void ValidateBetween(BetweenOptions options, const Datum& val, const Datum& lhs, + const char* rhs_str, const Datum& expected) { + auto rhs = ArrayFromJSON(TypeTraits<ArrowType>::type_singleton(), rhs_str); + ValidateBetween<ArrowType>(options, val, lhs, rhs, expected); +} + +template <typename ArrowType> +static void ValidateBetween(BetweenOptions options, const Datum& val, const char* lhs_str, + const Datum& rhs, const Datum& expected) { + auto lhs = ArrayFromJSON(TypeTraits<ArrowType>::type_singleton(), lhs_str); + ValidateBetween<ArrowType>(options, val, lhs, rhs, expected); +} + +template <typename ArrowType> +static void ValidateBetween(BetweenOptions options, const char* val_str, const Datum& lhs, + const Datum& rhs, const Datum& expected) { + auto val = ArrayFromJSON(TypeTraits<ArrowType>::type_singleton(), val_str); + ValidateBetween<ArrowType>(options, val, lhs, rhs, expected); +} + +template <typename ArrowType> +static void ValidateBetween(BetweenOptions options, const Datum& val, const Datum& lhs, + const char* rhs_str, const char* expected_str) { + auto rhs = ArrayFromJSON(TypeTraits<ArrowType>::type_singleton(), rhs_str); + auto expected = ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), expected_str); + ValidateBetween<ArrowType>(options, val, lhs, rhs, expected); +} + +template <typename ArrowType> +static void ValidateBetween(BetweenOptions options, const Datum& val, const char* lhs_str, + const Datum& rhs, const char* expected_str) { + auto lhs = ArrayFromJSON(TypeTraits<ArrowType>::type_singleton(), lhs_str); + auto expected = ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), expected_str); + ValidateBetween<ArrowType>(options, val, lhs, rhs, expected); +} + +template <typename ArrowType> +static void ValidateBetween(BetweenOptions options, const Datum& val, const char* lhs_str, + const char* rhs_str, const Datum& expected) { + auto lhs = ArrayFromJSON(TypeTraits<ArrowType>::type_singleton(), lhs_str); + auto rhs = ArrayFromJSON(TypeTraits<ArrowType>::type_singleton(), rhs_str); + ValidateBetween<ArrowType>(options, val, lhs, rhs, expected); +} + +template <typename ArrowType> +static void ValidateBetween(BetweenOptions options, const char* val_str, const Datum& lhs, + const Datum& rhs, const char* expected_str) { + auto val = ArrayFromJSON(TypeTraits<ArrowType>::type_singleton(), val_str); + auto expected = ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), expected_str); + ValidateBetween<ArrowType>(options, val, lhs, rhs, expected); +} + +template <typename ArrowType> +static void ValidateBetween(BetweenOptions options, const char* val_str, + const char* lhs_str, const Datum& rhs, + const Datum& expected) { + auto val = ArrayFromJSON(TypeTraits<ArrowType>::type_singleton(), val_str); + auto lhs = ArrayFromJSON(TypeTraits<ArrowType>::type_singleton(), lhs_str); + ValidateBetween<ArrowType>(options, val, lhs, rhs, expected); +} + +template <typename ArrowType> +static void ValidateBetween(BetweenOptions options, const char* val_str, const Datum& lhs, + const char* rhs_str, const Datum& expected) { + auto val = ArrayFromJSON(TypeTraits<ArrowType>::type_singleton(), val_str); + auto rhs = ArrayFromJSON(TypeTraits<ArrowType>::type_singleton(), rhs_str); + ValidateBetween<ArrowType>(options, val, lhs, rhs, expected); +} + +template <typename ArrowType> +static void ValidateBetween(BetweenOptions options, const Datum& val, const char* lhs_str, + const char* rhs_str, const char* expected_str) { + auto lhs = ArrayFromJSON(TypeTraits<ArrowType>::type_singleton(), lhs_str); + auto rhs = ArrayFromJSON(TypeTraits<ArrowType>::type_singleton(), rhs_str); + auto expected = ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), expected_str); + ValidateBetween<ArrowType>(options, val, lhs, rhs, expected); +} + +template <typename ArrowType> +static void ValidateBetween(BetweenOptions options, const char* val_str, const Datum& lhs, + const char* rhs_str, const char* expected_str) { + auto val = ArrayFromJSON(TypeTraits<ArrowType>::type_singleton(), val_str); + auto rhs = ArrayFromJSON(TypeTraits<ArrowType>::type_singleton(), rhs_str); + auto expected = ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), expected_str); + ValidateBetween<ArrowType>(options, val, lhs, rhs, expected); +} + +template <typename ArrowType> +static void ValidateBetween(BetweenOptions options, const char* val_str, + const char* lhs_str, const Datum& rhs, + const char* expected_str) { + auto val = ArrayFromJSON(TypeTraits<ArrowType>::type_singleton(), val_str); + auto lhs = ArrayFromJSON(TypeTraits<ArrowType>::type_singleton(), lhs_str); + auto expected = ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), expected_str); + ValidateBetween<ArrowType>(options, val, lhs, rhs, expected); +} + +template <typename ArrowType> +static void ValidateBetween(BetweenOptions options, const char* val_str, + const char* lhs_str, const char* rhs_str, + const Datum& expected) { + auto val = ArrayFromJSON(TypeTraits<ArrowType>::type_singleton(), val_str); + auto lhs = ArrayFromJSON(TypeTraits<ArrowType>::type_singleton(), lhs_str); + auto rhs = ArrayFromJSON(TypeTraits<ArrowType>::type_singleton(), rhs_str); + ValidateBetween<ArrowType>(options, val, lhs, rhs, expected); +} + +template <typename T> +static inline bool SlowBetween(BetweenOperator op, const T& val, const T& lhs, + const T& rhs) { + switch (op) { + case BETWEEN_LESS_EQUAL_LESS_EQUAL: + return ((lhs <= val) && (val <= rhs)); + case BETWEEN_LESS_EQUAL_LESS_THAN: + return ((lhs <= val) && (val < rhs)); + case BETWEEN_LESS_THAN_LESS_EQUAL: + return ((lhs < val) && (val <= rhs)); + case BETWEEN_LESS_THAN_LESS_THAN: + return ((lhs < val) && (val < rhs)); + default: + return false; + } +} + +template <typename ArrayType> +std::vector<bool> NullBitmapFromThreeArrays(const ArrayType& val, const ArrayType& lhs, + const ArrayType& rhs) { + auto value_lambda = [&val](int64_t i) { + return val.null_count() == 0 ? true : val.IsValid(i); + }; + + auto left_lambda = [&lhs](int64_t i) { + return lhs.null_count() == 0 ? true : lhs.IsValid(i); + }; + + auto right_lambda = [&rhs](int64_t i) { + return rhs.null_count() == 0 ? true : rhs.IsValid(i); + }; + + const int64_t length = lhs.length(); + std::vector<bool> null_bitmap(length); + + for (int64_t i = 0; i < length; i++) { + null_bitmap[i] = value_lambda(i) && left_lambda(i) && right_lambda(i); + } + + return null_bitmap; +} + +template <typename ArrowType> +Datum SimpleArrayScalarScalarBetween(BetweenOptions options, const Datum& val, Review comment: My understanding is that would have a performance overhead as this was not the suggested method to use in the original issue https://issues.apache.org/jira/browse/ARROW-9843 -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org