kou commented on code in PR #49443:
URL: https://github.com/apache/arrow/pull/49443#discussion_r2914649522


##########
cpp/src/arrow/compute/kernels/scalar_if_else_test.cc:
##########
@@ -609,6 +610,48 @@ TYPED_TEST(TestIfElseBaseBinary, IfElseBaseBinaryRand) {
   CheckIfElseOutput(cond, left, right, expected_data);
 }
 
+TYPED_TEST(TestIfElseBaseBinary, IfElseBaseBinarySliced) {
+  auto type = TypeTraits<TypeParam>::type_singleton();
+
+  auto full_arr = ArrayFromJSON(type, R"(["not used", null, "x", "x"])");
+  auto sliced = full_arr->Slice(1);
+
+  auto cond_asa = ArrayFromJSON(boolean(), "[true, false, false]");
+  ASSERT_OK_AND_ASSIGN(auto result_asa,
+                       CallFunction("if_else", {cond_asa, 
MakeNullScalar(type), sliced}));
+  ASSERT_OK(result_asa.make_array()->ValidateFull());
+  auto expected = ArrayFromJSON(type, R"([null, "x", "x"])");
+  AssertArraysEqual(*expected, *result_asa.make_array(), true);
+
+  auto cond_aas = ArrayFromJSON(boolean(), "[false, true, true]");
+  ASSERT_OK_AND_ASSIGN(auto result_aas,
+                       CallFunction("if_else", {cond_aas, sliced, 
MakeNullScalar(type)}));
+  ASSERT_OK(result_aas.make_array()->ValidateFull());
+  AssertArraysEqual(*expected, *result_aas.make_array(), true);
+
+  // edge case: offset=0 but offsets[0] != 0 (spec-valid, manually constructed)
+  using OffsetType = typename TypeTraits<TypeParam>::OffsetType::c_type;
+  std::vector<OffsetType> raw_offsets = {8, 8, 9, 10};
+  std::string raw_data(8, 'x');
+  raw_data += "xx";
+  auto offsets_buf = Buffer::Wrap(raw_offsets.data(), raw_offsets.size());
+  auto data_buf =
+      std::make_shared<Buffer>(reinterpret_cast<const 
uint8_t*>(raw_data.data()),
+                               static_cast<int64_t>(raw_data.size()));
+  auto array_data = ArrayData::Make(type, /*length=*/3, {nullptr, offsets_buf, 
data_buf},
+                                    /*null_count=*/1, /*offset=*/0);
+  std::vector<uint8_t> validity_bytes = {0, 1, 1};
+  ASSERT_OK_AND_ASSIGN(
+      array_data->buffers[0],
+      arrow::internal::BytesToBits(validity_bytes, 
arrow::default_memory_pool()));
+  auto arr = MakeArray(array_data);
+  ASSERT_OK(arr->ValidateFull());
+  ASSERT_OK_AND_ASSIGN(auto result_nonzero,
+                       CallFunction("if_else", {cond_asa, 
MakeNullScalar(type), arr}));
+  ASSERT_OK(result_nonzero.make_array()->ValidateFull());
+  AssertArraysEqual(*expected, *result_nonzero.make_array(), true);

Review Comment:
   Could you split this to a separated test because this data isn't "sliced"?



##########
cpp/src/arrow/compute/kernels/scalar_if_else_test.cc:
##########
@@ -609,6 +610,48 @@ TYPED_TEST(TestIfElseBaseBinary, IfElseBaseBinaryRand) {
   CheckIfElseOutput(cond, left, right, expected_data);
 }
 
+TYPED_TEST(TestIfElseBaseBinary, IfElseBaseBinarySliced) {
+  auto type = TypeTraits<TypeParam>::type_singleton();
+
+  auto full_arr = ArrayFromJSON(type, R"(["not used", null, "x", "x"])");
+  auto sliced = full_arr->Slice(1);
+
+  auto cond_asa = ArrayFromJSON(boolean(), "[true, false, false]");
+  ASSERT_OK_AND_ASSIGN(auto result_asa,
+                       CallFunction("if_else", {cond_asa, 
MakeNullScalar(type), sliced}));
+  ASSERT_OK(result_asa.make_array()->ValidateFull());
+  auto expected = ArrayFromJSON(type, R"([null, "x", "x"])");
+  AssertArraysEqual(*expected, *result_asa.make_array(), true);
+
+  auto cond_aas = ArrayFromJSON(boolean(), "[false, true, true]");
+  ASSERT_OK_AND_ASSIGN(auto result_aas,
+                       CallFunction("if_else", {cond_aas, sliced, 
MakeNullScalar(type)}));
+  ASSERT_OK(result_aas.make_array()->ValidateFull());
+  AssertArraysEqual(*expected, *result_aas.make_array(), true);
+
+  // edge case: offset=0 but offsets[0] != 0 (spec-valid, manually constructed)
+  using OffsetType = typename TypeTraits<TypeParam>::OffsetType::c_type;
+  std::vector<OffsetType> raw_offsets = {8, 8, 9, 10};
+  std::string raw_data(8, 'x');

Review Comment:
   This `'x'` isn't used, right?
   How about using another character for readability?



-- 
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]

Reply via email to