zanmato1984 commented on code in PR #43734:
URL: https://github.com/apache/arrow/pull/43734#discussion_r1721750423


##########
cpp/src/arrow/compute/row/row_encoder_internal_test.cc:
##########
@@ -0,0 +1,65 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "arrow/compute/row/row_encoder_internal.h"
+#include "arrow/testing/gtest_util.h"
+#include "arrow/type.h"
+#include "arrow/type_fwd.h"
+
+namespace arrow::compute::internal {
+
+// GH-43733: Test that the key encoder can handle boolean scalar values well.
+TEST(TestKeyEncoder, BooleanScalar) {
+  for (auto scalar : {BooleanScalar{}, BooleanScalar{true}, 
BooleanScalar{false}}) {
+    BooleanKeyEncoder key_encoder;
+    SCOPED_TRACE("scalar " + scalar.ToString());
+    constexpr int64_t batch_length = 10;
+    std::array<int32_t, batch_length> lengths{};
+    std::array<std::array<uint8_t, 2>, batch_length> payloads{};
+    key_encoder.AddLength(ExecValue{&scalar}, /*batch_length=*/10, 
lengths.data());
+    std::array<uint8_t*, batch_length> payload_ptrs{};
+    auto reset_and_get_payload_ptrs = [&]() -> uint8_t** {
+      for (int i = 0; i < batch_length; ++i) {
+        payload_ptrs[i] = payloads[i].data();
+      }
+      return payload_ptrs.data();
+    };
+    auto data_payload = reset_and_get_payload_ptrs();
+    ASSERT_OK(key_encoder.Encode(ExecValue{&scalar}, batch_length, 
data_payload));
+    data_payload = reset_and_get_payload_ptrs();
+    ASSERT_OK_AND_ASSIGN(
+        auto array_data,
+        key_encoder.Decode(data_payload, batch_length, 
::arrow::default_memory_pool()));

Review Comment:
   ```suggestion
       auto reset_payload_ptrs = [&]() {
         std::transform(payloads.begin(), payloads.end(), payload_ptrs.begin(),
                        [](auto& payload) -> uint8_t* { return payload.data(); 
});
       };
       reset_payload_ptrs();
       ASSERT_OK(key_encoder.Encode(ExecValue{&scalar}, batch_length, 
payload_ptrs.data()));
       // Reset the `payload_ptrs` again as the content are modified by 
`Encode`.
       reset_payload_ptrs();
       ASSERT_OK_AND_ASSIGN(auto array_data,
                            key_encoder.Decode(payload_ptrs.data(), 
batch_length,
                                               ::arrow::default_memory_pool()));
   ```



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