You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "zeroshade (via GitHub)" <gi...@apache.org> on 2023/02/13 16:20:48 UTC

[GitHub] [arrow] zeroshade commented on a diff in pull request #33641: GH-32104: [C++] Add support for Run-End encoded data to Arrow

zeroshade commented on code in PR #33641:
URL: https://github.com/apache/arrow/pull/33641#discussion_r1104686299


##########
cpp/src/arrow/array/array_dict_test.cc:
##########
@@ -1117,12 +1117,12 @@ TEST(TestDictionary, Validate) {
   arr = std::make_shared<DictionaryArray>(dict_type, indices, MakeArray(invalid_data));
   ASSERT_RAISES(Invalid, arr->ValidateFull());
 
-  ASSERT_DEATH(
-      {
-        std::shared_ptr<Array> null_dict_arr =
-            std::make_shared<DictionaryArray>(dict_type, indices, nullptr);
-      },
-      "");
+  //   ASSERT_DEATH(
+  //       {
+  //         std::shared_ptr<Array> null_dict_arr =
+  //             std::make_shared<DictionaryArray>(dict_type, indices, nullptr);
+  //       },
+  //       "");

Review Comment:
   did you mean to leave this commented?



##########
cpp/src/arrow/array/array_run_end.cc:
##########
@@ -0,0 +1,88 @@
+// 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 "arrow/array/array_run_end.h"
+#include "arrow/array/util.h"
+#include "arrow/util/logging.h"
+#include "arrow/util/ree_util.h"
+
+namespace arrow {
+
+// ----------------------------------------------------------------------
+// RunEndEncodedArray
+
+RunEndEncodedArray::RunEndEncodedArray(const std::shared_ptr<ArrayData>& data) {
+  this->SetData(data);
+}
+
+RunEndEncodedArray::RunEndEncodedArray(const std::shared_ptr<DataType>& type,
+                                       int64_t length,
+                                       const std::shared_ptr<Array>& run_ends,
+                                       const std::shared_ptr<Array>& values,
+                                       int64_t offset) {
+  this->SetData(ArrayData::Make(type, length,
+                                /*buffers=*/{NULLPTR},
+                                /*child_data=*/{run_ends->data(), values->data()},
+                                /*null_count=*/0, offset));

Review Comment:
   Should we add a couple `DCHECK_EQ`'s to ensure the passed in type is, in fact, a `run_end_encoded` type and that the run-end type and values type matches the types of the passed in arrays?



##########
cpp/src/arrow/array/array_run_end.cc:
##########
@@ -0,0 +1,88 @@
+// 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 "arrow/array/array_run_end.h"
+#include "arrow/array/util.h"
+#include "arrow/util/logging.h"
+#include "arrow/util/ree_util.h"
+
+namespace arrow {
+
+// ----------------------------------------------------------------------
+// RunEndEncodedArray
+
+RunEndEncodedArray::RunEndEncodedArray(const std::shared_ptr<ArrayData>& data) {
+  this->SetData(data);
+}
+
+RunEndEncodedArray::RunEndEncodedArray(const std::shared_ptr<DataType>& type,
+                                       int64_t length,
+                                       const std::shared_ptr<Array>& run_ends,
+                                       const std::shared_ptr<Array>& values,
+                                       int64_t offset) {
+  this->SetData(ArrayData::Make(type, length,
+                                /*buffers=*/{NULLPTR},
+                                /*child_data=*/{run_ends->data(), values->data()},
+                                /*null_count=*/0, offset));
+}
+
+Result<std::shared_ptr<RunEndEncodedArray>> RunEndEncodedArray::Make(
+    int64_t logical_length, const std::shared_ptr<Array>& run_ends,
+    const std::shared_ptr<Array>& values, int64_t logical_offset) {
+  auto run_end_type = run_ends->type();
+  auto values_type = values->type();
+  if (!RunEndEncodedType::RunEndTypeValid(*run_end_type)) {
+    return Status::Invalid("Run end type must be int16, int32 or int64");
+  }
+  if (run_ends->null_count() != 0) {
+    return Status::Invalid("Run ends array cannot contain null values");
+  }
+
+  return std::make_shared<RunEndEncodedArray>(
+      run_end_encoded(std::move(run_end_type), std::move(values_type)), logical_length,
+      run_ends, values, logical_offset);
+}
+
+void RunEndEncodedArray::SetData(const std::shared_ptr<ArrayData>& data) {
+  ARROW_CHECK_EQ(data->type->id(), Type::RUN_END_ENCODED);
+  DCHECK_EQ(data->child_data.size(), 2);
+
+  // A non-zero number of logical values in this array (offset + length) implies
+  // a non-zero number of runs and values.
+  DCHECK(data->offset + data->length == 0 || data->child_data[0]->length > 0);
+  DCHECK(data->offset + data->length == 0 || data->child_data[1]->length > 0);

Review Comment:
   possibly add a DCHECK that `child_data[1]->length >= child_data[0]->length` ?



##########
cpp/src/arrow/array/array_run_end.cc:
##########
@@ -0,0 +1,88 @@
+// 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 "arrow/array/array_run_end.h"
+#include "arrow/array/util.h"
+#include "arrow/util/logging.h"
+#include "arrow/util/ree_util.h"
+
+namespace arrow {
+
+// ----------------------------------------------------------------------
+// RunEndEncodedArray
+
+RunEndEncodedArray::RunEndEncodedArray(const std::shared_ptr<ArrayData>& data) {
+  this->SetData(data);
+}
+
+RunEndEncodedArray::RunEndEncodedArray(const std::shared_ptr<DataType>& type,
+                                       int64_t length,
+                                       const std::shared_ptr<Array>& run_ends,
+                                       const std::shared_ptr<Array>& values,
+                                       int64_t offset) {
+  this->SetData(ArrayData::Make(type, length,
+                                /*buffers=*/{NULLPTR},
+                                /*child_data=*/{run_ends->data(), values->data()},
+                                /*null_count=*/0, offset));
+}
+
+Result<std::shared_ptr<RunEndEncodedArray>> RunEndEncodedArray::Make(
+    int64_t logical_length, const std::shared_ptr<Array>& run_ends,
+    const std::shared_ptr<Array>& values, int64_t logical_offset) {
+  auto run_end_type = run_ends->type();
+  auto values_type = values->type();
+  if (!RunEndEncodedType::RunEndTypeValid(*run_end_type)) {
+    return Status::Invalid("Run end type must be int16, int32 or int64");
+  }
+  if (run_ends->null_count() != 0) {
+    return Status::Invalid("Run ends array cannot contain null values");
+  }

Review Comment:
   should we return an error if `values->length < run_ends->length` ?



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org