diff --git a/cpp/src/arrow/acero/swiss_join.cc b/cpp/src/arrow/acero/swiss_join.cc index 61c8bfe95414e..fce0a77ccafff 100644 --- a/cpp/src/arrow/acero/swiss_join.cc +++ b/cpp/src/arrow/acero/swiss_join.cc @@ -44,7 +44,7 @@ namespace acero { int RowArrayAccessor::VarbinaryColumnId(const RowTableMetadata& row_metadata, int column_id) { - ARROW_DCHECK(row_metadata.num_cols() > static_cast(column_id)); + ARROW_DCHECK(row_metadata.num_cols() > column_id); ARROW_DCHECK(!row_metadata.is_fixed_length); ARROW_DCHECK(!row_metadata.column_metadatas[column_id].is_fixed_length); @@ -79,7 +79,7 @@ int RowArrayAccessor::NumRowsToSkip(const RowTableImpl& rows, int column_id, int // Find the length of the requested varying length field in that row // - uint32_t field_offset_within_row, field_length; + int32_t field_offset_within_row, field_length; if (varbinary_column_id == 0) { rows.metadata().first_varbinary_offset_and_length( row_ptr, &field_offset_within_row, &field_length); @@ -94,10 +94,9 @@ int RowArrayAccessor::NumRowsToSkip(const RowTableImpl& rows, int column_id, int } else { // Fixed length column // - uint32_t field_length = rows.metadata().column_metadatas[column_id].fixed_length; - uint32_t num_bytes_skipped = 0; - while (num_rows_left > 0 && - num_bytes_skipped < static_cast(num_tail_bytes_to_skip)) { + int32_t field_length = rows.metadata().column_metadatas[column_id].fixed_length; + int32_t num_bytes_skipped = 0; + while (num_rows_left > 0 && num_bytes_skipped < num_tail_bytes_to_skip) { num_bytes_skipped += field_length; --num_rows_left; } @@ -122,8 +121,8 @@ void RowArrayAccessor::Visit(const RowTableImpl& rows, int column_id, int num_ro if (!is_fixed_length_column) { int varbinary_column_id = VarbinaryColumnId(rows.metadata(), column_id); const uint8_t* row_ptr_base = rows.data(2); - const uint32_t* row_offsets = rows.offsets(); - uint32_t field_offset_within_row, field_length; + const int32_t* row_offsets = rows.offsets(); + int32_t field_offset_within_row, field_length; if (varbinary_column_id == 0) { // Case 1: This is the first varbinary column @@ -149,15 +148,15 @@ void RowArrayAccessor::Visit(const RowTableImpl& rows, int column_id, int num_ro } if (is_fixed_length_column) { - uint32_t field_offset_within_row = rows.metadata().encoded_field_offset( + int32_t field_offset_within_row = rows.metadata().encoded_field_offset( rows.metadata().pos_after_encoding(column_id)); - uint32_t field_length = rows.metadata().column_metadatas[column_id].fixed_length; + int32_t field_length = rows.metadata().column_metadatas[column_id].fixed_length; // Bit column is encoded as a single byte // if (field_length == 0) { field_length = 1; } - uint32_t row_length = rows.metadata().fixed_length; + int32_t row_length = rows.metadata().fixed_length; bool is_fixed_length_row = rows.metadata().is_fixed_length; if (is_fixed_length_row) { @@ -173,7 +172,7 @@ void RowArrayAccessor::Visit(const RowTableImpl& rows, int column_id, int num_ro // Case 4: This is a fixed length column in a varying length row // const uint8_t* row_ptr_base = rows.data(2) + field_offset_within_row; - const uint32_t* row_offsets = rows.offsets(); + const int32_t* row_offsets = rows.offsets(); for (int i = 0; i < num_rows; ++i) { uint32_t row_id = row_ids[i]; const uint8_t* row_ptr = row_ptr_base + row_offsets[row_id]; @@ -269,7 +268,7 @@ Status RowArray::DecodeSelected(ResizableArrayData* output, int column_id, ARROW_ASSIGN_OR_RAISE(KeyColumnMetadata column_metadata, output->column_metadata()); if (column_metadata.is_fixed_length) { - uint32_t fixed_length = column_metadata.fixed_length; + int32_t fixed_length = column_metadata.fixed_length; switch (fixed_length) { case 0: RowArrayAccessor::Visit(rows_, column_id, num_rows_to_append, row_ids, @@ -375,7 +374,7 @@ void RowArray::DebugPrintToFile(const char* filename, bool print_sorted) const { } for (int64_t row_id = 0; row_id < rows_.length(); ++row_id) { - for (uint32_t column_id = 0; column_id < rows_.metadata().num_cols(); ++column_id) { + for (int column_id = 0; column_id < rows_.metadata().num_cols(); ++column_id) { bool is_null; uint32_t row_id_cast = static_cast(row_id); RowArrayAccessor::VisitNulls(rows_, column_id, 1, &row_id_cast, @@ -493,11 +492,11 @@ Status RowArrayMerge::PrepareForMerge(RowArray* target, num_rows = 0; num_bytes = 0; for (size_t i = 0; i < sources.size(); ++i) { - target->rows_.mutable_offsets()[num_rows] = static_cast(num_bytes); + target->rows_.mutable_offsets()[num_rows] = static_cast(num_bytes); num_rows += sources[i]->rows_.length(); num_bytes += sources[i]->rows_.offsets()[sources[i]->rows_.length()]; } - target->rows_.mutable_offsets()[num_rows] = static_cast(num_bytes); + target->rows_.mutable_offsets()[num_rows] = static_cast(num_bytes); } return Status::OK(); @@ -565,15 +564,15 @@ void RowArrayMerge::CopyVaryingLength(RowTableImpl* target, const RowTableImpl& int64_t first_target_row_offset, const int64_t* source_rows_permutation) { int64_t num_source_rows = source.length(); - uint32_t* target_offsets = target->mutable_offsets(); - const uint32_t* source_offsets = source.offsets(); + int32_t* target_offsets = target->mutable_offsets(); + const int32_t* source_offsets = source.offsets(); // Permutation of source rows is optional. // if (!source_rows_permutation) { int64_t target_row_offset = first_target_row_offset; for (int64_t i = 0; i < num_source_rows; ++i) { - target_offsets[first_target_row_id + i] = static_cast(target_row_offset); + target_offsets[first_target_row_id + i] = static_cast(target_row_offset); target_row_offset += source_offsets[i + 1] - source_offsets[i]; } // We purposefully skip outputting of N+1 offset, to allow concurrent @@ -604,7 +603,7 @@ void RowArrayMerge::CopyVaryingLength(RowTableImpl* target, const RowTableImpl& *target_row_ptr++ = *source_row_ptr++; } - target_offsets[first_target_row_id + i] = static_cast(target_row_offset); + target_offsets[first_target_row_id + i] = static_cast(target_row_offset); target_row_offset += length; } } diff --git a/cpp/src/arrow/acero/swiss_join_avx2.cc b/cpp/src/arrow/acero/swiss_join_avx2.cc index 0888dd8938455..4a1bcb8c34052 100644 --- a/cpp/src/arrow/acero/swiss_join_avx2.cc +++ b/cpp/src/arrow/acero/swiss_join_avx2.cc @@ -45,7 +45,7 @@ int RowArrayAccessor::Visit_avx2(const RowTableImpl& rows, int column_id, int nu if (!is_fixed_length_column) { int varbinary_column_id = VarbinaryColumnId(rows.metadata(), column_id); const uint8_t* row_ptr_base = rows.data(2); - const uint32_t* row_offsets = rows.offsets(); + const int32_t* row_offsets = rows.offsets(); if (varbinary_column_id == 0) { // Case 1: This is the first varbinary column @@ -56,8 +56,7 @@ int RowArrayAccessor::Visit_avx2(const RowTableImpl& rows, int column_id, int nu for (int i = 0; i < num_rows / unroll; ++i) { __m256i row_id = _mm256_loadu_si256(reinterpret_cast(row_ids) + i); - __m256i row_offset = _mm256_i32gather_epi32( - reinterpret_cast(row_offsets), row_id, sizeof(uint32_t)); + __m256i row_offset = _mm256_i32gather_epi32(row_offsets, row_id, sizeof(int32_t)); __m256i field_length = _mm256_sub_epi32( _mm256_i32gather_epi32( reinterpret_cast(row_ptr_base), @@ -78,8 +77,7 @@ int RowArrayAccessor::Visit_avx2(const RowTableImpl& rows, int column_id, int nu for (int i = 0; i < num_rows / unroll; ++i) { __m256i row_id = _mm256_loadu_si256(reinterpret_cast(row_ids) + i); - __m256i row_offset = _mm256_i32gather_epi32( - reinterpret_cast(row_offsets), row_id, sizeof(uint32_t)); + __m256i row_offset = _mm256_i32gather_epi32(row_offsets, row_id, sizeof(int32_t)); __m256i end_array_offset = _mm256_add_epi32(row_offset, varbinary_end_array_offset); @@ -140,12 +138,11 @@ int RowArrayAccessor::Visit_avx2(const RowTableImpl& rows, int column_id, int nu // Case 4: This is a fixed length column in varying length row // const uint8_t* row_ptr_base = rows.data(2); - const uint32_t* row_offsets = rows.offsets(); + const int32_t* row_offsets = rows.offsets(); for (int i = 0; i < num_rows / unroll; ++i) { __m256i row_id = _mm256_loadu_si256(reinterpret_cast(row_ids) + i); - __m256i row_offset = _mm256_i32gather_epi32( - reinterpret_cast(row_offsets), row_id, sizeof(uint32_t)); + __m256i row_offset = _mm256_i32gather_epi32(row_offsets, row_id, sizeof(int32_t)); __m256i field_offset = _mm256_add_epi32(row_offset, field_offset_within_row); process_8_values_fn(i * unroll, row_ptr_base, field_offset, field_length); } diff --git a/cpp/src/arrow/compute/key_hash_internal.cc b/cpp/src/arrow/compute/key_hash_internal.cc index a0002efb3faf3..907538d3b11ff 100644 --- a/cpp/src/arrow/compute/key_hash_internal.cc +++ b/cpp/src/arrow/compute/key_hash_internal.cc @@ -235,7 +235,7 @@ void Hashing32::HashVarLenImp(uint32_t num_rows, const T* offsets, } void Hashing32::HashVarLen(int64_t hardware_flags, bool combine_hashes, uint32_t num_rows, - const uint32_t* offsets, const uint8_t* concatenated_keys, + const int32_t* offsets, const uint8_t* concatenated_keys, uint32_t* hashes, uint32_t* hashes_temp_for_combine) { uint32_t num_processed = 0; #if defined(ARROW_HAVE_RUNTIME_AVX2) @@ -245,16 +245,16 @@ void Hashing32::HashVarLen(int64_t hardware_flags, bool combine_hashes, uint32_t } #endif if (combine_hashes) { - HashVarLenImp(num_rows - num_processed, offsets + num_processed, - concatenated_keys, hashes + num_processed); + HashVarLenImp(num_rows - num_processed, offsets + num_processed, + concatenated_keys, hashes + num_processed); } else { - HashVarLenImp(num_rows - num_processed, offsets + num_processed, - concatenated_keys, hashes + num_processed); + HashVarLenImp(num_rows - num_processed, offsets + num_processed, + concatenated_keys, hashes + num_processed); } } void Hashing32::HashVarLen(int64_t hardware_flags, bool combine_hashes, uint32_t num_rows, - const uint64_t* offsets, const uint8_t* concatenated_keys, + const int64_t* offsets, const uint8_t* concatenated_keys, uint32_t* hashes, uint32_t* hashes_temp_for_combine) { uint32_t num_processed = 0; #if defined(ARROW_HAVE_RUNTIME_AVX2) @@ -264,11 +264,11 @@ void Hashing32::HashVarLen(int64_t hardware_flags, bool combine_hashes, uint32_t } #endif if (combine_hashes) { - HashVarLenImp(num_rows - num_processed, offsets + num_processed, - concatenated_keys, hashes + num_processed); + HashVarLenImp(num_rows - num_processed, offsets + num_processed, + concatenated_keys, hashes + num_processed); } else { - HashVarLenImp(num_rows - num_processed, offsets + num_processed, - concatenated_keys, hashes + num_processed); + HashVarLenImp(num_rows - num_processed, offsets + num_processed, + concatenated_keys, hashes + num_processed); } } @@ -705,23 +705,21 @@ void Hashing64::HashVarLenImp(uint32_t num_rows, const T* offsets, } } -void Hashing64::HashVarLen(bool combine_hashes, uint32_t num_rows, - const uint32_t* offsets, const uint8_t* concatenated_keys, - uint64_t* hashes) { +void Hashing64::HashVarLen(bool combine_hashes, uint32_t num_rows, const int32_t* offsets, + const uint8_t* concatenated_keys, uint64_t* hashes) { if (combine_hashes) { - HashVarLenImp(num_rows, offsets, concatenated_keys, hashes); + HashVarLenImp(num_rows, offsets, concatenated_keys, hashes); } else { - HashVarLenImp(num_rows, offsets, concatenated_keys, hashes); + HashVarLenImp(num_rows, offsets, concatenated_keys, hashes); } } -void Hashing64::HashVarLen(bool combine_hashes, uint32_t num_rows, - const uint64_t* offsets, const uint8_t* concatenated_keys, - uint64_t* hashes) { +void Hashing64::HashVarLen(bool combine_hashes, uint32_t num_rows, const int64_t* offsets, + const uint8_t* concatenated_keys, uint64_t* hashes) { if (combine_hashes) { - HashVarLenImp(num_rows, offsets, concatenated_keys, hashes); + HashVarLenImp(num_rows, offsets, concatenated_keys, hashes); } else { - HashVarLenImp(num_rows, offsets, concatenated_keys, hashes); + HashVarLenImp(num_rows, offsets, concatenated_keys, hashes); } } diff --git a/cpp/src/arrow/compute/key_hash_internal.h b/cpp/src/arrow/compute/key_hash_internal.h index 7d226f52086b1..8b0617c8aea6b 100644 --- a/cpp/src/arrow/compute/key_hash_internal.h +++ b/cpp/src/arrow/compute/key_hash_internal.h @@ -67,11 +67,11 @@ class ARROW_EXPORT Hashing32 { static const int64_t kStripeSize = 4 * sizeof(uint32_t); static void HashVarLen(int64_t hardware_flags, bool combine_hashes, uint32_t num_rows, - const uint32_t* offsets, const uint8_t* concatenated_keys, + const int32_t* offsets, const uint8_t* concatenated_keys, uint32_t* hashes, uint32_t* temp_hashes_for_combine); static void HashVarLen(int64_t hardware_flags, bool combine_hashes, uint32_t num_rows, - const uint64_t* offsets, const uint8_t* concatenated_keys, + const int64_t* offsets, const uint8_t* concatenated_keys, uint32_t* hashes, uint32_t* temp_hashes_for_combine); static inline uint32_t Avalanche(uint32_t acc) { @@ -140,11 +140,11 @@ class ARROW_EXPORT Hashing32 { const uint8_t* concatenated_keys, uint32_t* hashes, uint32_t* hashes_temp_for_combine); static uint32_t HashVarLen_avx2(bool combine_hashes, uint32_t num_rows, - const uint32_t* offsets, + const int32_t* offsets, const uint8_t* concatenated_keys, uint32_t* hashes, uint32_t* hashes_temp_for_combine); static uint32_t HashVarLen_avx2(bool combine_hashes, uint32_t num_rows, - const uint64_t* offsets, + const int64_t* offsets, const uint8_t* concatenated_keys, uint32_t* hashes, uint32_t* hashes_temp_for_combine); #endif @@ -178,10 +178,10 @@ class ARROW_EXPORT Hashing64 { static const uint32_t kCombineConst = 0x9e3779b9UL; static const int64_t kStripeSize = 4 * sizeof(uint64_t); - static void HashVarLen(bool combine_hashes, uint32_t num_rows, const uint32_t* offsets, + static void HashVarLen(bool combine_hashes, uint32_t num_rows, const int32_t* offsets, const uint8_t* concatenated_keys, uint64_t* hashes); - static void HashVarLen(bool combine_hashes, uint32_t num_rows, const uint64_t* offsets, + static void HashVarLen(bool combine_hashes, uint32_t num_rows, const int64_t* offsets, const uint8_t* concatenated_keys, uint64_t* hashes); static inline uint64_t Avalanche(uint64_t acc); diff --git a/cpp/src/arrow/compute/key_hash_internal_avx2.cc b/cpp/src/arrow/compute/key_hash_internal_avx2.cc index 4def87bd7aa20..0159ed74673a5 100644 --- a/cpp/src/arrow/compute/key_hash_internal_avx2.cc +++ b/cpp/src/arrow/compute/key_hash_internal_avx2.cc @@ -288,28 +288,28 @@ uint32_t Hashing32::HashVarLenImp_avx2(uint32_t num_rows, const T* offsets, } uint32_t Hashing32::HashVarLen_avx2(bool combine_hashes, uint32_t num_rows, - const uint32_t* offsets, + const int32_t* offsets, const uint8_t* concatenated_keys, uint32_t* hashes, uint32_t* hashes_temp_for_combine) { if (combine_hashes) { - return HashVarLenImp_avx2(num_rows, offsets, concatenated_keys, - hashes, hashes_temp_for_combine); + return HashVarLenImp_avx2(num_rows, offsets, concatenated_keys, hashes, + hashes_temp_for_combine); } else { - return HashVarLenImp_avx2(num_rows, offsets, concatenated_keys, - hashes, hashes_temp_for_combine); + return HashVarLenImp_avx2(num_rows, offsets, concatenated_keys, + hashes, hashes_temp_for_combine); } } uint32_t Hashing32::HashVarLen_avx2(bool combine_hashes, uint32_t num_rows, - const uint64_t* offsets, + const int64_t* offsets, const uint8_t* concatenated_keys, uint32_t* hashes, uint32_t* hashes_temp_for_combine) { if (combine_hashes) { - return HashVarLenImp_avx2(num_rows, offsets, concatenated_keys, - hashes, hashes_temp_for_combine); + return HashVarLenImp_avx2(num_rows, offsets, concatenated_keys, hashes, + hashes_temp_for_combine); } else { - return HashVarLenImp_avx2(num_rows, offsets, concatenated_keys, - hashes, hashes_temp_for_combine); + return HashVarLenImp_avx2(num_rows, offsets, concatenated_keys, + hashes, hashes_temp_for_combine); } } diff --git a/cpp/src/arrow/compute/key_hash_test.cc b/cpp/src/arrow/compute/key_hash_test.cc index 4e5d869cb7db6..1c09e678559e9 100644 --- a/cpp/src/arrow/compute/key_hash_test.cc +++ b/cpp/src/arrow/compute/key_hash_test.cc @@ -98,7 +98,7 @@ class TestVectorHash { bool use_varlen_input, int min_length, int max_length) { using ArrayType = typename TypeTraits::ArrayType; using OffsetType = typename TypeTraits::OffsetType; - using offset_t = typename std::make_unsigned::type; + using offset_t = typename OffsetType::c_type; constexpr int min_num_unique = 100; constexpr int max_num_unique = 1000; diff --git a/cpp/src/arrow/compute/light_array_internal.cc b/cpp/src/arrow/compute/light_array_internal.cc index 4f235925d0fb6..c3828f01ee11d 100644 --- a/cpp/src/arrow/compute/light_array_internal.cc +++ b/cpp/src/arrow/compute/light_array_internal.cc @@ -201,8 +201,7 @@ Status ColumnArraysFromExecBatch(const ExecBatch& batch, int64_t start_row, Status ColumnArraysFromExecBatch(const ExecBatch& batch, std::vector* column_arrays) { - return ColumnArraysFromExecBatch(batch, 0, static_cast(batch.length), - column_arrays); + return ColumnArraysFromExecBatch(batch, 0, batch.length, column_arrays); } void ResizableArrayData::Init(const std::shared_ptr& data_type, @@ -355,9 +354,9 @@ std::shared_ptr ResizableArrayData::array_data() const { KeyColumnMetadata column_metadata; column_metadata = ColumnMetadataFromDataType(data_type_).ValueOrDie(); - auto valid_count = arrow::internal::CountSetBits( - buffers_[kValidityBuffer]->data(), /*offset=*/0, static_cast(num_rows_)); - int null_count = static_cast(num_rows_) - static_cast(valid_count); + auto valid_count = arrow::internal::CountSetBits(buffers_[kValidityBuffer]->data(), + /*offset=*/0, num_rows_); + auto null_count = num_rows_ - valid_count; if (column_metadata.is_fixed_length) { return ArrayData::Make(data_type_, num_rows_, @@ -478,9 +477,8 @@ void ExecBatchBuilder::Visit(const std::shared_ptr& column, int num_r for (int i = 0; i < num_rows; ++i) { uint16_t row_id = row_ids[i]; const uint8_t* field_ptr = - column->buffers[1]->data() + - (column->offset + row_id) * static_cast(metadata.fixed_length); - process_value_fn(i, field_ptr, static_cast(metadata.fixed_length)); + column->buffers[1]->data() + (column->offset + row_id) * metadata.fixed_length; + process_value_fn(i, field_ptr, metadata.fixed_length); } } } @@ -583,7 +581,7 @@ Status ExecBatchBuilder::AppendSelected(const std::shared_ptr& source }); for (int i = 0; i < num_rows_to_append; ++i) { int32_t length = offsets[num_rows_before + i]; - offsets[num_rows_before + i] = sum; + offsets[num_rows_before + i] = static_cast(sum); int32_t new_sum_maybe_overflow = 0; if (ARROW_PREDICT_FALSE( arrow::internal::AddWithOverflow(sum, length, &new_sum_maybe_overflow))) { diff --git a/cpp/src/arrow/compute/light_array_internal.h b/cpp/src/arrow/compute/light_array_internal.h index 67de71bf56c92..206f757a312ac 100644 --- a/cpp/src/arrow/compute/light_array_internal.h +++ b/cpp/src/arrow/compute/light_array_internal.h @@ -72,7 +72,7 @@ struct ARROW_EXPORT KeyColumnMetadata { /// isn't a null type column. /// /// For a varying-length binary column this represents the number of bytes per offset. - uint32_t fixed_length; + int32_t fixed_length; }; /// \brief A lightweight view into a "key" array @@ -133,34 +133,34 @@ class ARROW_EXPORT KeyColumnArray { /// \brief Return a mutable version of the offsets buffer /// /// Only valid if this is a view into a varbinary type - uint32_t* mutable_offsets() { + int32_t* mutable_offsets() { DCHECK(!metadata_.is_fixed_length); DCHECK_EQ(metadata_.fixed_length, sizeof(uint32_t)); - return reinterpret_cast(mutable_data(kFixedLengthBuffer)); + return reinterpret_cast(mutable_data(kFixedLengthBuffer)); } /// \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 { + const int32_t* offsets() const { DCHECK(!metadata_.is_fixed_length); DCHECK_EQ(metadata_.fixed_length, sizeof(uint32_t)); - return reinterpret_cast(data(kFixedLengthBuffer)); + return reinterpret_cast(data(kFixedLengthBuffer)); } /// \brief Return a mutable version of the large-offsets buffer /// /// Only valid if this is a view into a large varbinary type - uint64_t* mutable_large_offsets() { + int64_t* mutable_large_offsets() { DCHECK(!metadata_.is_fixed_length); DCHECK_EQ(metadata_.fixed_length, sizeof(uint64_t)); - return reinterpret_cast(mutable_data(kFixedLengthBuffer)); + return reinterpret_cast(mutable_data(kFixedLengthBuffer)); } /// \brief Return a read-only version of the large-offsets buffer /// /// Only valid if this is a view into a large varbinary type - const uint64_t* large_offsets() const { + const int64_t* large_offsets() const { DCHECK(!metadata_.is_fixed_length); DCHECK_EQ(metadata_.fixed_length, sizeof(uint64_t)); - return reinterpret_cast(data(kFixedLengthBuffer)); + return reinterpret_cast(data(kFixedLengthBuffer)); } /// \brief Return the type metadata const KeyColumnMetadata& metadata() const { return metadata_; } diff --git a/cpp/src/arrow/compute/row/compare_internal.cc b/cpp/src/arrow/compute/row/compare_internal.cc index 078a8287c71c0..47051e87e06e7 100644 --- a/cpp/src/arrow/compute/row/compare_internal.cc +++ b/cpp/src/arrow/compute/row/compare_internal.cc @@ -31,7 +31,7 @@ namespace arrow { namespace compute { template -void KeyCompare::NullUpdateColumnToRow(uint32_t id_col, uint32_t num_rows_to_compare, +void KeyCompare::NullUpdateColumnToRow(uint32_t id_col, int32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, const uint32_t* left_to_right_map, LightContext* ctx, const KeyColumnArray& col, @@ -57,7 +57,7 @@ void KeyCompare::NullUpdateColumnToRow(uint32_t id_col, uint32_t num_rows_to_com // Remove rows from the result for which the column value is a null const uint8_t* null_masks = rows.null_masks(); uint32_t null_mask_num_bytes = rows.metadata().null_masks_bytes_per_row; - for (uint32_t i = num_processed; i < num_rows_to_compare; ++i) { + for (int32_t i = num_processed; i < num_rows_to_compare; ++i) { uint32_t irow_left = use_selection ? sel_left_maybe_null[i] : i; uint32_t irow_right = left_to_right_map[irow_left]; int64_t bitid = irow_right * null_mask_num_bytes * 8 + null_bit_id; @@ -68,7 +68,7 @@ void KeyCompare::NullUpdateColumnToRow(uint32_t id_col, uint32_t num_rows_to_com // null const uint8_t* non_nulls = col.data(0); ARROW_DCHECK(non_nulls); - for (uint32_t i = num_processed; i < num_rows_to_compare; ++i) { + for (int32_t i = num_processed; i < num_rows_to_compare; ++i) { uint32_t irow_left = use_selection ? sel_left_maybe_null[i] : i; match_bytevector[i] &= bit_util::GetBit(non_nulls, irow_left + col.bit_offset(0)) ? 0xff : 0; @@ -78,7 +78,7 @@ void KeyCompare::NullUpdateColumnToRow(uint32_t id_col, uint32_t num_rows_to_com uint32_t null_mask_num_bytes = rows.metadata().null_masks_bytes_per_row; const uint8_t* non_nulls = col.data(0); ARROW_DCHECK(non_nulls); - for (uint32_t i = num_processed; i < num_rows_to_compare; ++i) { + for (int32_t i = num_processed; i < num_rows_to_compare; ++i) { uint32_t irow_left = use_selection ? sel_left_maybe_null[i] : i; uint32_t irow_right = left_to_right_map[irow_left]; int64_t bitid_right = irow_right * null_mask_num_bytes * 8 + null_bit_id; @@ -93,37 +93,37 @@ void KeyCompare::NullUpdateColumnToRow(uint32_t id_col, uint32_t num_rows_to_com template void KeyCompare::CompareBinaryColumnToRowHelper( - uint32_t offset_within_row, uint32_t first_row_to_compare, - uint32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, - const uint32_t* left_to_right_map, LightContext* ctx, const KeyColumnArray& col, - const RowTableImpl& rows, uint8_t* match_bytevector, COMPARE_FN compare_fn) { + int32_t offset_within_row, uint32_t first_row_to_compare, int32_t num_rows_to_compare, + const uint16_t* sel_left_maybe_null, const uint32_t* left_to_right_map, + LightContext* ctx, const KeyColumnArray& col, const RowTableImpl& rows, + uint8_t* match_bytevector, COMPARE_FN compare_fn) { bool is_fixed_length = rows.metadata().is_fixed_length; if (is_fixed_length) { uint32_t fixed_length = rows.metadata().fixed_length; const uint8_t* rows_left = col.data(1); const uint8_t* rows_right = rows.data(1); - for (uint32_t i = first_row_to_compare; i < num_rows_to_compare; ++i) { + for (int32_t i = first_row_to_compare; i < num_rows_to_compare; ++i) { uint32_t irow_left = use_selection ? sel_left_maybe_null[i] : i; uint32_t irow_right = left_to_right_map[irow_left]; - uint32_t offset_right = irow_right * fixed_length + offset_within_row; + int32_t offset_right = irow_right * fixed_length + offset_within_row; match_bytevector[i] = compare_fn(rows_left, rows_right, irow_left, offset_right); } } else { const uint8_t* rows_left = col.data(1); - const uint32_t* offsets_right = rows.offsets(); + const int32_t* offsets_right = rows.offsets(); const uint8_t* rows_right = rows.data(2); - for (uint32_t i = first_row_to_compare; i < num_rows_to_compare; ++i) { + for (int32_t i = first_row_to_compare; i < num_rows_to_compare; ++i) { uint32_t irow_left = use_selection ? sel_left_maybe_null[i] : i; uint32_t irow_right = left_to_right_map[irow_left]; - uint32_t offset_right = offsets_right[irow_right] + offset_within_row; + int32_t offset_right = offsets_right[irow_right] + offset_within_row; match_bytevector[i] = compare_fn(rows_left, rows_right, irow_left, offset_right); } } } template -void KeyCompare::CompareBinaryColumnToRow(uint32_t offset_within_row, - uint32_t num_rows_to_compare, +void KeyCompare::CompareBinaryColumnToRow(int32_t offset_within_row, + int32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, const uint32_t* left_to_right_map, LightContext* ctx, const KeyColumnArray& col, @@ -236,22 +236,22 @@ void KeyCompare::CompareBinaryColumnToRow(uint32_t offset_within_row, // Overwrites the match_bytevector instead of updating it template void KeyCompare::CompareVarBinaryColumnToRowHelper( - uint32_t id_varbinary_col, uint32_t first_row_to_compare, - uint32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, - const uint32_t* left_to_right_map, LightContext* ctx, const KeyColumnArray& col, - const RowTableImpl& rows, uint8_t* match_bytevector) { - const uint32_t* offsets_left = col.offsets(); - const uint32_t* offsets_right = rows.offsets(); + uint32_t id_varbinary_col, uint32_t first_row_to_compare, int32_t num_rows_to_compare, + const uint16_t* sel_left_maybe_null, const uint32_t* left_to_right_map, + LightContext* ctx, const KeyColumnArray& col, const RowTableImpl& rows, + uint8_t* match_bytevector) { + const int32_t* offsets_left = col.offsets(); + const int32_t* offsets_right = rows.offsets(); const uint8_t* rows_left = col.data(2); const uint8_t* rows_right = rows.data(2); - for (uint32_t i = first_row_to_compare; i < num_rows_to_compare; ++i) { + for (int32_t i = first_row_to_compare; i < num_rows_to_compare; ++i) { uint32_t irow_left = use_selection ? sel_left_maybe_null[i] : i; uint32_t irow_right = left_to_right_map[irow_left]; - uint32_t begin_left = offsets_left[irow_left]; - uint32_t length_left = offsets_left[irow_left + 1] - begin_left; - uint32_t begin_right = offsets_right[irow_right]; - uint32_t length_right; - uint32_t offset_within_row; + int32_t begin_left = offsets_left[irow_left]; + int32_t length_left = offsets_left[irow_left + 1] - begin_left; + int32_t begin_right = offsets_right[irow_right]; + int32_t length_right; + int32_t offset_within_row; if (!is_first_varbinary_col) { rows.metadata().nth_varbinary_offset_and_length( rows_right + begin_right, id_varbinary_col, &offset_within_row, &length_right); @@ -260,7 +260,7 @@ void KeyCompare::CompareVarBinaryColumnToRowHelper( rows_right + begin_right, &offset_within_row, &length_right); } begin_right += offset_within_row; - uint32_t length = std::min(length_left, length_right); + int32_t length = std::min(length_left, length_right); const uint64_t* key_left_ptr = reinterpret_cast(rows_left + begin_left); util::CheckAlignment(rows_right + begin_right); @@ -291,7 +291,7 @@ void KeyCompare::CompareVarBinaryColumnToRowHelper( // Overwrites the match_bytevector instead of updating it template void KeyCompare::CompareVarBinaryColumnToRow(uint32_t id_varbinary_col, - uint32_t num_rows_to_compare, + int32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, const uint32_t* left_to_right_map, LightContext* ctx, const KeyColumnArray& col, @@ -328,7 +328,7 @@ void KeyCompare::AndByteVectors(LightContext* ctx, uint32_t num_elements, } void KeyCompare::CompareColumnsToRows( - uint32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, + int32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, const uint32_t* left_to_right_map, LightContext* ctx, uint32_t* out_num_rows, uint16_t* out_sel_left_maybe_same, const std::vector& cols, const RowTableImpl& rows, bool are_cols_in_encoding_order, @@ -363,7 +363,7 @@ void KeyCompare::CompareColumnsToRows( continue; } - uint32_t offset_within_row = rows.metadata().encoded_field_offset( + int32_t offset_within_row = rows.metadata().encoded_field_offset( are_cols_in_encoding_order ? static_cast(icol) : rows.metadata().pos_after_encoding(static_cast(icol))); diff --git a/cpp/src/arrow/compute/row/compare_internal.h b/cpp/src/arrow/compute/row/compare_internal.h index b039ca97ff978..cf567c688976b 100644 --- a/cpp/src/arrow/compute/row/compare_internal.h +++ b/cpp/src/arrow/compute/row/compare_internal.h @@ -36,7 +36,7 @@ class ARROW_EXPORT KeyCompare { // If there is input selection on the left, the resulting selection is a filtered image // of input selection. static void CompareColumnsToRows( - uint32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, + int32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, const uint32_t* left_to_right_map, LightContext* ctx, uint32_t* out_num_rows, uint16_t* out_sel_left_maybe_same, const std::vector& cols, const RowTableImpl& rows, bool are_cols_in_encoding_order, @@ -44,7 +44,7 @@ class ARROW_EXPORT KeyCompare { private: template - static void NullUpdateColumnToRow(uint32_t id_col, uint32_t num_rows_to_compare, + static void NullUpdateColumnToRow(uint32_t id_col, int32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, const uint32_t* left_to_right_map, LightContext* ctx, const KeyColumnArray& col, const RowTableImpl& rows, @@ -53,14 +53,14 @@ class ARROW_EXPORT KeyCompare { template static void CompareBinaryColumnToRowHelper( - uint32_t offset_within_row, uint32_t first_row_to_compare, - uint32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, + int32_t offset_within_row, uint32_t first_row_to_compare, + int32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, const uint32_t* left_to_right_map, LightContext* ctx, const KeyColumnArray& col, const RowTableImpl& rows, uint8_t* match_bytevector, COMPARE_FN compare_fn); template - static void CompareBinaryColumnToRow(uint32_t offset_within_row, - uint32_t num_rows_to_compare, + static void CompareBinaryColumnToRow(int32_t offset_within_row, + int32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, const uint32_t* left_to_right_map, LightContext* ctx, const KeyColumnArray& col, @@ -69,14 +69,14 @@ class ARROW_EXPORT KeyCompare { template static void CompareVarBinaryColumnToRowHelper( - uint32_t id_varlen_col, uint32_t first_row_to_compare, uint32_t num_rows_to_compare, + uint32_t id_varlen_col, uint32_t first_row_to_compare, int32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, const uint32_t* left_to_right_map, LightContext* ctx, const KeyColumnArray& col, const RowTableImpl& rows, uint8_t* match_bytevector); template static void CompareVarBinaryColumnToRow(uint32_t id_varlen_col, - uint32_t num_rows_to_compare, + int32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, const uint32_t* left_to_right_map, LightContext* ctx, const KeyColumnArray& col, @@ -89,28 +89,28 @@ class ARROW_EXPORT KeyCompare { #if defined(ARROW_HAVE_RUNTIME_AVX2) template - static uint32_t NullUpdateColumnToRowImp_avx2( - uint32_t id_col, uint32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, + static int32_t NullUpdateColumnToRowImp_avx2( + uint32_t id_col, int32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, const uint32_t* left_to_right_map, LightContext* ctx, const KeyColumnArray& col, const RowTableImpl& rows, uint8_t* match_bytevector); template - static uint32_t CompareBinaryColumnToRowHelper_avx2( - uint32_t offset_within_row, uint32_t num_rows_to_compare, + static int32_t CompareBinaryColumnToRowHelper_avx2( + int32_t offset_within_row, int32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, const uint32_t* left_to_right_map, LightContext* ctx, const KeyColumnArray& col, const RowTableImpl& rows, uint8_t* match_bytevector, COMPARE8_FN compare8_fn); template - static uint32_t CompareBinaryColumnToRowImp_avx2( - uint32_t offset_within_row, uint32_t num_rows_to_compare, + static int32_t CompareBinaryColumnToRowImp_avx2( + int32_t offset_within_row, int32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, const uint32_t* left_to_right_map, LightContext* ctx, const KeyColumnArray& col, const RowTableImpl& rows, uint8_t* match_bytevector); template static void CompareVarBinaryColumnToRowImp_avx2( - uint32_t id_varlen_col, uint32_t num_rows_to_compare, + uint32_t id_varlen_col, int32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, const uint32_t* left_to_right_map, LightContext* ctx, const KeyColumnArray& col, const RowTableImpl& rows, uint8_t* match_bytevector); @@ -118,23 +118,23 @@ class ARROW_EXPORT KeyCompare { static uint32_t AndByteVectors_avx2(uint32_t num_elements, uint8_t* bytevector_A, const uint8_t* bytevector_B); - static uint32_t NullUpdateColumnToRow_avx2(bool use_selection, uint32_t id_col, - uint32_t num_rows_to_compare, - const uint16_t* sel_left_maybe_null, - const uint32_t* left_to_right_map, - LightContext* ctx, const KeyColumnArray& col, - const RowTableImpl& rows, - uint8_t* match_bytevector); + static int32_t NullUpdateColumnToRow_avx2(bool use_selection, uint32_t id_col, + int32_t num_rows_to_compare, + const uint16_t* sel_left_maybe_null, + const uint32_t* left_to_right_map, + LightContext* ctx, const KeyColumnArray& col, + const RowTableImpl& rows, + uint8_t* match_bytevector); - static uint32_t CompareBinaryColumnToRow_avx2( - bool use_selection, uint32_t offset_within_row, uint32_t num_rows_to_compare, + static int32_t CompareBinaryColumnToRow_avx2( + bool use_selection, int32_t offset_within_row, int32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, const uint32_t* left_to_right_map, LightContext* ctx, const KeyColumnArray& col, const RowTableImpl& rows, uint8_t* match_bytevector); - static uint32_t CompareVarBinaryColumnToRow_avx2( + static int32_t CompareVarBinaryColumnToRow_avx2( bool use_selection, bool is_first_varbinary_col, uint32_t id_varlen_col, - uint32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, + int32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, const uint32_t* left_to_right_map, LightContext* ctx, const KeyColumnArray& col, const RowTableImpl& rows, uint8_t* match_bytevector); diff --git a/cpp/src/arrow/compute/row/compare_internal_avx2.cc b/cpp/src/arrow/compute/row/compare_internal_avx2.cc index ff407c51b83cb..b790b4ea490de 100644 --- a/cpp/src/arrow/compute/row/compare_internal_avx2.cc +++ b/cpp/src/arrow/compute/row/compare_internal_avx2.cc @@ -36,8 +36,8 @@ inline __m256i set_first_n_bytes_avx2(int n) { } template -uint32_t KeyCompare::NullUpdateColumnToRowImp_avx2( - uint32_t id_col, uint32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, +int32_t KeyCompare::NullUpdateColumnToRowImp_avx2( + uint32_t id_col, int32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, const uint32_t* left_to_right_map, LightContext* ctx, const KeyColumnArray& col, const RowTableImpl& rows, uint8_t* match_bytevector) { if (!rows.has_any_nulls(ctx) && !col.data(0)) { @@ -51,9 +51,9 @@ uint32_t KeyCompare::NullUpdateColumnToRowImp_avx2( const uint8_t* null_masks = rows.null_masks(); uint32_t null_mask_num_bytes = rows.metadata().null_masks_bytes_per_row; - uint32_t num_processed = 0; - constexpr uint32_t unroll = 8; - for (uint32_t i = 0; i < num_rows_to_compare / unroll; ++i) { + int32_t num_processed = 0; + constexpr int32_t unroll = 8; + for (int32_t i = 0; i < num_rows_to_compare / unroll; ++i) { __m256i irow_right; if (use_selection) { __m256i irow_left = _mm256_cvtepu16_epi32( @@ -86,9 +86,9 @@ uint32_t KeyCompare::NullUpdateColumnToRowImp_avx2( // null const uint8_t* non_nulls = col.data(0); ARROW_DCHECK(non_nulls); - uint32_t num_processed = 0; - constexpr uint32_t unroll = 8; - for (uint32_t i = 0; i < num_rows_to_compare / unroll; ++i) { + int32_t num_processed = 0; + constexpr int32_t unroll = 8; + for (int32_t i = 0; i < num_rows_to_compare / unroll; ++i) { __m256i cmp; if (use_selection) { __m256i irow_left = _mm256_cvtepu16_epi32( @@ -121,9 +121,9 @@ uint32_t KeyCompare::NullUpdateColumnToRowImp_avx2( const uint8_t* non_nulls = col.data(0); ARROW_DCHECK(non_nulls); - uint32_t num_processed = 0; - constexpr uint32_t unroll = 8; - for (uint32_t i = 0; i < num_rows_to_compare / unroll; ++i) { + int32_t num_processed = 0; + constexpr int32_t unroll = 8; + for (int32_t i = 0; i < num_rows_to_compare / unroll; ++i) { __m256i left_null; __m256i irow_right; if (use_selection) { @@ -179,8 +179,8 @@ uint32_t KeyCompare::NullUpdateColumnToRowImp_avx2( } template -uint32_t KeyCompare::CompareBinaryColumnToRowHelper_avx2( - uint32_t offset_within_row, uint32_t num_rows_to_compare, +int32_t KeyCompare::CompareBinaryColumnToRowHelper_avx2( + int32_t offset_within_row, int32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, const uint32_t* left_to_right_map, LightContext* ctx, const KeyColumnArray& col, const RowTableImpl& rows, uint8_t* match_bytevector, COMPARE8_FN compare8_fn) { @@ -189,9 +189,9 @@ uint32_t KeyCompare::CompareBinaryColumnToRowHelper_avx2( uint32_t fixed_length = rows.metadata().fixed_length; const uint8_t* rows_left = col.data(1); const uint8_t* rows_right = rows.data(1); - constexpr uint32_t unroll = 8; + constexpr int32_t unroll = 8; __m256i irow_left = _mm256_setr_epi32(0, 1, 2, 3, 4, 5, 6, 7); - for (uint32_t i = 0; i < num_rows_to_compare / unroll; ++i) { + for (int32_t i = 0; i < num_rows_to_compare / unroll; ++i) { if (use_selection) { irow_left = _mm256_cvtepu16_epi32( _mm_loadu_si128(reinterpret_cast(sel_left_maybe_null) + i)); @@ -218,11 +218,11 @@ uint32_t KeyCompare::CompareBinaryColumnToRowHelper_avx2( return num_rows_to_compare - (num_rows_to_compare % unroll); } else { const uint8_t* rows_left = col.data(1); - const uint32_t* offsets_right = rows.offsets(); + const int32_t* offsets_right = rows.offsets(); const uint8_t* rows_right = rows.data(2); - constexpr uint32_t unroll = 8; + constexpr int32_t unroll = 8; __m256i irow_left = _mm256_setr_epi32(0, 1, 2, 3, 4, 5, 6, 7); - for (uint32_t i = 0; i < num_rows_to_compare / unroll; ++i) { + for (int32_t i = 0; i < num_rows_to_compare / unroll; ++i) { if (use_selection) { irow_left = _mm256_cvtepu16_epi32( _mm_loadu_si128(reinterpret_cast(sel_left_maybe_null) + i)); @@ -234,8 +234,7 @@ uint32_t KeyCompare::CompareBinaryColumnToRowHelper_avx2( irow_right = _mm256_loadu_si256(reinterpret_cast(left_to_right_map) + i); } - __m256i offset_right = - _mm256_i32gather_epi32((const int*)offsets_right, irow_right, 4); + __m256i offset_right = _mm256_i32gather_epi32(offsets_right, irow_right, 4); offset_right = _mm256_add_epi32(offset_right, _mm256_set1_epi32(offset_within_row)); reinterpret_cast(match_bytevector)[i] = @@ -415,8 +414,8 @@ inline uint64_t Compare8_Binary_avx2(uint32_t length, const uint8_t* left_base, } template -uint32_t KeyCompare::CompareBinaryColumnToRowImp_avx2( - uint32_t offset_within_row, uint32_t num_rows_to_compare, +int32_t KeyCompare::CompareBinaryColumnToRowImp_avx2( + int32_t offset_within_row, int32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, const uint32_t* left_to_right_map, LightContext* ctx, const KeyColumnArray& col, const RowTableImpl& rows, uint8_t* match_bytevector) { @@ -500,22 +499,22 @@ uint32_t KeyCompare::CompareBinaryColumnToRowImp_avx2( // Overwrites the match_bytevector instead of updating it template void KeyCompare::CompareVarBinaryColumnToRowImp_avx2( - uint32_t id_varbinary_col, uint32_t num_rows_to_compare, + uint32_t id_varbinary_col, int32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, const uint32_t* left_to_right_map, LightContext* ctx, const KeyColumnArray& col, const RowTableImpl& rows, uint8_t* match_bytevector) { - const uint32_t* offsets_left = col.offsets(); - const uint32_t* offsets_right = rows.offsets(); + const int32_t* offsets_left = col.offsets(); + const int32_t* offsets_right = rows.offsets(); const uint8_t* rows_left = col.data(2); const uint8_t* rows_right = rows.data(2); - for (uint32_t i = 0; i < num_rows_to_compare; ++i) { + for (int32_t i = 0; i < num_rows_to_compare; ++i) { uint32_t irow_left = use_selection ? sel_left_maybe_null[i] : i; uint32_t irow_right = left_to_right_map[irow_left]; - uint32_t begin_left = offsets_left[irow_left]; - uint32_t length_left = offsets_left[irow_left + 1] - begin_left; - uint32_t begin_right = offsets_right[irow_right]; - uint32_t length_right; - uint32_t offset_within_row; + int32_t begin_left = offsets_left[irow_left]; + int32_t length_left = offsets_left[irow_left + 1] - begin_left; + int32_t begin_right = offsets_right[irow_right]; + int32_t length_right; + int32_t offset_within_row; if (!is_first_varbinary_col) { rows.metadata().nth_varbinary_offset_and_length( rows_right + begin_right, id_varbinary_col, &offset_within_row, &length_right); @@ -526,7 +525,7 @@ void KeyCompare::CompareVarBinaryColumnToRowImp_avx2( begin_right += offset_within_row; __m256i result_or = _mm256_setzero_si256(); - uint32_t length = std::min(length_left, length_right); + int32_t length = std::min(length_left, length_right); if (length > 0) { const __m256i* key_left_ptr = reinterpret_cast(rows_left + begin_left); @@ -534,7 +533,7 @@ void KeyCompare::CompareVarBinaryColumnToRowImp_avx2( reinterpret_cast(rows_right + begin_right); int32_t j; // length is greater than zero - for (j = 0; j < (static_cast(length) + 31) / 32 - 1; ++j) { + for (j = 0; j < (length + 31) / 32 - 1; ++j) { __m256i key_left = _mm256_loadu_si256(key_left_ptr + j); __m256i key_right = _mm256_loadu_si256(key_right_ptr + j); result_or = _mm256_or_si256(result_or, _mm256_xor_si256(key_left, key_right)); @@ -565,18 +564,18 @@ uint32_t KeyCompare::AndByteVectors_avx2(uint32_t num_elements, uint8_t* bytevec return (num_elements - (num_elements % unroll)); } -uint32_t KeyCompare::NullUpdateColumnToRow_avx2( - bool use_selection, uint32_t id_col, uint32_t num_rows_to_compare, +int32_t KeyCompare::NullUpdateColumnToRow_avx2( + bool use_selection, uint32_t id_col, int32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, const uint32_t* left_to_right_map, LightContext* ctx, const KeyColumnArray& col, const RowTableImpl& rows, uint8_t* match_bytevector) { int64_t num_rows_safe = TailSkipForSIMD::FixBitAccess(sizeof(uint32_t), col.length(), col.bit_offset(0)); if (sel_left_maybe_null) { - num_rows_to_compare = static_cast(TailSkipForSIMD::FixSelection( - num_rows_safe, static_cast(num_rows_to_compare), sel_left_maybe_null)); + num_rows_to_compare = static_cast(TailSkipForSIMD::FixSelection( + num_rows_safe, num_rows_to_compare, sel_left_maybe_null)); } else { - num_rows_to_compare = static_cast(num_rows_safe); + num_rows_to_compare = static_cast(num_rows_safe); } if (use_selection) { @@ -590,8 +589,8 @@ uint32_t KeyCompare::NullUpdateColumnToRow_avx2( } } -uint32_t KeyCompare::CompareBinaryColumnToRow_avx2( - bool use_selection, uint32_t offset_within_row, uint32_t num_rows_to_compare, +int32_t KeyCompare::CompareBinaryColumnToRow_avx2( + bool use_selection, int32_t offset_within_row, int32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, const uint32_t* left_to_right_map, LightContext* ctx, const KeyColumnArray& col, const RowTableImpl& rows, uint8_t* match_bytevector) { @@ -611,10 +610,10 @@ uint32_t KeyCompare::CompareBinaryColumnToRow_avx2( TailSkipForSIMD::FixBinaryAccess(sizeof(__m256i), col.length(), col_width); } if (sel_left_maybe_null) { - num_rows_to_compare = static_cast(TailSkipForSIMD::FixSelection( - num_rows_safe, static_cast(num_rows_to_compare), sel_left_maybe_null)); + num_rows_to_compare = static_cast(TailSkipForSIMD::FixSelection( + num_rows_safe, num_rows_to_compare, sel_left_maybe_null)); } else { - num_rows_to_compare = static_cast( + num_rows_to_compare = static_cast( std::min(num_rows_safe, static_cast(num_rows_to_compare))); } @@ -629,18 +628,18 @@ uint32_t KeyCompare::CompareBinaryColumnToRow_avx2( } } -uint32_t KeyCompare::CompareVarBinaryColumnToRow_avx2( +int32_t KeyCompare::CompareVarBinaryColumnToRow_avx2( bool use_selection, bool is_first_varbinary_col, uint32_t id_varlen_col, - uint32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, + int32_t num_rows_to_compare, const uint16_t* sel_left_maybe_null, const uint32_t* left_to_right_map, LightContext* ctx, const KeyColumnArray& col, const RowTableImpl& rows, uint8_t* match_bytevector) { int64_t num_rows_safe = TailSkipForSIMD::FixVarBinaryAccess(sizeof(__m256i), col.length(), col.offsets()); if (use_selection) { - num_rows_to_compare = static_cast(TailSkipForSIMD::FixSelection( - num_rows_safe, static_cast(num_rows_to_compare), sel_left_maybe_null)); + num_rows_to_compare = static_cast(TailSkipForSIMD::FixSelection( + num_rows_safe, num_rows_to_compare, sel_left_maybe_null)); } else { - num_rows_to_compare = static_cast(num_rows_safe); + num_rows_to_compare = static_cast(num_rows_safe); } if (use_selection) { diff --git a/cpp/src/arrow/compute/row/encode_internal.cc b/cpp/src/arrow/compute/row/encode_internal.cc index 01d552ef8270f..8303aae19ed6d 100644 --- a/cpp/src/arrow/compute/row/encode_internal.cc +++ b/cpp/src/arrow/compute/row/encode_internal.cc @@ -24,8 +24,8 @@ namespace compute { void RowTableEncoder::Init(const std::vector& cols, int row_alignment, int string_alignment) { row_metadata_.FromColumnMetadataVector(cols, row_alignment, string_alignment); - uint32_t num_cols = row_metadata_.num_cols(); - uint32_t num_varbinary_cols = row_metadata_.num_varbinary_cols(); + int32_t num_cols = row_metadata_.num_cols(); + int32_t num_varbinary_cols = row_metadata_.num_varbinary_cols(); batch_all_cols_.resize(num_cols); batch_varbinary_cols_.resize(num_varbinary_cols); batch_varbinary_cols_base_offsets_.resize(num_varbinary_cols); @@ -163,7 +163,7 @@ Status RowTableEncoder::EncodeSelected(RowTableImpl* rows, uint32_t num_selected for (size_t icol = 0; icol < batch_all_cols_.size(); ++icol) { if (batch_all_cols_[icol].metadata().is_fixed_length) { - uint32_t offset_within_row = rows->metadata().column_offsets[icol]; + int32_t offset_within_row = rows->metadata().column_offsets[icol]; EncoderBinary::EncodeSelected(offset_within_row, rows, batch_all_cols_[icol], num_selected, selection); } @@ -188,7 +188,7 @@ struct TransformBoolean { const KeyColumnArray& temp) { // Make sure that the temp buffer is large enough DCHECK(temp.length() >= column.length() && temp.metadata().is_fixed_length && - temp.metadata().fixed_length >= sizeof(uint8_t)); + temp.metadata().fixed_length >= static_cast(sizeof(uint8_t))); KeyColumnMetadata metadata; metadata.is_fixed_length = true; metadata.fixed_length = sizeof(uint8_t); @@ -238,7 +238,7 @@ void EncoderInteger::PostDecode(const KeyColumnArray& input, KeyColumnArray* out } void EncoderInteger::Decode(uint32_t start_row, uint32_t num_rows, - uint32_t offset_within_row, const RowTableImpl& rows, + int32_t offset_within_row, const RowTableImpl& rows, KeyColumnArray* col, LightContext* ctx, KeyColumnArray* temp) { KeyColumnArray col_prep; @@ -288,7 +288,7 @@ void EncoderInteger::Decode(uint32_t start_row, uint32_t num_rows, DCHECK(false); } } else { - const uint32_t* row_offsets = rows.offsets() + start_row; + const int32_t* row_offsets = rows.offsets() + start_row; const uint8_t* row_base = rows.data(2); row_base += offset_within_row; uint8_t* col_base = col_prep.mutable_data(1); @@ -327,7 +327,7 @@ void EncoderInteger::Decode(uint32_t start_row, uint32_t num_rows, } template -void EncoderBinary::EncodeSelectedImp(uint32_t offset_within_row, RowTableImpl* rows, +void EncoderBinary::EncodeSelectedImp(int32_t offset_within_row, RowTableImpl* rows, const KeyColumnArray& col, uint32_t num_selected, const uint16_t* selection, COPY_FN copy_fn, SET_NULL_FN set_null_fn) { @@ -354,14 +354,14 @@ void EncoderBinary::EncodeSelectedImp(uint32_t offset_within_row, RowTableImpl* } else { const uint8_t* src_base = col.data(1); uint8_t* dst = rows->mutable_data(2) + offset_within_row; - const uint32_t* offsets = rows->offsets(); + const int32_t* offsets = rows->offsets(); for (uint32_t i = 0; i < num_selected; ++i) { copy_fn(dst + offsets[i], src_base, selection[i]); } if (col.data(0)) { const uint8_t* non_null_bits = col.data(0); uint8_t* dst = rows->mutable_data(2) + offset_within_row; - const uint32_t* offsets = rows->offsets(); + const int32_t* offsets = rows->offsets(); for (uint32_t i = 0; i < num_selected; ++i) { bool is_null = !bit_util::GetBit(non_null_bits, selection[i] + col.bit_offset(0)); if (is_null) { @@ -372,7 +372,7 @@ void EncoderBinary::EncodeSelectedImp(uint32_t offset_within_row, RowTableImpl* } } -void EncoderBinary::EncodeSelected(uint32_t offset_within_row, RowTableImpl* rows, +void EncoderBinary::EncodeSelected(int32_t offset_within_row, RowTableImpl* rows, const KeyColumnArray& col, uint32_t num_selected, const uint16_t* selection) { if (col.metadata().is_null_type) { @@ -441,7 +441,7 @@ bool EncoderBinary::IsInteger(const KeyColumnMetadata& metadata) { } void EncoderBinary::Decode(uint32_t start_row, uint32_t num_rows, - uint32_t offset_within_row, const RowTableImpl& rows, + int32_t offset_within_row, const RowTableImpl& rows, KeyColumnArray* col, LightContext* ctx, KeyColumnArray* temp) { if (IsInteger(col->metadata())) { EncoderInteger::Decode(start_row, num_rows, offset_within_row, rows, col, ctx, temp); @@ -478,7 +478,7 @@ void EncoderBinary::Decode(uint32_t start_row, uint32_t num_rows, template void EncoderBinary::DecodeImp(uint32_t start_row, uint32_t num_rows, - uint32_t offset_within_row, const RowTableImpl& rows, + int32_t offset_within_row, const RowTableImpl& rows, KeyColumnArray* col) { DecodeHelper( start_row, num_rows, offset_within_row, &rows, nullptr, col, col, @@ -492,7 +492,7 @@ void EncoderBinary::DecodeImp(uint32_t start_row, uint32_t num_rows, } void EncoderBinaryPair::Decode(uint32_t start_row, uint32_t num_rows, - uint32_t offset_within_row, const RowTableImpl& rows, + int32_t offset_within_row, const RowTableImpl& rows, KeyColumnArray* col1, KeyColumnArray* col2, LightContext* ctx, KeyColumnArray* temp1, KeyColumnArray* temp2) { @@ -532,7 +532,7 @@ void EncoderBinaryPair::Decode(uint32_t start_row, uint32_t num_rows, } #endif if (num_processed < num_rows) { - using DecodeImp_t = void (*)(uint32_t, uint32_t, uint32_t, uint32_t, + using DecodeImp_t = void (*)(uint32_t, uint32_t, uint32_t, int32_t, const RowTableImpl&, KeyColumnArray*, KeyColumnArray*); static const DecodeImp_t DecodeImp_fn[] = { DecodeImp, DecodeImp, @@ -567,7 +567,7 @@ void EncoderBinaryPair::Decode(uint32_t start_row, uint32_t num_rows, template void EncoderBinaryPair::DecodeImp(uint32_t num_rows_to_skip, uint32_t start_row, - uint32_t num_rows, uint32_t offset_within_row, + uint32_t num_rows, int32_t offset_within_row, const RowTableImpl& rows, KeyColumnArray* col1, KeyColumnArray* col2) { DCHECK(rows.length() >= start_row + num_rows); @@ -577,7 +577,7 @@ void EncoderBinaryPair::DecodeImp(uint32_t num_rows_to_skip, uint32_t start_row, uint8_t* dst_B = col2->mutable_data(1); uint32_t fixed_length = rows.metadata().fixed_length; - const uint32_t* offsets; + const int32_t* offsets; const uint8_t* src_base; if (is_row_fixed_length) { src_base = rows.data(1) + fixed_length * start_row + offset_within_row; @@ -632,11 +632,11 @@ void EncoderOffsets::Decode(uint32_t start_row, uint32_t num_rows, // The Nth element is the sum of all the lengths of varbinary columns data in // that row, up to and including Nth varbinary column. - const uint32_t* row_offsets = rows.offsets() + start_row; + const int32_t* row_offsets = rows.offsets() + start_row; // Set the base offset for each column for (size_t col = 0; col < varbinary_cols->size(); ++col) { - uint32_t* col_offsets = (*varbinary_cols)[col].mutable_offsets(); + int32_t* col_offsets = (*varbinary_cols)[col].mutable_offsets(); col_offsets[0] = varbinary_cols_base_offset[col]; } @@ -645,16 +645,16 @@ void EncoderOffsets::Decode(uint32_t start_row, uint32_t num_rows, for (uint32_t i = 0; i < num_rows; ++i) { // Find the beginning of cumulative lengths array for next row const uint8_t* row = rows.data(2) + row_offsets[i]; - const uint32_t* varbinary_ends = rows.metadata().varbinary_end_array(row); + const int32_t* varbinary_ends = rows.metadata().varbinary_end_array(row); // Update the offset of each column - uint32_t offset_within_row = rows.metadata().fixed_length; + int32_t offset_within_row = rows.metadata().fixed_length; for (size_t col = 0; col < varbinary_cols->size(); ++col) { offset_within_row += RowTableMetadata::padding_for_alignment(offset_within_row, string_alignment); - uint32_t length = varbinary_ends[col] - offset_within_row; + int32_t length = varbinary_ends[col] - offset_within_row; offset_within_row = varbinary_ends[col]; - uint32_t* col_offsets = (*varbinary_cols)[col].mutable_offsets(); + int32_t* col_offsets = (*varbinary_cols)[col].mutable_offsets(); col_offsets[i + 1] = col_offsets[i] + length; } } @@ -668,7 +668,7 @@ void EncoderOffsets::GetRowOffsetsSelected(RowTableImpl* rows, return; } - uint32_t* row_offsets = rows->mutable_offsets(); + int32_t* row_offsets = rows->mutable_offsets(); for (uint32_t i = 0; i < num_selected; ++i) { row_offsets[i] = rows->metadata().fixed_length; } @@ -676,7 +676,7 @@ void EncoderOffsets::GetRowOffsetsSelected(RowTableImpl* rows, for (size_t icol = 0; icol < cols.size(); ++icol) { bool is_fixed_length = (cols[icol].metadata().is_fixed_length); if (!is_fixed_length) { - const uint32_t* col_offsets = cols[icol].offsets(); + const int32_t* col_offsets = cols[icol].offsets(); for (uint32_t i = 0; i < num_selected; ++i) { uint32_t irow = selection[i]; uint32_t length = col_offsets[irow + 1] - col_offsets[irow]; @@ -686,7 +686,7 @@ void EncoderOffsets::GetRowOffsetsSelected(RowTableImpl* rows, } const uint8_t* non_null_bits = cols[icol].data(0); if (non_null_bits) { - const uint32_t* col_offsets = cols[icol].offsets(); + const int32_t* col_offsets = cols[icol].offsets(); for (uint32_t i = 0; i < num_selected; ++i) { uint32_t irow = selection[i]; bool is_null = @@ -715,11 +715,11 @@ template void EncoderOffsets::EncodeSelectedImp(uint32_t ivarbinary, RowTableImpl* rows, const std::vector& cols, uint32_t num_selected, const uint16_t* selection) { - const uint32_t* row_offsets = rows->offsets(); + const int32_t* row_offsets = rows->offsets(); uint8_t* row_base = rows->mutable_data(2) + rows->metadata().varbinary_end_array_offset + ivarbinary * sizeof(uint32_t); - const uint32_t* col_offsets = cols[ivarbinary].offsets(); + const int32_t* col_offsets = cols[ivarbinary].offsets(); const uint8_t* col_non_null_bits = cols[ivarbinary].data(0); for (uint32_t i = 0; i < num_selected; ++i) { @@ -840,16 +840,16 @@ void EncoderNulls::Decode(uint32_t start_row, uint32_t num_rows, const RowTableI void EncoderVarBinary::EncodeSelected(uint32_t ivarbinary, RowTableImpl* rows, const KeyColumnArray& cols, uint32_t num_selected, const uint16_t* selection) { - const uint32_t* row_offsets = rows->offsets(); + const int32_t* row_offsets = rows->offsets(); uint8_t* row_base = rows->mutable_data(2); - const uint32_t* col_offsets = cols.offsets(); + const int32_t* col_offsets = cols.offsets(); const uint8_t* col_base = cols.data(2); if (ivarbinary == 0) { for (uint32_t i = 0; i < num_selected; ++i) { uint8_t* row = row_base + row_offsets[i]; - uint32_t row_offset; - uint32_t length; + int32_t row_offset; + int32_t length; rows->metadata().first_varbinary_offset_and_length(row, &row_offset, &length); uint32_t irow = selection[i]; memcpy(row + row_offset, col_base + col_offsets[irow], length); @@ -857,8 +857,8 @@ void EncoderVarBinary::EncodeSelected(uint32_t ivarbinary, RowTableImpl* rows, } else { for (uint32_t i = 0; i < num_selected; ++i) { uint8_t* row = row_base + row_offsets[i]; - uint32_t row_offset; - uint32_t length; + int32_t row_offset; + int32_t length; rows->metadata().nth_varbinary_offset_and_length(row, ivarbinary, &row_offset, &length); uint32_t irow = selection[i]; diff --git a/cpp/src/arrow/compute/row/encode_internal.h b/cpp/src/arrow/compute/row/encode_internal.h index 2afc150530b9e..515e641a23799 100644 --- a/cpp/src/arrow/compute/row/encode_internal.h +++ b/cpp/src/arrow/compute/row/encode_internal.h @@ -122,7 +122,7 @@ class ARROW_EXPORT RowTableEncoder { class EncoderInteger { public: - static void Decode(uint32_t start_row, uint32_t num_rows, uint32_t offset_within_row, + static void Decode(uint32_t start_row, uint32_t num_rows, int32_t offset_within_row, const RowTableImpl& rows, KeyColumnArray* col, LightContext* ctx, KeyColumnArray* temp); static bool UsesTransform(const KeyColumnArray& column); @@ -137,24 +137,24 @@ class EncoderInteger { class EncoderBinary { public: - static void EncodeSelected(uint32_t offset_within_row, RowTableImpl* rows, + static void EncodeSelected(int32_t offset_within_row, RowTableImpl* rows, const KeyColumnArray& col, uint32_t num_selected, const uint16_t* selection); - static void Decode(uint32_t start_row, uint32_t num_rows, uint32_t offset_within_row, + static void Decode(uint32_t start_row, uint32_t num_rows, int32_t offset_within_row, const RowTableImpl& rows, KeyColumnArray* col, LightContext* ctx, KeyColumnArray* temp); static bool IsInteger(const KeyColumnMetadata& metadata); private: template - static void EncodeSelectedImp(uint32_t offset_within_row, RowTableImpl* rows, + static void EncodeSelectedImp(int32_t offset_within_row, RowTableImpl* rows, const KeyColumnArray& col, uint32_t num_selected, const uint16_t* selection, COPY_FN copy_fn, SET_NULL_FN set_null_fn); template static inline void DecodeHelper(uint32_t start_row, uint32_t num_rows, - uint32_t offset_within_row, + int32_t offset_within_row, const RowTableImpl* rows_const, RowTableImpl* rows_mutable_maybe_null, const KeyColumnArray* col_const, @@ -173,7 +173,7 @@ class EncoderBinary { copy_fn(dst, src, col_width); } } else { - const uint32_t* row_offsets = rows_const->offsets(); + const int32_t* row_offsets = rows_const->offsets(); for (uint32_t i = 0; i < num_rows; ++i) { const uint8_t* src; uint8_t* dst; @@ -185,15 +185,15 @@ class EncoderBinary { } template - static void DecodeImp(uint32_t start_row, uint32_t num_rows, uint32_t offset_within_row, + static void DecodeImp(uint32_t start_row, uint32_t num_rows, int32_t offset_within_row, const RowTableImpl& rows, KeyColumnArray* col); #if defined(ARROW_HAVE_RUNTIME_AVX2) static void DecodeHelper_avx2(bool is_row_fixed_length, uint32_t start_row, - uint32_t num_rows, uint32_t offset_within_row, + uint32_t num_rows, int32_t offset_within_row, const RowTableImpl& rows, KeyColumnArray* col); template static void DecodeImp_avx2(uint32_t start_row, uint32_t num_rows, - uint32_t offset_within_row, const RowTableImpl& rows, + int32_t offset_within_row, const RowTableImpl& rows, KeyColumnArray* col); #endif }; @@ -204,23 +204,23 @@ class EncoderBinaryPair { const KeyColumnMetadata& col2) { return EncoderBinary::IsInteger(col1) && EncoderBinary::IsInteger(col2); } - static void Decode(uint32_t start_row, uint32_t num_rows, uint32_t offset_within_row, + static void Decode(uint32_t start_row, uint32_t num_rows, int32_t offset_within_row, const RowTableImpl& rows, KeyColumnArray* col1, KeyColumnArray* col2, LightContext* ctx, KeyColumnArray* temp1, KeyColumnArray* temp2); private: template static void DecodeImp(uint32_t num_rows_to_skip, uint32_t start_row, uint32_t num_rows, - uint32_t offset_within_row, const RowTableImpl& rows, + int32_t offset_within_row, const RowTableImpl& rows, KeyColumnArray* col1, KeyColumnArray* col2); #if defined(ARROW_HAVE_RUNTIME_AVX2) static uint32_t DecodeHelper_avx2(bool is_row_fixed_length, uint32_t col_width, uint32_t start_row, uint32_t num_rows, - uint32_t offset_within_row, const RowTableImpl& rows, + int32_t offset_within_row, const RowTableImpl& rows, KeyColumnArray* col1, KeyColumnArray* col2); template static uint32_t DecodeImp_avx2(uint32_t start_row, uint32_t num_rows, - uint32_t offset_within_row, const RowTableImpl& rows, + int32_t offset_within_row, const RowTableImpl& rows, KeyColumnArray* col1, KeyColumnArray* col2); #endif }; @@ -256,7 +256,7 @@ class EncoderVarBinary { private: template - static inline void DecodeHelper(uint32_t start_row, uint32_t num_rows, + static inline void DecodeHelper(uint32_t start_row, int32_t num_rows, uint32_t varbinary_col_id, const RowTableImpl* rows_const, RowTableImpl* rows_mutable_maybe_null, @@ -267,19 +267,19 @@ class EncoderVarBinary { ARROW_DCHECK(!rows_const->metadata().is_fixed_length && !col_const->metadata().is_fixed_length); - const uint32_t* row_offsets_for_batch = rows_const->offsets() + start_row; - const uint32_t* col_offsets = col_const->offsets(); + const int32_t* row_offsets_for_batch = rows_const->offsets() + start_row; + const int32_t* col_offsets = col_const->offsets(); - uint32_t col_offset_next = col_offsets[0]; - for (uint32_t i = 0; i < num_rows; ++i) { - uint32_t col_offset = col_offset_next; + int32_t col_offset_next = col_offsets[0]; + for (int32_t i = 0; i < num_rows; ++i) { + int32_t col_offset = col_offset_next; col_offset_next = col_offsets[i + 1]; - uint32_t row_offset = row_offsets_for_batch[i]; + int32_t row_offset = row_offsets_for_batch[i]; const uint8_t* row = rows_const->data(2) + row_offset; - uint32_t offset_within_row; - uint32_t length; + int32_t offset_within_row; + int32_t length; if (first_varbinary_col) { rows_const->metadata().first_varbinary_offset_and_length(row, &offset_within_row, &length); diff --git a/cpp/src/arrow/compute/row/encode_internal_avx2.cc b/cpp/src/arrow/compute/row/encode_internal_avx2.cc index 50969c7bd6034..85f72914996da 100644 --- a/cpp/src/arrow/compute/row/encode_internal_avx2.cc +++ b/cpp/src/arrow/compute/row/encode_internal_avx2.cc @@ -23,7 +23,7 @@ namespace arrow { namespace compute { void EncoderBinary::DecodeHelper_avx2(bool is_row_fixed_length, uint32_t start_row, - uint32_t num_rows, uint32_t offset_within_row, + uint32_t num_rows, int32_t offset_within_row, const RowTableImpl& rows, KeyColumnArray* col) { if (is_row_fixed_length) { DecodeImp_avx2(start_row, num_rows, offset_within_row, rows, col); @@ -34,7 +34,7 @@ void EncoderBinary::DecodeHelper_avx2(bool is_row_fixed_length, uint32_t start_r template void EncoderBinary::DecodeImp_avx2(uint32_t start_row, uint32_t num_rows, - uint32_t offset_within_row, const RowTableImpl& rows, + int32_t offset_within_row, const RowTableImpl& rows, KeyColumnArray* col) { DecodeHelper( start_row, num_rows, offset_within_row, &rows, nullptr, col, col, @@ -49,10 +49,10 @@ void EncoderBinary::DecodeImp_avx2(uint32_t start_row, uint32_t num_rows, uint32_t EncoderBinaryPair::DecodeHelper_avx2( bool is_row_fixed_length, uint32_t col_width, uint32_t start_row, uint32_t num_rows, - uint32_t offset_within_row, const RowTableImpl& rows, KeyColumnArray* col1, + int32_t offset_within_row, const RowTableImpl& rows, KeyColumnArray* col1, KeyColumnArray* col2) { using DecodeImp_avx2_t = - uint32_t (*)(uint32_t start_row, uint32_t num_rows, uint32_t offset_within_row, + uint32_t (*)(uint32_t start_row, uint32_t num_rows, int32_t offset_within_row, const RowTableImpl& rows, KeyColumnArray* col1, KeyColumnArray* col2); static const DecodeImp_avx2_t DecodeImp_avx2_fn[] = { DecodeImp_avx2, DecodeImp_avx2, DecodeImp_avx2, @@ -66,7 +66,7 @@ uint32_t EncoderBinaryPair::DecodeHelper_avx2( template uint32_t EncoderBinaryPair::DecodeImp_avx2(uint32_t start_row, uint32_t num_rows, - uint32_t offset_within_row, + int32_t offset_within_row, const RowTableImpl& rows, KeyColumnArray* col1, KeyColumnArray* col2) { ARROW_DCHECK(col_width == 1 || col_width == 2 || col_width == 4 || col_width == 8); @@ -75,7 +75,7 @@ uint32_t EncoderBinaryPair::DecodeImp_avx2(uint32_t start_row, uint32_t num_rows uint8_t* col_vals_B = col2->mutable_data(1); uint32_t fixed_length = rows.metadata().fixed_length; - const uint32_t* offsets; + const int32_t* offsets; const uint8_t* src_base; if (is_row_fixed_length) { src_base = rows.data(1) + fixed_length * start_row + offset_within_row; @@ -99,7 +99,7 @@ uint32_t EncoderBinaryPair::DecodeImp_avx2(uint32_t start_row, uint32_t num_rows src2 = reinterpret_cast(src + fixed_length * 2); src3 = reinterpret_cast(src + fixed_length * 3); } else { - const uint32_t* row_offsets = offsets + i * unroll; + const int32_t* row_offsets = offsets + i * unroll; const uint8_t* src = src_base; src0 = reinterpret_cast(src + row_offsets[0]); src1 = reinterpret_cast(src + row_offsets[1]); @@ -140,7 +140,7 @@ uint32_t EncoderBinaryPair::DecodeImp_avx2(uint32_t start_row, uint32_t num_rows } } } else { - const uint32_t* row_offsets = offsets + i * unroll; + const int32_t* row_offsets = offsets + i * unroll; const uint8_t* src = src_base; for (int j = 0; j < unroll; ++j) { if (col_width == 1) { diff --git a/cpp/src/arrow/compute/row/row_internal.cc b/cpp/src/arrow/compute/row/row_internal.cc index f6a62c09fcf24..81d867076ecc9 100644 --- a/cpp/src/arrow/compute/row/row_internal.cc +++ b/cpp/src/arrow/compute/row/row_internal.cc @@ -22,8 +22,8 @@ namespace arrow { namespace compute { -uint32_t RowTableMetadata::num_varbinary_cols() const { - uint32_t result = 0; +int32_t RowTableMetadata::num_varbinary_cols() const { + int32_t result = 0; for (auto column_metadata : column_metadatas) { if (!column_metadata.is_fixed_length) { ++result; @@ -120,8 +120,8 @@ void RowTableMetadata::FromColumnMetadataVector( varbinary_end_array_offset = 0; column_offsets.resize(num_cols); - uint32_t num_varbinary_cols = 0; - uint32_t offset_within_row = 0; + int32_t num_varbinary_cols = 0; + int32_t offset_within_row = 0; for (uint32_t i = 0; i < num_cols; ++i) { const KeyColumnMetadata& col = cols[column_order[i]]; if (col.is_fixed_length && col.fixed_length != 0 && @@ -135,7 +135,7 @@ void RowTableMetadata::FromColumnMetadataVector( varbinary_end_array_offset = offset_within_row; } DCHECK(column_offsets[i] - varbinary_end_array_offset == - num_varbinary_cols * sizeof(uint32_t)); + num_varbinary_cols * static_cast(sizeof(int32_t))); ++num_varbinary_cols; offset_within_row += sizeof(uint32_t); } else { @@ -189,7 +189,7 @@ Status RowTableImpl::Init(MemoryPool* pool, const RowTableMetadata& metadata) { auto offsets, AllocateResizableBuffer(size_offsets(kInitialRowsCapacity), pool_)); offsets_ = std::move(offsets); memset(offsets_->mutable_data(), 0, size_offsets(kInitialRowsCapacity)); - reinterpret_cast(offsets_->mutable_data())[0] = 0; + reinterpret_cast(offsets_->mutable_data())[0] = 0; ARROW_ASSIGN_OR_RAISE( auto rows, @@ -224,7 +224,7 @@ void RowTableImpl::Clean() { has_any_nulls_ = false; if (!metadata_.is_fixed_length) { - reinterpret_cast(offsets_->mutable_data())[0] = 0; + reinterpret_cast(offsets_->mutable_data())[0] = 0; } } @@ -314,7 +314,7 @@ Status RowTableImpl::ResizeOptionalVaryingLengthBuffer(int64_t num_extra_bytes) } Status RowTableImpl::AppendSelectionFrom(const RowTableImpl& from, - uint32_t num_rows_to_append, + int32_t num_rows_to_append, const uint16_t* source_row_ids) { DCHECK(metadata_.is_compatible(from.metadata())); @@ -322,13 +322,13 @@ Status RowTableImpl::AppendSelectionFrom(const RowTableImpl& from, if (!metadata_.is_fixed_length) { // Varying-length rows - auto from_offsets = reinterpret_cast(from.offsets_->data()); - auto to_offsets = reinterpret_cast(offsets_->mutable_data()); - uint32_t total_length = to_offsets[num_rows_]; - uint32_t total_length_to_append = 0; - for (uint32_t i = 0; i < num_rows_to_append; ++i) { + auto from_offsets = reinterpret_cast(from.offsets_->data()); + auto to_offsets = reinterpret_cast(offsets_->mutable_data()); + int32_t total_length = to_offsets[num_rows_]; + int32_t total_length_to_append = 0; + for (int32_t i = 0; i < num_rows_to_append; ++i) { uint16_t row_id = source_row_ids ? source_row_ids[i] : i; - uint32_t length = from_offsets[row_id + 1] - from_offsets[row_id]; + int32_t length = from_offsets[row_id + 1] - from_offsets[row_id]; total_length_to_append += length; to_offsets[num_rows_ + i + 1] = total_length + total_length_to_append; } @@ -337,9 +337,9 @@ Status RowTableImpl::AppendSelectionFrom(const RowTableImpl& from, const uint8_t* src = from.rows_->data(); uint8_t* dst = rows_->mutable_data() + total_length; - for (uint32_t i = 0; i < num_rows_to_append; ++i) { + for (int32_t i = 0; i < num_rows_to_append; ++i) { uint16_t row_id = source_row_ids ? source_row_ids[i] : i; - uint32_t length = from_offsets[row_id + 1] - from_offsets[row_id]; + int32_t length = from_offsets[row_id + 1] - from_offsets[row_id]; auto src64 = reinterpret_cast(src + from_offsets[row_id]); auto dst64 = reinterpret_cast(dst); for (uint32_t j = 0; j < bit_util::CeilDiv(length, 8); ++j) { @@ -351,7 +351,7 @@ Status RowTableImpl::AppendSelectionFrom(const RowTableImpl& from, // Fixed-length rows const uint8_t* src = from.rows_->data(); uint8_t* dst = rows_->mutable_data() + num_rows_ * metadata_.fixed_length; - for (uint32_t i = 0; i < num_rows_to_append; ++i) { + for (int32_t i = 0; i < num_rows_to_append; ++i) { uint16_t row_id = source_row_ids ? source_row_ids[i] : i; uint32_t length = metadata_.fixed_length; auto src64 = reinterpret_cast(src + length * row_id); @@ -368,7 +368,7 @@ Status RowTableImpl::AppendSelectionFrom(const RowTableImpl& from, uint64_t dst_byte_offset = num_rows_ * byte_length; const uint8_t* src_base = from.null_masks_->data(); uint8_t* dst_base = null_masks_->mutable_data(); - for (uint32_t i = 0; i < num_rows_to_append; ++i) { + for (int32_t i = 0; i < num_rows_to_append; ++i) { uint32_t row_id = source_row_ids ? source_row_ids[i] : i; int64_t src_byte_offset = row_id * byte_length; const uint8_t* src = src_base + src_byte_offset; @@ -384,8 +384,8 @@ Status RowTableImpl::AppendSelectionFrom(const RowTableImpl& from, return Status::OK(); } -Status RowTableImpl::AppendEmpty(uint32_t num_rows_to_append, - uint32_t num_extra_bytes_to_append) { +Status RowTableImpl::AppendEmpty(int32_t num_rows_to_append, + int32_t num_extra_bytes_to_append) { RETURN_NOT_OK(ResizeFixedLengthBuffers(num_rows_to_append)); RETURN_NOT_OK(ResizeOptionalVaryingLengthBuffer(num_extra_bytes_to_append)); num_rows_ += num_rows_to_append; diff --git a/cpp/src/arrow/compute/row/row_internal.h b/cpp/src/arrow/compute/row/row_internal.h index 3220b7ffe6e40..95c2be233c9ae 100644 --- a/cpp/src/arrow/compute/row/row_internal.h +++ b/cpp/src/arrow/compute/row/row_internal.h @@ -39,7 +39,7 @@ struct ARROW_EXPORT RowTableMetadata { /// For a varying-length binary, size of all encoded fixed-length key columns, /// including lengths of varying-length columns, rounded up to the multiple of string /// alignment. - uint32_t fixed_length; + int32_t fixed_length; /// Offset within a row to the array of 32-bit offsets within a row of /// ends of varbinary fields. @@ -52,7 +52,7 @@ struct ARROW_EXPORT RowTableMetadata { /// to obtain the beginning of the next varbinary field. /// The first varbinary field starts at offset specified by fixed_length, /// which should already be aligned. - uint32_t varbinary_end_array_offset; + int32_t varbinary_end_array_offset; /// Fixed number of bytes per row that are used to encode null masks. /// Null masks indicate for a single row which of its columns are null. @@ -76,20 +76,20 @@ struct ARROW_EXPORT RowTableMetadata { std::vector inverse_column_order; /// Offsets within a row to fields in their encoding order. - std::vector column_offsets; + std::vector column_offsets; /// Rounding up offset to the nearest multiple of alignment value. /// Alignment must be a power of 2. - static inline uint32_t padding_for_alignment(uint32_t offset, int required_alignment) { + static inline int32_t padding_for_alignment(int32_t offset, int required_alignment) { ARROW_DCHECK(ARROW_POPCOUNT64(required_alignment) == 1); - return static_cast((-static_cast(offset)) & - (required_alignment - 1)); + return static_cast((-static_cast(offset)) & + (required_alignment - 1)); } /// Rounding up offset to the beginning of next column, /// choosing required alignment based on the data type of that column. - static inline uint32_t padding_for_alignment(uint32_t offset, int string_alignment, - const KeyColumnMetadata& col_metadata) { + static inline int32_t padding_for_alignment(int32_t offset, int string_alignment, + const KeyColumnMetadata& col_metadata) { if (!col_metadata.is_fixed_length || ARROW_POPCOUNT64(col_metadata.fixed_length) <= 1) { return 0; @@ -99,20 +99,20 @@ struct ARROW_EXPORT RowTableMetadata { } /// Returns an array of offsets within a row of ends of varbinary fields. - inline const uint32_t* varbinary_end_array(const uint8_t* row) const { + inline const int32_t* varbinary_end_array(const uint8_t* row) const { ARROW_DCHECK(!is_fixed_length); - return reinterpret_cast(row + varbinary_end_array_offset); + return reinterpret_cast(row + varbinary_end_array_offset); } /// \brief An array of mutable offsets within a row of ends of varbinary fields. - inline uint32_t* varbinary_end_array(uint8_t* row) const { + inline int32_t* varbinary_end_array(uint8_t* row) const { ARROW_DCHECK(!is_fixed_length); - return reinterpret_cast(row + varbinary_end_array_offset); + return reinterpret_cast(row + varbinary_end_array_offset); } /// Returns the offset within the row and length of the first varbinary field. - inline void first_varbinary_offset_and_length(const uint8_t* row, uint32_t* offset, - uint32_t* length) const { + inline void first_varbinary_offset_and_length(const uint8_t* row, int32_t* offset, + int32_t* length) const { ARROW_DCHECK(!is_fixed_length); *offset = fixed_length; *length = varbinary_end_array(row)[0] - fixed_length; @@ -121,12 +121,12 @@ struct ARROW_EXPORT RowTableMetadata { /// Returns the offset within the row and length of the second and further varbinary /// fields. inline void nth_varbinary_offset_and_length(const uint8_t* row, int varbinary_id, - uint32_t* out_offset, - uint32_t* out_length) const { + int32_t* out_offset, + int32_t* out_length) const { ARROW_DCHECK(!is_fixed_length); ARROW_DCHECK(varbinary_id > 0); - const uint32_t* varbinary_end = varbinary_end_array(row); - uint32_t offset = varbinary_end[varbinary_id - 1]; + const int32_t* varbinary_end = varbinary_end_array(row); + int32_t offset = varbinary_end[varbinary_id - 1]; offset += padding_for_alignment(offset, string_alignment); *out_offset = offset; *out_length = varbinary_end[varbinary_id] - offset; @@ -136,11 +136,11 @@ struct ARROW_EXPORT RowTableMetadata { uint32_t pos_after_encoding(uint32_t icol) const { return inverse_column_order[icol]; } - uint32_t encoded_field_offset(uint32_t icol) const { return column_offsets[icol]; } + int32_t encoded_field_offset(uint32_t icol) const { return column_offsets[icol]; } - uint32_t num_cols() const { return static_cast(column_metadatas.size()); } + int32_t num_cols() const { return static_cast(column_metadatas.size()); } - uint32_t num_varbinary_cols() const; + int32_t num_varbinary_cols() const; /// \brief Populate this instance to describe `cols` with the given alignment void FromColumnMetadataVector(const std::vector& cols, @@ -175,12 +175,12 @@ class ARROW_EXPORT RowTableImpl { /// \param num_extra_bytes_to_append For tables storing variable-length data this /// should be a guess of how many data bytes will be needed to populate the /// data. This is ignored if there are no variable-length columns - Status AppendEmpty(uint32_t num_rows_to_append, uint32_t num_extra_bytes_to_append); + Status AppendEmpty(int32_t num_rows_to_append, int32_t num_extra_bytes_to_append); /// \brief Append rows from a source table /// \param from The table to append from /// \param num_rows_to_append The number of rows to append /// \param source_row_ids Indices (into `from`) of the desired rows - Status AppendSelectionFrom(const RowTableImpl& from, uint32_t num_rows_to_append, + Status AppendSelectionFrom(const RowTableImpl& from, int32_t num_rows_to_append, const uint16_t* source_row_ids); /// \brief Metadata describing the data stored in this table const RowTableMetadata& metadata() const { return metadata_; } @@ -195,8 +195,8 @@ class ARROW_EXPORT RowTableImpl { ARROW_DCHECK(i >= 0 && i < kMaxBuffers); return buffers_[i]; } - const uint32_t* offsets() const { return reinterpret_cast(data(1)); } - uint32_t* mutable_offsets() { return reinterpret_cast(mutable_data(1)); } + const int32_t* offsets() const { return reinterpret_cast(data(1)); } + int32_t* mutable_offsets() { return reinterpret_cast(mutable_data(1)); } const uint8_t* null_masks() const { return null_masks_->data(); } uint8_t* null_masks() { return null_masks_->mutable_data(); } diff --git a/cpp/src/arrow/compute/util.h b/cpp/src/arrow/compute/util.h index 88dce160ce936..9be4e071c48de 100644 --- a/cpp/src/arrow/compute/util.h +++ b/cpp/src/arrow/compute/util.h @@ -269,7 +269,7 @@ class TailSkipForSIMD { return num_rows_safe; } static int64_t FixVarBinaryAccess(int num_bytes_accessed_together, int64_t num_rows, - const uint32_t* offsets) { + const int32_t* offsets) { // Do not process rows that could read past the end of the buffer using N // byte loads/stores. //