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

[GitHub] [arrow] felipecrv commented on a diff in pull request #34195: GH-32105: [C++] Encode and decode Run-End Encoded vectors

felipecrv commented on code in PR #34195:
URL: https://github.com/apache/arrow/pull/34195#discussion_r1119476602


##########
cpp/src/arrow/compute/kernels/vector_run_end_encode.cc:
##########
@@ -0,0 +1,652 @@
+// 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 <utility>
+
+#include "arrow/compute/api_vector.h"
+#include "arrow/compute/kernels/common_internal.h"
+#include "arrow/util/checked_cast.h"
+#include "arrow/util/ree_util.h"
+
+namespace arrow {
+namespace compute {
+namespace internal {
+
+template <typename ArrowType, bool has_validity_buffer>
+struct ReadValueImpl {
+  using CType = typename ArrowType::c_type;
+
+  [[nodiscard]] bool ReadValue(const uint8_t* input_validity, const void* input_values,
+                               CType* out, int64_t read_offset) const {
+    bool valid = true;
+    if constexpr (has_validity_buffer) {
+      valid = bit_util::GetBit(input_validity, read_offset);
+    }
+    if (valid) {
+      *out = (reinterpret_cast<const CType*>(input_values))[read_offset];
+    }
+    return valid;
+  }
+};
+
+template <>
+bool ReadValueImpl<BooleanType, true>::ReadValue(const uint8_t* input_validity,
+                                                 const void* input_values, CType* out,
+                                                 int64_t read_offset) const {
+  const bool valid = bit_util::GetBit(input_validity, read_offset);
+  *out = valid &&
+         bit_util::GetBit(reinterpret_cast<const uint8_t*>(input_values), read_offset);
+  return valid;
+}
+
+template <>
+bool ReadValueImpl<BooleanType, false>::ReadValue(const uint8_t* input_validity,
+                                                  const void* input_values, CType* out,
+                                                  int64_t read_offset) const {
+  *out = bit_util::GetBit(reinterpret_cast<const uint8_t*>(input_values), read_offset);
+  return true;
+}
+

Review Comment:
   The function definition currently declares kernels for `numeric`, `bool`, and `null` types. The `Type::NA` implementation was a TODO in the initial code by Tobias, and I added a specialized implementation for them. I think I will need something similar that doesn't use this for fixed-length binary arrays. Can I create a separate issue for those and work on getting this PR merged with these initial types. I'm trying to get to a steady flow of small PRs.



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