edponce commented on a change in pull request #11882:
URL: https://github.com/apache/arrow/pull/11882#discussion_r784211897
##########
File path: cpp/src/arrow/compute/kernels/scalar_compare_test.cc
##########
@@ -1865,5 +1861,636 @@ 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, Between(val, lhs, rhs, options, nullptr));
+ AssertArraysEqual(*expected.make_array(), *result.make_array(),
+ /*verbose=*/true);
+}
+
+template <typename ArrowType>
+void ValidateBetween(BetweenOptions options, const Datum& val, const Datum&
lhs,
+ const Datum& rhs) {
+ CompareOperator lhs_val;
+ CompareOperator val_rhs;
+ BetweenOptions::Inclusive include_endpoints = options.inclusive;
+
+ if (include_endpoints == BetweenOptions::Inclusive::NEITHER) {
+ lhs_val = LESS;
+ val_rhs = LESS;
+ } else if (include_endpoints == BetweenOptions::Inclusive::LEFT) {
+ lhs_val = LESS_EQUAL;
+ val_rhs = LESS;
+ } else if (include_endpoints == BetweenOptions::Inclusive::RIGHT) {
+ lhs_val = LESS;
+ val_rhs = LESS_EQUAL;
+ } else {
+ lhs_val = LESS_EQUAL;
+ val_rhs = LESS_EQUAL;
+ }
+
+ ASSERT_OK_AND_ASSIGN(Datum resultl,
+ CallFunction(CompareOperatorToFunctionName(lhs_val),
{lhs, val}));
+ ASSERT_OK_AND_ASSIGN(Datum resultr,
+ CallFunction(CompareOperatorToFunctionName(val_rhs),
{val, rhs}));
+ ASSERT_OK_AND_ASSIGN(Datum expected, CallFunction("and", {resultl,
resultr}));
+
+ ValidateBetween<ArrowType>(options, val, lhs, rhs, expected);
+}
+
+template <typename ArrowType>
+class TestNumericBetweenKernel : public ::testing::Test {};
+
+TYPED_TEST_SUITE(TestNumericBetweenKernel, NumericArrowTypes);
+TYPED_TEST(TestNumericBetweenKernel, SimpleBetweenArrayScalarScalar) {
+ using ScalarType = typename TypeTraits<TypeParam>::ScalarType;
+ using CType = typename TypeTraits<TypeParam>::CType;
+
+ Datum zero(std::make_shared<ScalarType>(CType(0)));
+ Datum four(std::make_shared<ScalarType>(CType(4)));
+ Datum null(std::make_shared<ScalarType>());
+ BetweenOptions InclusiveBoth(BetweenOptions::Inclusive::BOTH);
+ ValidateBetween<TypeParam>(
+ InclusiveBoth, ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(),
"[]"), zero,
+ four, ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), "[]"));
+ ValidateBetween<TypeParam>(
+ InclusiveBoth, ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(),
"[null]"),
+ zero, four, ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
"[null]"));
+ ValidateBetween<TypeParam>(
+ InclusiveBoth,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,0,1,1,2,2]"),
zero, four,
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
"[1,1,1,1,1,1]"));
+ ValidateBetween<TypeParam>(
+ InclusiveBoth,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,1,2,3,4,5]"),
zero, four,
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
"[1,1,1,1,1,0]"));
+ ValidateBetween<TypeParam>(
+ InclusiveBoth,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[5,4,3,2,1,0]"),
zero, four,
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
"[0,1,1,1,1,1]"));
+ ValidateBetween<TypeParam>(
+ InclusiveBoth,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[null,0,1,1]"),
zero, four,
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
"[null,1,1,1]"));
+ ValidateBetween<TypeParam>(
+ InclusiveBoth,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[5,4,3,2,1,0]"),
null, four,
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ "[null,null,null,null,null,null]"));
+ ValidateBetween<TypeParam>(
+ InclusiveBoth,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[5,4,3,2,1,0]"),
zero, null,
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ "[null,null,null,null,null,null]"));
+ BetweenOptions InclusiveLeft(BetweenOptions::Inclusive::LEFT);
+ ValidateBetween<TypeParam>(
+ InclusiveLeft, ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(),
"[]"), zero,
+ four, ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), "[]"));
+ ValidateBetween<TypeParam>(
+ InclusiveLeft, ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(),
"[null]"),
+ zero, four, ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
"[null]"));
+ ValidateBetween<TypeParam>(
+ InclusiveLeft,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,0,1,1,2,2]"),
zero, four,
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
"[1,1,1,1,1,1]"));
+ ValidateBetween<TypeParam>(
+ InclusiveLeft,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,1,2,3,4,5]"),
zero, four,
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
"[1,1,1,1,0,0]"));
+ ValidateBetween<TypeParam>(
+ InclusiveLeft,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[5,4,3,2,1,0]"),
zero, four,
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
"[0,0,1,1,1,1]"));
+ ValidateBetween<TypeParam>(
+ InclusiveLeft,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[null,0,1,1]"),
zero, four,
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
"[null,1,1,1]"));
+ ValidateBetween<TypeParam>(
+ InclusiveLeft,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[5,4,3,2,1,0]"),
null, four,
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ "[null,null,null,null,null,null]"));
+ ValidateBetween<TypeParam>(
+ InclusiveLeft,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[5,4,3,2,1,0]"),
zero, null,
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ "[null,null,null,null,null,null]"));
+ BetweenOptions InclusiveRight(BetweenOptions::Inclusive::RIGHT);
+ ValidateBetween<TypeParam>(
+ InclusiveRight, ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(),
"[]"), zero,
+ four, ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), "[]"));
+ ValidateBetween<TypeParam>(
+ InclusiveRight, ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(),
"[null]"),
+ zero, four, ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
"[null]"));
+ ValidateBetween<TypeParam>(
+ InclusiveRight,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,0,1,1,2,2]"),
zero, four,
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
"[0,0,1,1,1,1]"));
+ ValidateBetween<TypeParam>(
+ InclusiveRight,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,1,2,3,4,5]"),
zero, four,
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
"[0,1,1,1,1,0]"));
+ ValidateBetween<TypeParam>(
+ InclusiveRight,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[5,4,3,2,1,0]"),
zero, four,
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
"[0,1,1,1,1,0]"));
+ ValidateBetween<TypeParam>(
+ InclusiveRight,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[null,0,1,1]"),
zero, four,
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
"[null,0,1,1]"));
+ ValidateBetween<TypeParam>(
+ InclusiveRight,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[5,4,3,2,1,0]"),
null, four,
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ "[null,null,null,null,null,null]"));
+ ValidateBetween<TypeParam>(
+ InclusiveRight,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[5,4,3,2,1,0]"),
zero, null,
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ "[null,null,null,null,null,null]"));
+ BetweenOptions InclusiveNeither(BetweenOptions::Inclusive::NEITHER);
+ ValidateBetween<TypeParam>(
+ InclusiveNeither, ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(),
"[]"),
+ zero, four, ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
"[]"));
+ ValidateBetween<TypeParam>(
+ InclusiveNeither, ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(),
"[null]"),
+ zero, four, ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
"[null]"));
+ ValidateBetween<TypeParam>(
+ InclusiveNeither,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,0,1,1,2,2]"),
zero, four,
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
"[0,0,1,1,1,1]"));
+ ValidateBetween<TypeParam>(
+ InclusiveNeither,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,1,2,3,4,5]"),
zero, four,
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
"[0,1,1,1,0,0]"));
+ ValidateBetween<TypeParam>(
+ InclusiveNeither,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[5,4,3,2,1,0]"),
zero, four,
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
"[0,0,1,1,1,0]"));
+ ValidateBetween<TypeParam>(
+ InclusiveNeither,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[null,0,1,1]"),
zero, four,
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
"[null,0,1,1]"));
+ ValidateBetween<TypeParam>(
+ InclusiveNeither,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[5,4,3,2,1,0]"),
null, four,
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ "[null,null,null,null,null,null]"));
+ ValidateBetween<TypeParam>(
+ InclusiveNeither,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[5,4,3,2,1,0]"),
zero, null,
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ "[null,null,null,null,null,null]"));
+}
+
+TYPED_TEST(TestNumericBetweenKernel, SimpleBetweenScalarArrayArray) {
+ using ScalarType = typename TypeTraits<TypeParam>::ScalarType;
+ using CType = typename TypeTraits<TypeParam>::CType;
+
+ Datum one(std::make_shared<ScalarType>(CType(1)));
+
+ BetweenOptions InclusiveBoth(BetweenOptions::Inclusive::BOTH);
+ ValidateBetween<TypeParam>(
+ InclusiveBoth, one,
ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), "[]"));
+ ValidateBetween<TypeParam>(
+ InclusiveBoth, one,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[null]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[null]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), "[null]"));
+ ValidateBetween<TypeParam>(
+ InclusiveBoth, one,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,0,1,3,3]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[10,10,2,5,5]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ "[true,true,true,false,false]"));
+ ValidateBetween<TypeParam>(
+ InclusiveBoth, one,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(),
"[0,0,1,null,3,3]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,10,2,2,5,5]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ "[false,true,true,null,false,false]"));
+ BetweenOptions InclusiveLeft(BetweenOptions::Inclusive::LEFT);
+ ValidateBetween<TypeParam>(
+ InclusiveLeft, one,
ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), "[]"));
+ ValidateBetween<TypeParam>(
+ InclusiveLeft, one,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[null]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[null]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), "[null]"));
+ ValidateBetween<TypeParam>(
+ InclusiveLeft, one,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,0,1,3,3]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[10,10,2,5,5]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ "[true,true,true,false,false]"));
+ ValidateBetween<TypeParam>(
+ InclusiveLeft, one,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(),
"[0,0,1,null,3,3]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,10,2,2,5,5]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ "[false,true,true,null,false,false]"));
+ BetweenOptions InclusiveRight(BetweenOptions::Inclusive::RIGHT);
+ ValidateBetween<TypeParam>(
+ InclusiveRight, one,
ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), "[]"));
+ ValidateBetween<TypeParam>(
+ InclusiveRight, one,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[null]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[null]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), "[null]"));
+ ValidateBetween<TypeParam>(
+ InclusiveRight, one,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,0,1,3,3]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[10,10,2,5,5]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ "[true,true,false,false,false]"));
+ ValidateBetween<TypeParam>(
+ InclusiveRight, one,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(),
"[0,0,1,null,3,3]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,10,2,2,5,5]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ "[false,true,false,null,false,false]"));
+ BetweenOptions InclusiveNeither(BetweenOptions::Inclusive::NEITHER);
+ ValidateBetween<TypeParam>(
+ InclusiveNeither, one,
ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), "[]"));
+ ValidateBetween<TypeParam>(
+ InclusiveNeither, one,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[null]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[null]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), "[null]"));
+ ValidateBetween<TypeParam>(
+ InclusiveNeither, one,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,0,1,3,3]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[10,10,2,5,5]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ "[true,true,false,false,false]"));
+ ValidateBetween<TypeParam>(
+ InclusiveNeither, one,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(),
"[0,0,1,null,3,3]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,10,2,2,5,5]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ "[false,true,false,null,false,false]"));
+}
+
+TYPED_TEST(TestNumericBetweenKernel, SimpleBetweenArrayArrayArray) {
+ BetweenOptions InclusiveBoth(BetweenOptions::Inclusive::BOTH);
+ ValidateBetween<TypeParam>(
+ InclusiveBoth, ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(),
"[]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), "[]"));
+ ValidateBetween<TypeParam>(
+ InclusiveBoth, ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(),
"[null]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[null]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[null]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), "[null]"));
+ ValidateBetween<TypeParam>(
+ InclusiveBoth,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[1,1,2,2,2]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,0,1,3,3]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[10,10,2,5,5]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ "[true,true,true,false,false]"));
+ ValidateBetween<TypeParam>(
+ InclusiveBoth,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,1,2,2,2,2]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(),
"[0,0,1,null,3,3]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,10,2,2,5,5]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ "[true,true,true,null,false,false]"));
+ BetweenOptions InclusiveLeft(BetweenOptions::Inclusive::LEFT);
+ ValidateBetween<TypeParam>(
+ InclusiveLeft, ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(),
"[]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), "[]"));
+ ValidateBetween<TypeParam>(
+ InclusiveLeft, ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(),
"[null]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[null]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[null]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), "[null]"));
+ ValidateBetween<TypeParam>(
+ InclusiveLeft,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[1,1,2,2,2]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,0,1,3,3]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[10,10,2,5,5]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ "[true,true,false,false,false]"));
+ ValidateBetween<TypeParam>(
+ InclusiveLeft,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,1,2,2,2,2]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(),
"[0,0,1,null,3,3]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,10,2,2,5,5]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ "[false,true,false,null,false,false]"));
+ BetweenOptions InclusiveRight(BetweenOptions::Inclusive::RIGHT);
+ ValidateBetween<TypeParam>(
+ InclusiveRight, ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(),
"[]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), "[]"));
+ ValidateBetween<TypeParam>(
+ InclusiveRight, ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(),
"[null]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[null]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[null]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), "[null]"));
+ ValidateBetween<TypeParam>(
+ InclusiveRight,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[1,1,2,2,2]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,0,1,3,3]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[10,10,2,5,5]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ "[true,true,true,false,false]"));
+ ValidateBetween<TypeParam>(
+ InclusiveRight,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,1,2,2,2,2]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(),
"[0,0,1,null,3,3]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,10,2,2,5,5]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ "[false,true,true,null,false,false]"));
+ BetweenOptions InclusiveNeither(BetweenOptions::Inclusive::NEITHER);
+ ValidateBetween<TypeParam>(
+ InclusiveNeither, ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(),
"[]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), "[]"));
+ ValidateBetween<TypeParam>(
+ InclusiveNeither, ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(),
"[null]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[null]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[null]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), "[null]"));
+ ValidateBetween<TypeParam>(
+ InclusiveNeither,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[1,1,2,2,2]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,0,1,3,3]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[10,10,2,5,5]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ "[true,true,false,false,false]"));
+ ValidateBetween<TypeParam>(
+ InclusiveNeither,
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,1,2,2,2,2]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(),
"[0,0,1,null,3,3]"),
+ ArrayFromJSON(TypeTraits<TypeParam>::type_singleton(), "[0,10,2,2,5,5]"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ "[false,true,false,null,false,false]"));
+}
+
+template <typename Type>
+struct BetweenRandomNumeric {
+ static void Test(const std::shared_ptr<DataType>& type) {
+ using ScalarType = typename TypeTraits<Type>::ScalarType;
+ using CType = typename TypeTraits<Type>::CType;
+ auto rand = random::RandomArrayGenerator(0x5416447);
+ const int64_t length = 1000;
+ for (auto null_probability : {0.0, 0.01, 0.1, 0.25, 0.5, 1.0}) {
+ for (auto inclusive :
+ {BetweenOptions::Inclusive::BOTH, BetweenOptions::Inclusive::LEFT,
+ BetweenOptions::Inclusive::RIGHT,
BetweenOptions::Inclusive::NEITHER}) {
+ auto data1 =
+ rand.Numeric<typename Type::PhysicalType>(length, 0, 100,
null_probability);
+ auto data2 =
+ rand.Numeric<typename Type::PhysicalType>(length, 0, 100,
null_probability);
+ auto data3 =
+ rand.Numeric<typename Type::PhysicalType>(length, 0, 100,
null_probability);
+
+ // Create view of data as the type (e.g. timestamp)
+ auto array1 = Datum(*data1->View(type));
+ auto array2 = Datum(*data2->View(type));
+ auto array3 = Datum(*data3->View(type));
+ auto scalar1 = Datum(std::make_shared<ScalarType>(CType(10), type));
+ auto scalar2 = Datum(std::make_shared<ScalarType>(CType(30), type));
+ auto scalar3 = Datum(std::make_shared<ScalarType>(CType(50), type));
+ auto options = BetweenOptions(inclusive);
+ ValidateBetween<Type>(options, array1, scalar2, scalar3);
+ ValidateBetween<Type>(options, array1, array2, scalar3);
+ ValidateBetween<Type>(options, array1, array2, array3);
+ ValidateBetween<Type>(options, array1, scalar2, scalar3);
+ ValidateBetween<Type>(options, scalar1, array2, array3);
+ ValidateBetween<Type>(options, scalar1, array2, scalar3);
+ ValidateBetween<Type>(options, scalar1, scalar2, array3);
+ ValidateBetween<Type>(options, array1, scalar2, array3);
+ }
+ }
+ }
+};
+
+TEST(TestNumericBetweenKernel, BetweenPrimitiveRandomTests) {
+ TestRandomPrimitiveCTypes<BetweenRandomNumeric>();
+}
+
+class TestStringBetweenKernel : public ::testing::Test {};
+
+TEST(TestStringBetweenKernel, RandomBetween) {
+ using ScalarType = typename TypeTraits<StringType>::ScalarType;
+
+ auto rand = random::RandomArrayGenerator(0x5416447);
+ for (size_t i = 3; i < 10; i++) {
+ for (auto null_probability : {0.0, 0.01, 0.1, 0.25, 0.5, 1.0}) {
+ for (auto inclusive :
+ {BetweenOptions::Inclusive::BOTH, BetweenOptions::Inclusive::LEFT,
+ BetweenOptions::Inclusive::RIGHT,
BetweenOptions::Inclusive::NEITHER}) {
+ const int64_t length = static_cast<int64_t>(1ULL << i);
+ auto array1 = Datum(rand.String(length, 0, 16, null_probability));
+ auto array2 = Datum(rand.String(length, 0, 16, null_probability));
+ auto array3 = Datum(rand.String(length, 0, 16, null_probability));
+ auto scalar1 = Datum(std::make_shared<ScalarType>("fupi"));
+ auto scalar2 = Datum(std::make_shared<ScalarType>("tupu"));
+ auto scalar3 = Datum(std::make_shared<ScalarType>("zito"));
+ auto options = BetweenOptions(inclusive);
+ ValidateBetween<StringType>(options, array1, scalar2, scalar3);
+ ValidateBetween<StringType>(options, scalar1, array2, scalar3);
+ ValidateBetween<StringType>(options, scalar1, scalar2, array3);
+ ValidateBetween<StringType>(options, scalar1, array2, array3);
+ ValidateBetween<StringType>(options, array1, scalar2, array3);
+ ValidateBetween<StringType>(options, array1, array2, scalar3);
+ ValidateBetween<StringType>(options, array1, array2, array3);
+ }
+ }
+ }
+}
+
+TEST(TestStringBetweenKernel, StringArrayScalarScalarTest) {
+ using ScalarType = typename TypeTraits<StringType>::ScalarType;
+ auto l = Datum(std::make_shared<ScalarType>("abc"));
+ auto r = Datum(std::make_shared<ScalarType>("zzz"));
+ BetweenOptions InclusiveOption(BetweenOptions::Inclusive::BOTH);
+ ValidateBetween<StringType>(
+ InclusiveOption, ArrayFromJSON(TypeTraits<StringType>::type_singleton(),
"[]"), l,
+ r, ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), "[]"));
+ ValidateBetween<StringType>(
+ InclusiveOption, ArrayFromJSON(TypeTraits<StringType>::type_singleton(),
"[null]"),
+ l, r, ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
"[null]"));
+ ValidateBetween<StringType>(InclusiveOption,
+
ArrayFromJSON(TypeTraits<StringType>::type_singleton(),
+ R"(["aaa", "aaaa", "ccc", "z"])"),
+ l, r,
+
ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ R"([false, false, true, true])"));
+ ValidateBetween<StringType>(InclusiveOption,
+
ArrayFromJSON(TypeTraits<StringType>::type_singleton(),
+ R"(["a", "aaaa", "c", "z"])"),
+ l, r,
+
ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ R"([false, false, true, true])"));
+ ValidateBetween<StringType>(InclusiveOption,
+
ArrayFromJSON(TypeTraits<StringType>::type_singleton(),
+ R"(["a", "aaaa", "fff", "zzzz"])"),
+ l, r,
+
ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ R"([false, false, true, false])"));
+ ValidateBetween<StringType>(InclusiveOption,
+
ArrayFromJSON(TypeTraits<StringType>::type_singleton(),
+ R"(["abc", "baa", "fff", "zzz"])"),
+ l, r,
+
ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ R"([true, true, true, true])"));
+ ValidateBetween<StringType>(InclusiveOption,
+
ArrayFromJSON(TypeTraits<StringType>::type_singleton(),
+ R"(["abd", null, null, "zzx"])"),
+ l, r,
+
ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(),
+ R"([true, null, null, true])"));
+}
+
+TEST(TestStringBetweenKernel, StringArrayArrayArrayTest) {
+ BetweenOptions InclusiveOption(BetweenOptions::Inclusive::BOTH);
+ ValidateBetween<StringType>(
+ InclusiveOption,
+ ArrayFromJSON(TypeTraits<StringType>::type_singleton(),
+ R"(["david","hello","world"])"),
+ ArrayFromJSON(TypeTraits<StringType>::type_singleton(),
R"(["adam","hi","whirl"])"),
+ ArrayFromJSON(TypeTraits<StringType>::type_singleton(),
+ R"(["robert","goeiemoreen","whirlwind"])"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), "[true, false,
false]"));
+ ValidateBetween<StringType>(
+ InclusiveOption,
+ ArrayFromJSON(TypeTraits<StringType>::type_singleton(),
R"(["x","a","f"])"),
+ ArrayFromJSON(TypeTraits<StringType>::type_singleton(),
R"(["w","a","e"])"),
+ ArrayFromJSON(TypeTraits<StringType>::type_singleton(),
R"(["z","a","g"])"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), "[true, true,
true]"));
+ ValidateBetween<StringType>(
+ InclusiveOption,
+ ArrayFromJSON(TypeTraits<StringType>::type_singleton(),
+ R"(["block","bit","binary"])"),
+ ArrayFromJSON(TypeTraits<StringType>::type_singleton(),
+ R"(["bit","nibble","ternary"])"),
+ ArrayFromJSON(TypeTraits<StringType>::type_singleton(),
R"(["word","d","xyz"])"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), "[true, false,
false]"));
+ ValidateBetween<StringType>(
+ InclusiveOption,
+ ArrayFromJSON(TypeTraits<StringType>::type_singleton(),
+ R"(["よしもと","の","ち"])"),
+ ArrayFromJSON(TypeTraits<StringType>::type_singleton(),
R"(["は","へ","あ"])"),
+ ArrayFromJSON(TypeTraits<StringType>::type_singleton(),
R"(["な","を","ち"])"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), "[false, false,
true]"));
+ ValidateBetween<StringType>(
+ InclusiveOption,
+ ArrayFromJSON(TypeTraits<StringType>::type_singleton(),
R"(["A","ア","王"])"),
+ ArrayFromJSON(TypeTraits<StringType>::type_singleton(),
R"(["た","あ","歩"])"),
+ ArrayFromJSON(TypeTraits<StringType>::type_singleton(),
R"(["李","田",null])"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), "[false, true,
null]"));
+ ValidateBetween<StringType>(
+ InclusiveOption,
+ ArrayFromJSON(TypeTraits<StringType>::type_singleton(),
R"(["Б",null,"Я"])"),
+ ArrayFromJSON(TypeTraits<StringType>::type_singleton(),
R"(["А","Ж","Щ"])"),
+ ArrayFromJSON(TypeTraits<StringType>::type_singleton(),
R"(["Д","Л","Ф"])"),
+ ArrayFromJSON(TypeTraits<BooleanType>::type_singleton(), "[true, null,
false]"));
+}
+
+TEST(TestTimestampsBetweenKernel, TimestampsArrayArrayArrayTest) {
+ const std::string arr_json = R"(["1970-01-01","2000-02-02","1900-02-28"])";
+ const std::string lhs_json = R"(["1970-01-01","2000-02-01","1900-02-28"])";
+ const std::string rhs_json = R"(["1970-01-02","2000-02-02","1900-02-28"])";
+ // Between Options
+ BetweenOptions both(BetweenOptions::Inclusive::BOTH);
+ BetweenOptions left(BetweenOptions::Inclusive::LEFT);
+ BetweenOptions right(BetweenOptions::Inclusive::RIGHT);
+ BetweenOptions neither(BetweenOptions::Inclusive::NEITHER);
+ // Same units should be fine
+ auto arr = ArrayFromJSON(timestamp(TimeUnit::SECOND), arr_json);
+ auto lhs = ArrayFromJSON(timestamp(TimeUnit::SECOND), lhs_json);
+ auto rhs = ArrayFromJSON(timestamp(TimeUnit::SECOND), rhs_json);
+ // BOTH
+ ValidateBetween<TimestampType>(both, arr, lhs, rhs);
+ // LEFT
+ ValidateBetween<TimestampType>(left, arr, lhs, rhs);
+ // RIGHT
+ ValidateBetween<TimestampType>(right, arr, lhs, rhs);
+ // NEITHER
+ ValidateBetween<TimestampType>(neither, arr, lhs, rhs);
Review comment:
Nit: No need for these comments as the code already is clear enough.
--
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]