michalursa commented on code in PR #12872: URL: https://github.com/apache/arrow/pull/12872#discussion_r853573176
########## cpp/src/arrow/compute/light_array.h: ########## @@ -0,0 +1,380 @@ +// 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. + +#pragma once + +#include <cstdint> + +#include "arrow/array.h" +#include "arrow/compute/exec.h" +#include "arrow/type.h" +#include "arrow/util/logging.h" + +/// This file contains lightweight containers for Arrow buffers. These containers +/// makes compromises in terms of strong ownership and the range of data types supported +/// in order to gain performance and reduced overhead. + +namespace arrow { +namespace compute { + +/// \brief Description of the layout of a "key" column +/// +/// A "key" column is a non-nested, non-union column. +/// Every key column has either 0 (null), 2 (e.g. int32) or 3 (e.g. string) buffers +/// and no children. +/// +/// This metadata object is a zero-allocation analogue of arrow::DataType +struct ARROW_EXPORT KeyColumnMetadata { + KeyColumnMetadata() = default; + KeyColumnMetadata(bool is_fixed_length_in, uint32_t fixed_length_in, + bool is_null_type_in = false) + : is_fixed_length(is_fixed_length_in), + is_null_type(is_null_type_in), + fixed_length(fixed_length_in) {} + /// \brief True if the column is not a varying-length binary type + /// + /// If this is true the column will have a validity buffer and + /// a data buffer and the third buffer will be unused. + bool is_fixed_length; + /// \brief True if this column is the null type + bool is_null_type; + /// \brief The number of bytes for each item + /// + /// Zero has a special meaning, indicating a bit vector with one bit per value if it + /// isn't a null type column. + /// + /// For a varying-length binary column this represents the number of bytes per offset. + uint32_t fixed_length; +}; + +/// \brief A lightweight view into a "key" array +/// +/// A "key" column is a non-nested, non-union column \see KeyColumnMetadata +/// +/// This metadata object is a zero-allocation analogue of arrow::ArrayData +class ARROW_EXPORT KeyColumnArray { + public: + /// \brief Create an uninitialized KeyColumnArray + KeyColumnArray() = default; + /// \brief Create a read-only view from buffers + /// + /// This is a view only and does not take ownership of the buffers. The lifetime + /// of the buffers must exceed the lifetime of this view + KeyColumnArray(const KeyColumnMetadata& metadata, int64_t length, + const uint8_t* buffer0, const uint8_t* buffer1, const uint8_t* buffer2, + int bit_offset0 = 0, int bit_offset1 = 0); Review Comment: done ########## cpp/src/arrow/compute/light_array.h: ########## @@ -0,0 +1,380 @@ +// 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. + +#pragma once + +#include <cstdint> + +#include "arrow/array.h" +#include "arrow/compute/exec.h" +#include "arrow/type.h" +#include "arrow/util/logging.h" + +/// This file contains lightweight containers for Arrow buffers. These containers +/// makes compromises in terms of strong ownership and the range of data types supported +/// in order to gain performance and reduced overhead. + +namespace arrow { +namespace compute { + +/// \brief Description of the layout of a "key" column +/// +/// A "key" column is a non-nested, non-union column. +/// Every key column has either 0 (null), 2 (e.g. int32) or 3 (e.g. string) buffers +/// and no children. +/// +/// This metadata object is a zero-allocation analogue of arrow::DataType +struct ARROW_EXPORT KeyColumnMetadata { + KeyColumnMetadata() = default; + KeyColumnMetadata(bool is_fixed_length_in, uint32_t fixed_length_in, + bool is_null_type_in = false) + : is_fixed_length(is_fixed_length_in), + is_null_type(is_null_type_in), + fixed_length(fixed_length_in) {} + /// \brief True if the column is not a varying-length binary type + /// + /// If this is true the column will have a validity buffer and + /// a data buffer and the third buffer will be unused. + bool is_fixed_length; + /// \brief True if this column is the null type + bool is_null_type; + /// \brief The number of bytes for each item + /// + /// Zero has a special meaning, indicating a bit vector with one bit per value if it + /// isn't a null type column. + /// + /// For a varying-length binary column this represents the number of bytes per offset. + uint32_t fixed_length; +}; + +/// \brief A lightweight view into a "key" array +/// +/// A "key" column is a non-nested, non-union column \see KeyColumnMetadata +/// +/// This metadata object is a zero-allocation analogue of arrow::ArrayData +class ARROW_EXPORT KeyColumnArray { + public: + /// \brief Create an uninitialized KeyColumnArray + KeyColumnArray() = default; + /// \brief Create a read-only view from buffers + /// + /// This is a view only and does not take ownership of the buffers. The lifetime + /// of the buffers must exceed the lifetime of this view + KeyColumnArray(const KeyColumnMetadata& metadata, int64_t length, + const uint8_t* buffer0, const uint8_t* buffer1, const uint8_t* buffer2, + int bit_offset0 = 0, int bit_offset1 = 0); + /// \brief Create a mutable view from buffers + /// + /// This is a view only and does not take ownership of the buffers. The lifetime + /// of the buffers must exceed the lifetime of this view + KeyColumnArray(const KeyColumnMetadata& metadata, int64_t length, uint8_t* buffer0, + uint8_t* buffer1, uint8_t* buffer2, int bit_offset0 = 0, + int bit_offset1 = 0); + /// \brief Create a sliced view of `this` + /// + /// The number of rows used in offset must be divisible by 8 + /// in order to not split bit vectors within a single byte. + KeyColumnArray Slice(int64_t offset, int64_t length) const; + /// \brief Create a copy of `this` with a buffer from `other` + /// + /// The copy will be identical to `this` except the buffer at buffer_id_to_replace + /// will be replaced by the corresponding buffer in `other`. + KeyColumnArray WithBufferFrom(const KeyColumnArray& other, + int buffer_id_to_replace) const; + + /// \brief Create a copy of `this` with new metadata + KeyColumnArray WithMetadata(const KeyColumnMetadata& metadata) const; + + // Constants used for accessing buffers using data() and mutable_data(). + static constexpr int kValidityBuffer = 0; + static constexpr int kFixedLengthBuffer = 1; + static constexpr int kVariableLengthBuffer = 2; + + /// \brief Return one of the underlying mutable buffers + uint8_t* mutable_data(int i) { + ARROW_DCHECK(i >= 0 && i <= kMaxBuffers); + return mutable_buffers_[i]; + } + /// \brief Return one of the underlying read-only buffers + const uint8_t* data(int i) const { + ARROW_DCHECK(i >= 0 && i <= kMaxBuffers); + return buffers_[i]; + } + /// \brief Return a mutable version of the offsets buffer + /// + /// Only valid if this is a view into a varbinary type + uint32_t* mutable_offsets() { + DCHECK(!metadata_.is_fixed_length); + return reinterpret_cast<uint32_t*>(mutable_data(1)); + } + /// \brief Return a read-only version of the offsets buffer + /// + /// Only valid if this is a view into a varbinary type + const uint32_t* offsets() const { + DCHECK(!metadata_.is_fixed_length); + return reinterpret_cast<const uint32_t*>(data(1)); Review Comment: done ########## cpp/src/arrow/compute/light_array.h: ########## @@ -0,0 +1,380 @@ +// 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. + +#pragma once + +#include <cstdint> + +#include "arrow/array.h" +#include "arrow/compute/exec.h" +#include "arrow/type.h" +#include "arrow/util/logging.h" + +/// This file contains lightweight containers for Arrow buffers. These containers +/// makes compromises in terms of strong ownership and the range of data types supported +/// in order to gain performance and reduced overhead. + +namespace arrow { +namespace compute { + +/// \brief Description of the layout of a "key" column +/// +/// A "key" column is a non-nested, non-union column. +/// Every key column has either 0 (null), 2 (e.g. int32) or 3 (e.g. string) buffers +/// and no children. +/// +/// This metadata object is a zero-allocation analogue of arrow::DataType +struct ARROW_EXPORT KeyColumnMetadata { + KeyColumnMetadata() = default; + KeyColumnMetadata(bool is_fixed_length_in, uint32_t fixed_length_in, + bool is_null_type_in = false) + : is_fixed_length(is_fixed_length_in), + is_null_type(is_null_type_in), + fixed_length(fixed_length_in) {} + /// \brief True if the column is not a varying-length binary type + /// + /// If this is true the column will have a validity buffer and + /// a data buffer and the third buffer will be unused. + bool is_fixed_length; + /// \brief True if this column is the null type + bool is_null_type; + /// \brief The number of bytes for each item + /// + /// Zero has a special meaning, indicating a bit vector with one bit per value if it + /// isn't a null type column. + /// + /// For a varying-length binary column this represents the number of bytes per offset. + uint32_t fixed_length; +}; + +/// \brief A lightweight view into a "key" array +/// +/// A "key" column is a non-nested, non-union column \see KeyColumnMetadata +/// +/// This metadata object is a zero-allocation analogue of arrow::ArrayData +class ARROW_EXPORT KeyColumnArray { + public: + /// \brief Create an uninitialized KeyColumnArray + KeyColumnArray() = default; + /// \brief Create a read-only view from buffers + /// + /// This is a view only and does not take ownership of the buffers. The lifetime + /// of the buffers must exceed the lifetime of this view + KeyColumnArray(const KeyColumnMetadata& metadata, int64_t length, + const uint8_t* buffer0, const uint8_t* buffer1, const uint8_t* buffer2, + int bit_offset0 = 0, int bit_offset1 = 0); + /// \brief Create a mutable view from buffers + /// + /// This is a view only and does not take ownership of the buffers. The lifetime + /// of the buffers must exceed the lifetime of this view + KeyColumnArray(const KeyColumnMetadata& metadata, int64_t length, uint8_t* buffer0, + uint8_t* buffer1, uint8_t* buffer2, int bit_offset0 = 0, + int bit_offset1 = 0); + /// \brief Create a sliced view of `this` + /// + /// The number of rows used in offset must be divisible by 8 + /// in order to not split bit vectors within a single byte. + KeyColumnArray Slice(int64_t offset, int64_t length) const; + /// \brief Create a copy of `this` with a buffer from `other` + /// + /// The copy will be identical to `this` except the buffer at buffer_id_to_replace + /// will be replaced by the corresponding buffer in `other`. + KeyColumnArray WithBufferFrom(const KeyColumnArray& other, + int buffer_id_to_replace) const; + + /// \brief Create a copy of `this` with new metadata + KeyColumnArray WithMetadata(const KeyColumnMetadata& metadata) const; + + // Constants used for accessing buffers using data() and mutable_data(). + static constexpr int kValidityBuffer = 0; + static constexpr int kFixedLengthBuffer = 1; + static constexpr int kVariableLengthBuffer = 2; + + /// \brief Return one of the underlying mutable buffers + uint8_t* mutable_data(int i) { + ARROW_DCHECK(i >= 0 && i <= kMaxBuffers); + return mutable_buffers_[i]; + } + /// \brief Return one of the underlying read-only buffers + const uint8_t* data(int i) const { + ARROW_DCHECK(i >= 0 && i <= kMaxBuffers); + return buffers_[i]; + } + /// \brief Return a mutable version of the offsets buffer + /// + /// Only valid if this is a view into a varbinary type + uint32_t* mutable_offsets() { + DCHECK(!metadata_.is_fixed_length); + return reinterpret_cast<uint32_t*>(mutable_data(1)); Review Comment: done -- 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]
