zagto commented on code in PR #13330:
URL: https://github.com/apache/arrow/pull/13330#discussion_r953950594


##########
cpp/src/arrow/array/array_encoded_test.cc:
##########
@@ -0,0 +1,119 @@
+// 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 <gtest/gtest.h>
+
+#include <cstdint>
+#include <cstring>
+#include <memory>
+#include <vector>
+
+#include "arrow/array.h"
+#include "arrow/array/builder_nested.h"
+#include "arrow/chunked_array.h"
+#include "arrow/status.h"
+#include "arrow/testing/builder.h"
+#include "arrow/testing/gtest_util.h"
+#include "arrow/type.h"
+#include "arrow/util/checked_cast.h"
+
+namespace arrow {
+
+using internal::checked_cast;
+
+// ----------------------------------------------------------------------
+// Run-length encoded array tests
+
+namespace {
+
+auto string_values = ArrayFromJSON(utf8(), R"(["Hello", "World", null])");
+auto int32_values = ArrayFromJSON(int32(), "[10, 20, 30]");
+auto int32_only_null = ArrayFromJSON(int32(), "[null, null, null]");
+
+TEST(RunLengthEncodedArray, MakeArray) {
+  ASSERT_OK_AND_ASSIGN(auto rle_array,
+                       RunLengthEncodedArray::Make(int32_values, 
string_values, 3));
+  auto array_data = rle_array->data();
+  auto new_array = MakeArray(array_data);
+  ASSERT_ARRAYS_EQUAL(*new_array, *rle_array);
+  // should be the exact same ArrayData object
+  ASSERT_EQ(new_array->data(), array_data);
+  ASSERT_NE(std::dynamic_pointer_cast<RunLengthEncodedArray>(new_array), 
NULLPTR);
+}
+
+TEST(RunLengthEncodedArray, FromRunEndsAndValues) {
+  std::shared_ptr<RunLengthEncodedArray> rle_array;
+
+  ASSERT_OK_AND_ASSIGN(rle_array,
+                       RunLengthEncodedArray::Make(int32_values, int32_values, 
3));
+  ASSERT_EQ(rle_array->length(), 3);
+  ASSERT_ARRAYS_EQUAL(*rle_array->values_array(), *int32_values);
+  ASSERT_ARRAYS_EQUAL(*rle_array->run_ends_array(), *int32_values);
+  ASSERT_EQ(rle_array->offset(), 0);
+  ASSERT_EQ(rle_array->data()->null_count, 0);
+  // one dummy buffer, since code may assume there is exactly one buffer
+  ASSERT_EQ(rle_array->data()->buffers.size(), 1);

Review Comment:
   This is correct since the RLE parent always has to have a null count of 0, 
and no validity bitmap. It can actually encode arrays with null values, but 
there are not set in the parent, since we don't want the standard on bit per 
logical element validity bitmap. I find this a bit confusing, but this is how 
it works for Unions too. I tried to do it differently first, but Arrow code 
essentially assumes non-zero null count = has validity bitmap



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