pitrou commented on code in PR #36204:
URL: https://github.com/apache/arrow/pull/36204#discussion_r1244998090
##########
cpp/src/arrow/compute/kernels/scalar_set_lookup_test.cc:
##########
@@ -253,11 +268,11 @@ TEST_F(TestIsInKernel, TimeDuration) {
"[true, false, false, true, true]", /*skip_nulls=*/true);
}
- // Different units, invalid cast
- ASSERT_RAISES(Invalid, IsIn(ArrayFromJSON(duration(TimeUnit::SECOND), "[0,
1, 2]"),
- ArrayFromJSON(duration(TimeUnit::MILLI), "[0,
2]")));
+ // Different units, cast value_set to values
+ CheckIsIn(ArrayFromJSON(duration(TimeUnit::SECOND), "[0, 2]"),
+ ArrayFromJSON(duration(TimeUnit::MILLI), "[1, 2, 2000]"), "[false,
true]");
Review Comment:
More explicitly ensure that the cast actually happens (either 2 or 2000
could be the successful match...)
```suggestion
CheckIsIn(ArrayFromJSON(duration(TimeUnit::SECOND), "[0, 1, 2]"),
ArrayFromJSON(duration(TimeUnit::MILLI), "[1, 2, 2000]"),
"[false, false, true]");
```
##########
cpp/src/arrow/compute/kernels/scalar_set_lookup_test.cc:
##########
@@ -126,25 +126,40 @@ TEST_F(TestIsInKernel, ImplicitlyCastValueSet) {
"true, false, true, false]"));
AssertArraysEqual(*expected, *out.make_array());
- // fails; value_set cannot be cast to int8
- opts = SetLookupOptions{ArrayFromJSON(float32(), "[2.5, 3.1, 5.0]")};
- ASSERT_RAISES(Invalid, CallFunction("is_in", {input}, &opts));
+ // value_set cannot be casted to int8, but int8 is castable to float
+ CheckIsIn(input, ArrayFromJSON(float32(), "[1.0, 2.5, 3.1, 5.0]"),
+ "[false, true, false, false, false, true, false, false, false]");
// Allow implicit casts between binary types...
CheckIsIn(ArrayFromJSON(binary(), R"(["aaa", "bbb", "ccc", null, "bbb"])"),
ArrayFromJSON(fixed_size_binary(3), R"(["aaa", "bbb"])"),
"[true, true, false, false, true]");
+ CheckIsIn(ArrayFromJSON(fixed_size_binary(3), R"(["aaa", "bbb", "ccc", null,
"bbb"])"),
+ ArrayFromJSON(binary(), R"(["aaa", "bbb"])"),
+ "[true, true, false, false, true]");
Review Comment:
Can you perhaps make things more interesting by making entries that are not
3-bytes long?
```suggestion
CheckIsIn(ArrayFromJSON(binary(), R"(["aaa", "bb", "ccc", null, "bbb"])"),
ArrayFromJSON(fixed_size_binary(3), R"(["aaa", "bbb"])"),
"[true, false, false, false, true]");
CheckIsIn(ArrayFromJSON(fixed_size_binary(3), R"(["aaa", "bbb", "ccc",
null, "bbb"])"),
ArrayFromJSON(binary(), R"(["aa", "bbb"])"),
"[false, true, false, false, true]");
```
##########
cpp/src/arrow/compute/kernels/scalar_set_lookup_test.cc:
##########
@@ -253,11 +268,11 @@ TEST_F(TestIsInKernel, TimeDuration) {
"[true, false, false, true, true]", /*skip_nulls=*/true);
}
- // Different units, invalid cast
- ASSERT_RAISES(Invalid, IsIn(ArrayFromJSON(duration(TimeUnit::SECOND), "[0,
1, 2]"),
- ArrayFromJSON(duration(TimeUnit::MILLI), "[0,
2]")));
+ // Different units, cast value_set to values
Review Comment:
Is the comment correct? It will attempt to cast value_set to values, fail
because of truncation, and then cast values to value_set.
##########
cpp/src/arrow/compute/kernels/scalar_set_lookup_test.cc:
##########
@@ -779,11 +794,11 @@ TEST_F(TestIndexInKernel, TimeDuration) {
CheckIndexIn(duration(TimeUnit::SECOND), "[null, null, null, null]",
"[null]",
"[0, 0, 0, 0]");
- // Different units, invalid cast
- ASSERT_RAISES(Invalid, IndexIn(ArrayFromJSON(duration(TimeUnit::SECOND),
"[0, 1, 2]"),
- ArrayFromJSON(duration(TimeUnit::MILLI), "[0,
2]")));
+ // Different units, cast value_set to values
Review Comment:
Similar comments here :-)
##########
cpp/src/arrow/compute/kernels/scalar_set_lookup_test.cc:
##########
@@ -822,6 +837,50 @@ TEST_F(TestIndexInKernel, Boolean) {
CheckIndexIn(boolean(), "[null, null, null, null]", "[null]", "[0, 0, 0,
0]");
}
+TEST_F(TestIndexInKernel, ImplicitlyCastValueSet) {
+ auto input = ArrayFromJSON(int8(), "[0, 1, 2, 3, 4, 5, 6, 7, 8]");
+
+ SetLookupOptions opts{ArrayFromJSON(int32(), "[2, 3, 5, 7]")};
+ ASSERT_OK_AND_ASSIGN(Datum out, CallFunction("index_in", {input}, &opts));
+
+ auto expected = ArrayFromJSON(int32(), ("[null, null, 0, 1, null,"
+ "2, null, 3, null]"));
+ AssertArraysEqual(*expected, *out.make_array());
+
+ // Although value_set cannot be cast to int8, but int8 is castable to float
+ CheckIndexIn(input, ArrayFromJSON(float32(), "[1.0, 2.5, 3.1, 5.0]"),
+ "[null, 0, null, null, null, 3, null, null, null]");
+
+ // Allow implicit casts between binary types...
+ CheckIndexIn(ArrayFromJSON(binary(), R"(["aaa", "bbb", "ccc", null,
"bbb"])"),
Review Comment:
Similar suggestions here as for `is_in`.
--
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]