From 1b4d0c310e8b753f280362969b3fccfd741a0234 Mon Sep 17 00:00:00 2001 From: Matt Topol Date: Mon, 13 Jan 2025 04:59:51 -0500 Subject: [PATCH 01/17] GH-45180: [C++][Fuzzing] Fix Negation bug discovered by fuzzing (#45181) ### Rationale for this change If the value for Decimal32 or Decimal64 is `INT32_MIN` or `INT64_MIN` respectively, then UBSAN reports an issue when calling Negate on them due to overflow. ### What changes are included in this PR? Have the `Negate` methods of Decimal32 and Decimal64 use `arrow::internal::SafeSignedNegate`. ### Are these changes tested? Unit tests were added for both cases which were able to reproduce the problem when UBSAN was on without the fix. ### Are there any user-facing changes? No. * OSS-Fuzz issue: https://issues.oss-fuzz.com/issues/371239168 * GitHub Issue: #45180 Authored-by: Matt Topol Signed-off-by: Antoine Pitrou --- cpp/src/arrow/util/basic_decimal.cc | 16 ++++++++++++++++ cpp/src/arrow/util/basic_decimal.h | 10 ++-------- cpp/src/arrow/util/decimal_test.cc | 22 ++++++++++++++++++++++ testing | 2 +- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/cpp/src/arrow/util/basic_decimal.cc b/cpp/src/arrow/util/basic_decimal.cc index 22db1e705190..e82078055f33 100644 --- a/cpp/src/arrow/util/basic_decimal.cc +++ b/cpp/src/arrow/util/basic_decimal.cc @@ -50,6 +50,11 @@ static constexpr uint64_t kInt64Mask = 0xFFFFFFFFFFFFFFFF; static constexpr uint64_t kInt32Mask = 0xFFFFFFFF; #endif +BasicDecimal32& BasicDecimal32::Negate() { + value_ = arrow::internal::SafeSignedNegate(value_); + return *this; +} + DecimalStatus BasicDecimal32::Divide(const BasicDecimal32& divisor, BasicDecimal32* result, BasicDecimal32* remainder) const { @@ -152,6 +157,11 @@ BasicDecimal32::operator BasicDecimal64() const { return BasicDecimal64(static_cast(value())); } +BasicDecimal64& BasicDecimal64::Negate() { + value_ = arrow::internal::SafeSignedNegate(value_); + return *this; +} + DecimalStatus BasicDecimal64::Divide(const BasicDecimal64& divisor, BasicDecimal64* result, BasicDecimal64* remainder) const { @@ -253,12 +263,18 @@ const BasicDecimal64& BasicDecimal64::GetHalfScaleMultiplier(int32_t scale) { bool BasicDecimal32::FitsInPrecision(int32_t precision) const { DCHECK_GE(precision, 0); DCHECK_LE(precision, kMaxPrecision); + if (value_ == INT32_MIN) { + return false; + } return Abs(*this) < DecimalTraits::powers_of_ten()[precision]; } bool BasicDecimal64::FitsInPrecision(int32_t precision) const { DCHECK_GE(precision, 0); DCHECK_LE(precision, kMaxPrecision); + if (value_ == INT64_MIN) { + return false; + } return Abs(*this) < DecimalTraits::powers_of_ten()[precision]; } diff --git a/cpp/src/arrow/util/basic_decimal.h b/cpp/src/arrow/util/basic_decimal.h index b5404bb7bc6d..638c4870f1de 100644 --- a/cpp/src/arrow/util/basic_decimal.h +++ b/cpp/src/arrow/util/basic_decimal.h @@ -276,10 +276,7 @@ class ARROW_EXPORT BasicDecimal32 : public SmallBasicDecimal { using ValueType = int32_t; /// \brief Negate the current value (in-place) - BasicDecimal32& Negate() { - value_ = -value_; - return *this; - } + BasicDecimal32& Negate(); /// \brief Absolute value (in-place) BasicDecimal32& Abs() { return *this < 0 ? Negate() : *this; } @@ -429,10 +426,7 @@ class ARROW_EXPORT BasicDecimal64 : public SmallBasicDecimal { using ValueType = int64_t; /// \brief Negate the current value (in-place) - BasicDecimal64& Negate() { - value_ = -value_; - return *this; - } + BasicDecimal64& Negate(); /// \brief Absolute value (in-place) BasicDecimal64& Abs() { return *this < 0 ? Negate() : *this; } diff --git a/cpp/src/arrow/util/decimal_test.cc b/cpp/src/arrow/util/decimal_test.cc index d2f8ae3b7aad..e0aa0b2b85a4 100644 --- a/cpp/src/arrow/util/decimal_test.cc +++ b/cpp/src/arrow/util/decimal_test.cc @@ -219,6 +219,28 @@ class DecimalFromStringTest : public ::testing::Test { } }; +TEST(Decimal32Test, TestIntMinNegate) { + Decimal32 d(INT32_MIN); + auto neg = d.Negate(); + ASSERT_EQ(neg, Decimal32(arrow::internal::SafeSignedNegate(INT32_MIN))); +} + +TEST(Decimal32Test, TestIntMinFitsPrecision) { + Decimal32 d(INT32_MIN); + ASSERT_FALSE(d.FitsInPrecision(9)); +} + +TEST(Decimal64Test, TestIntMinNegate) { + Decimal64 d(INT64_MIN); + auto neg = d.Negate(); + ASSERT_EQ(neg, Decimal64(arrow::internal::SafeSignedNegate(INT64_MIN))); +} + +TEST(Decimal64Test, TestIntMinFitsPrecision) { + Decimal64 d(INT64_MIN); + ASSERT_FALSE(d.FitsInPrecision(18)); +} + TYPED_TEST_SUITE(DecimalFromStringTest, DecimalTypes); TYPED_TEST(DecimalFromStringTest, Basics) { this->TestBasics(); } diff --git a/testing b/testing index 4d209492d514..d2a137123034 160000 --- a/testing +++ b/testing @@ -1 +1 @@ -Subproject commit 4d209492d514c2d3cb2d392681b9aa00e6d8da1c +Subproject commit d2a13712303498963395318a4eb42872e66aead7 From 16a0408375e1af98b30d3348c28404a05d302e3e Mon Sep 17 00:00:00 2001 From: Ian Cook Date: Mon, 13 Jan 2025 09:23:45 -0500 Subject: [PATCH 02/17] GH-45230: [Docs] Add LinkedIn social link and fix top nav scaling problems (#45228) This adds a LinkedIn icon social link to the main docs pages and fixes the layout of the top nav, which previously looked bad at widths between 960px and 1200px. * GitHub Issue: #45230 --- docs/source/_static/theme_overrides.css | 35 +++++++++++++++++++++++-- docs/source/conf.py | 6 +++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/docs/source/_static/theme_overrides.css b/docs/source/_static/theme_overrides.css index f7f25269a661..55403b2ed019 100644 --- a/docs/source/_static/theme_overrides.css +++ b/docs/source/_static/theme_overrides.css @@ -25,14 +25,39 @@ --pst-font-weight-heading: 600; } -/* Change header hight to make the logo a bit larger */ +/* Change header height to make the logo a bit larger */ /* only on wider screens */ -@media only screen and (min-width: 1170px){ + +@media only screen and (min-width: 1200px) { :root { --pst-header-height: 6rem; } } +/* Adjust layout of nav to fit narrower screens */ + +@media only screen and (max-width: 1199px) { + + /* Condense link text in nav to preserve layout */ + .navbar-header-items__center a.nav-link:not(.dropdown-item), + .navbar-header-items__center button.nav-item { + letter-spacing: -0.02em; + } + + /* Shrink search button */ + .search-button__default-text, + .search-button__kbd-shortcut { + display:none !important; + } + + /* Reduce horizontal space between icons in nav and sidebar */ + div.sidebar-header-items__end, + div.navbar-header-items__end, + ul.navbar-icon-links { + column-gap: 0.75rem !important; + } +} + /* Contributing landing page overview cards */ .contrib-card { @@ -84,3 +109,9 @@ dl.cpp.enumerator { p.breathe-sectiondef-title { margin-top: 1rem; } + +/* Keep social icons arranged horizontally in sidebar */ + +.sidebar-header-items__end { + flex-wrap: wrap; +} diff --git a/docs/source/conf.py b/docs/source/conf.py index 9b60c4180c68..e9b926e884a4 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -342,6 +342,7 @@ }, "header_links_before_dropdown": 2, "header_dropdown_text": "Implementations", + "navbar_align": "left", "navbar_end": ["version-switcher", "theme-switcher", "navbar-icon-links"], "icon_links": [ { @@ -349,6 +350,11 @@ "url": "https://github.com/apache/arrow", "icon": "fa-brands fa-square-github", }, + { + "name": "LinkedIn", + "url": "https://www.linkedin.com/company/apache-arrow/", + "icon": "fa-brands fa-linkedin", + }, { "name": "X", "url": "https://twitter.com/ApacheArrow", From d7385e4c6dd60be8c0eed8416408dfe89e21b96e Mon Sep 17 00:00:00 2001 From: Rossi Sun Date: Mon, 13 Jan 2025 22:29:50 +0800 Subject: [PATCH 03/17] GH-44513: [C++] Fix overflow issues for large build side in swiss join (#45108) ### Rationale for this change #44513 triggers two distinct overflow issues within swiss join, both happening when the build side table contains large enough number of rows or distinct keys. (Cases at this extent of hash join build side are rather rare, so we haven't seen them reported until now): 1. The first issue is, our swiss table implementation takes the higher `N` bits of 32-bit hash value as the index to a buffer storing "block"s (a block contains `8` key - in some code also referred to as "group" - ids). This `N`-bit number is further multiplied by the size of a block, which is also related to `N`. The `N` in the case of #44513 is `26` and a block takes `40` bytes. So the multiply is possible to produce a number over `1 << 31` (negative when interpreted as signed 32bit). In our AVX2 specialization of accessing the block buffer https://github.com/apache/arrow/blob/0a00e25f2f6fb927fb555b69038d0be9b9d9f265/cpp/src/arrow/compute/key_map_internal_avx2.cc#L404 , the issue like https://github.com/apache/arrow/issues/41813#issuecomment-2168286330 shows up. This is the actual issue that directly produced the segfault in #44513. 2. The other issue is, we take `7` bits of the 32-bit hash value after `N` as a "stamp" (to quick fail the hash comparison). But when `N` is greater than `25`, some arithmetic code like https://github.com/apache/arrow/blob/0a00e25f2f6fb927fb555b69038d0be9b9d9f265/cpp/src/arrow/compute/key_map_internal.cc#L397 (`bits_hash_` is `constexpr 32`, `log_blocks_` is `N`, `bits_stamp_` is `constexpr 7`, this is to retrieve the stamp from a hash) produces `hash >> -1` aka `hash >> 0xFFFFFFFF` aka `hash >> 31` (the heading `1`s are trimmed) then the stamp value is wrong and results in false-mismatched rows. This is the reason of my false positive run in https://github.com/apache/arrow/issues/44513#issuecomment-2556438531 . ### What changes are included in this PR? For issue 1, use 64-bit index gather intrinsic to avoid the offset overflow. For issue 2, do not right-shift the hash if `N + 7 >= 32`. This is actually allowing the bits overlapping between block id (the `N` bits) and stamp (the `7` bits). Though this may introduce more false-positive hash comparisons (thus worsen the performance), I think this is still more reasonable than brutally failing for `N > 25`. I introduce two members `bits_shift_for_block_and_stamp_` and `bits_shift_for_block_`, which are derived from `log_blocks_` - esp. set to `0` and `32 - N` when `N + 7 >= 32`, this is to avoid branching like `if (log_blocks_ + bits_stamp_ > bits_hash_)` in tight loops. ### Are these changes tested? The fix is manually tested with the original case in my local. (I do have a concrete C++ UT to verify the fix but it requires too much resource and runs for too long time so it is impractical to run in any reasonable CI environment.) ### Are there any user-facing changes? None. * GitHub Issue: #44513 Lead-authored-by: Rossi Sun Co-authored-by: Antoine Pitrou Signed-off-by: Rossi Sun --- cpp/src/arrow/compute/key_map_internal.cc | 21 ++++--- cpp/src/arrow/compute/key_map_internal.h | 25 ++++++++- .../arrow/compute/key_map_internal_avx2.cc | 55 +++++++++++-------- 3 files changed, 69 insertions(+), 32 deletions(-) diff --git a/cpp/src/arrow/compute/key_map_internal.cc b/cpp/src/arrow/compute/key_map_internal.cc index f134c9145535..ad264533bff3 100644 --- a/cpp/src/arrow/compute/key_map_internal.cc +++ b/cpp/src/arrow/compute/key_map_internal.cc @@ -254,9 +254,9 @@ void SwissTable::early_filter_imp(const int num_keys, const uint32_t* hashes, // Extract from hash: block index and stamp // uint32_t hash = hashes[i]; - uint32_t iblock = hash >> (bits_hash_ - bits_stamp_ - log_blocks_); + uint32_t iblock = hash >> bits_shift_for_block_and_stamp_; uint32_t stamp = iblock & stamp_mask; - iblock >>= bits_stamp_; + iblock >>= bits_shift_for_block_; uint32_t num_block_bytes = num_groupid_bits + 8; const uint8_t* blockbase = @@ -399,7 +399,7 @@ bool SwissTable::find_next_stamp_match(const uint32_t hash, const uint32_t in_sl const uint64_t num_groupid_bits = num_groupid_bits_from_log_blocks(log_blocks_); constexpr uint64_t stamp_mask = 0x7f; const int stamp = - static_cast((hash >> (bits_hash_ - log_blocks_ - bits_stamp_)) & stamp_mask); + static_cast((hash >> bits_shift_for_block_and_stamp_) & stamp_mask); uint64_t start_slot_id = wrap_global_slot_id(in_slot_id); int match_found; int local_slot; @@ -659,6 +659,9 @@ Status SwissTable::grow_double() { int num_group_id_bits_after = num_groupid_bits_from_log_blocks(log_blocks_ + 1); uint64_t group_id_mask_before = ~0ULL >> (64 - num_group_id_bits_before); int log_blocks_after = log_blocks_ + 1; + int bits_shift_for_block_and_stamp_after = + ComputeBitsShiftForBlockAndStamp(log_blocks_after); + int bits_shift_for_block_after = ComputeBitsShiftForBlock(log_blocks_after); uint64_t block_size_before = (8 + num_group_id_bits_before); uint64_t block_size_after = (8 + num_group_id_bits_after); uint64_t block_size_total_after = (block_size_after << log_blocks_after) + padding_; @@ -701,8 +704,7 @@ Status SwissTable::grow_double() { } int ihalf = block_id_new & 1; - uint8_t stamp_new = - hash >> ((bits_hash_ - log_blocks_after - bits_stamp_)) & stamp_mask; + uint8_t stamp_new = (hash >> bits_shift_for_block_and_stamp_after) & stamp_mask; uint64_t group_id_bit_offs = j * num_group_id_bits_before; uint64_t group_id = (util::SafeLoadAs(block_base + 8 + (group_id_bit_offs >> 3)) >> @@ -744,8 +746,7 @@ Status SwissTable::grow_double() { (util::SafeLoadAs(block_base + 8 + (group_id_bit_offs >> 3)) >> (group_id_bit_offs & 7)) & group_id_mask_before; - uint8_t stamp_new = - hash >> ((bits_hash_ - log_blocks_after - bits_stamp_)) & stamp_mask; + uint8_t stamp_new = (hash >> bits_shift_for_block_and_stamp_after) & stamp_mask; uint8_t* block_base_new = blocks_new->mutable_data() + block_id_new * block_size_after; @@ -773,6 +774,8 @@ Status SwissTable::grow_double() { blocks_ = std::move(blocks_new); hashes_ = std::move(hashes_new_buffer); log_blocks_ = log_blocks_after; + bits_shift_for_block_and_stamp_ = bits_shift_for_block_and_stamp_after; + bits_shift_for_block_ = bits_shift_for_block_after; return Status::OK(); } @@ -784,6 +787,8 @@ Status SwissTable::init(int64_t hardware_flags, MemoryPool* pool, int log_blocks log_minibatch_ = util::MiniBatch::kLogMiniBatchLength; log_blocks_ = log_blocks; + bits_shift_for_block_and_stamp_ = ComputeBitsShiftForBlockAndStamp(log_blocks_); + bits_shift_for_block_ = ComputeBitsShiftForBlock(log_blocks_); int num_groupid_bits = num_groupid_bits_from_log_blocks(log_blocks_); num_inserted_ = 0; @@ -820,6 +825,8 @@ void SwissTable::cleanup() { hashes_ = nullptr; } log_blocks_ = 0; + bits_shift_for_block_and_stamp_ = ComputeBitsShiftForBlockAndStamp(log_blocks_); + bits_shift_for_block_ = ComputeBitsShiftForBlock(log_blocks_); num_inserted_ = 0; } diff --git a/cpp/src/arrow/compute/key_map_internal.h b/cpp/src/arrow/compute/key_map_internal.h index a5e784a9e446..66a9957006dd 100644 --- a/cpp/src/arrow/compute/key_map_internal.h +++ b/cpp/src/arrow/compute/key_map_internal.h @@ -203,6 +203,23 @@ class ARROW_EXPORT SwissTable { // Resize large hash tables when 75% full. Status grow_double(); + // When log_blocks is greater than 25, there will be overlapping bits between block id + // and stamp within a 32-bit hash value. So we must check if this is the case when + // right shifting a hash value to retrieve block id and stamp. The following two + // functions derive the number of bits to right shift from the given log_blocks. + static int ComputeBitsShiftForBlockAndStamp(int log_blocks) { + if (ARROW_PREDICT_FALSE(log_blocks + bits_stamp_ > bits_hash_)) { + return 0; + } + return bits_hash_ - log_blocks - bits_stamp_; + } + static int ComputeBitsShiftForBlock(int log_blocks) { + if (ARROW_PREDICT_FALSE(log_blocks + bits_stamp_ > bits_hash_)) { + return bits_hash_ - log_blocks; + } + return bits_stamp_; + } + // Number of hash bits stored in slots in a block. // The highest bits of hash determine block id. // The next set of highest bits is a "stamp" stored in a slot in a block. @@ -214,6 +231,11 @@ class ARROW_EXPORT SwissTable { int log_minibatch_; // Base 2 log of the number of blocks int log_blocks_ = 0; + // The following two variables are derived from log_blocks_ as log_blocks_ changes, and + // used in tight loops to avoid calling the ComputeXXX functions (introducing a + // branching on whether log_blocks_ + bits_stamp_ > bits_hash_). + int bits_shift_for_block_and_stamp_ = ComputeBitsShiftForBlockAndStamp(log_blocks_); + int bits_shift_for_block_ = ComputeBitsShiftForBlock(log_blocks_); // Number of keys inserted into hash table uint32_t num_inserted_ = 0; @@ -271,8 +293,7 @@ void SwissTable::insert_into_empty_slot(uint32_t slot_id, uint32_t hash, constexpr uint64_t stamp_mask = 0x7f; int start_slot = (slot_id & 7); - int stamp = - static_cast((hash >> (bits_hash_ - log_blocks_ - bits_stamp_)) & stamp_mask); + int stamp = static_cast((hash >> bits_shift_for_block_and_stamp_) & stamp_mask); uint64_t block_id = slot_id >> 3; uint8_t* blockbase = blocks_->mutable_data() + num_block_bytes * block_id; diff --git a/cpp/src/arrow/compute/key_map_internal_avx2.cc b/cpp/src/arrow/compute/key_map_internal_avx2.cc index 1a16603a0faa..be54f7de6397 100644 --- a/cpp/src/arrow/compute/key_map_internal_avx2.cc +++ b/cpp/src/arrow/compute/key_map_internal_avx2.cc @@ -45,10 +45,9 @@ int SwissTable::early_filter_imp_avx2_x8(const int num_hashes, const uint32_t* h // Calculate block index and hash stamp for a byte in a block // __m256i vhash = _mm256_loadu_si256(vhash_ptr + i); - __m256i vblock_id = _mm256_srlv_epi32( - vhash, _mm256_set1_epi32(bits_hash_ - bits_stamp_ - log_blocks_)); + __m256i vblock_id = _mm256_srli_epi32(vhash, bits_shift_for_block_and_stamp_); __m256i vstamp = _mm256_and_si256(vblock_id, vstamp_mask); - vblock_id = _mm256_srli_epi32(vblock_id, bits_stamp_); + vblock_id = _mm256_srli_epi32(vblock_id, bits_shift_for_block_); // We now split inputs and process 4 at a time, // in order to process 64-bit blocks @@ -301,19 +300,15 @@ int SwissTable::early_filter_imp_avx2_x32(const int num_hashes, const uint32_t* _mm256_and_si256(vhash2, _mm256_set1_epi32(0xffff0000))); vhash1 = _mm256_or_si256(_mm256_srli_epi32(vhash1, 16), _mm256_and_si256(vhash3, _mm256_set1_epi32(0xffff0000))); - __m256i vstamp_A = _mm256_and_si256( - _mm256_srlv_epi32(vhash0, _mm256_set1_epi32(16 - log_blocks_ - 7)), - _mm256_set1_epi16(0x7f)); - __m256i vstamp_B = _mm256_and_si256( - _mm256_srlv_epi32(vhash1, _mm256_set1_epi32(16 - log_blocks_ - 7)), - _mm256_set1_epi16(0x7f)); + __m256i vstamp_A = _mm256_and_si256(_mm256_srli_epi32(vhash0, 16 - log_blocks_ - 7), + _mm256_set1_epi16(0x7f)); + __m256i vstamp_B = _mm256_and_si256(_mm256_srli_epi32(vhash1, 16 - log_blocks_ - 7), + _mm256_set1_epi16(0x7f)); __m256i vstamp = _mm256_or_si256(vstamp_A, _mm256_slli_epi16(vstamp_B, 8)); - __m256i vblock_id_A = - _mm256_and_si256(_mm256_srlv_epi32(vhash0, _mm256_set1_epi32(16 - log_blocks_)), - _mm256_set1_epi16(block_id_mask)); - __m256i vblock_id_B = - _mm256_and_si256(_mm256_srlv_epi32(vhash1, _mm256_set1_epi32(16 - log_blocks_)), - _mm256_set1_epi16(block_id_mask)); + __m256i vblock_id_A = _mm256_and_si256(_mm256_srli_epi32(vhash0, 16 - log_blocks_), + _mm256_set1_epi16(block_id_mask)); + __m256i vblock_id_B = _mm256_and_si256(_mm256_srli_epi32(vhash1, 16 - log_blocks_), + _mm256_set1_epi16(block_id_mask)); __m256i vblock_id = _mm256_or_si256(vblock_id_A, _mm256_slli_epi16(vblock_id_B, 8)); // Visit all block bytes in reverse order (overwriting data on multiple matches) @@ -392,16 +387,30 @@ int SwissTable::extract_group_ids_avx2(const int num_keys, const uint32_t* hashe } else { for (int i = 0; i < num_keys / unroll; ++i) { __m256i hash = _mm256_loadu_si256(reinterpret_cast(hashes) + i); + // Extend hash and local_slot to 64-bit to compute 64-bit group id offsets to + // gather from. This is to prevent index overflow issues in GH-44513. + // NB: Use zero-extend conversion for unsigned hash. + __m256i hash_lo = _mm256_cvtepu32_epi64(_mm256_castsi256_si128(hash)); + __m256i hash_hi = _mm256_cvtepu32_epi64(_mm256_extracti128_si256(hash, 1)); __m256i local_slot = _mm256_set1_epi64x(reinterpret_cast(local_slots)[i]); - local_slot = _mm256_shuffle_epi8( - local_slot, _mm256_setr_epi32(0x80808000, 0x80808001, 0x80808002, 0x80808003, - 0x80808004, 0x80808005, 0x80808006, 0x80808007)); - local_slot = _mm256_mullo_epi32(local_slot, _mm256_set1_epi32(byte_size)); - __m256i pos = _mm256_srlv_epi32(hash, _mm256_set1_epi32(bits_hash_ - log_blocks_)); - pos = _mm256_mullo_epi32(pos, _mm256_set1_epi32(byte_multiplier)); - pos = _mm256_add_epi32(pos, local_slot); - __m256i group_id = _mm256_i32gather_epi32(elements, pos, 1); + __m256i local_slot_lo = _mm256_shuffle_epi8( + local_slot, _mm256_setr_epi32(0x80808000, 0x80808080, 0x80808001, 0x80808080, + 0x80808002, 0x80808080, 0x80808003, 0x80808080)); + __m256i local_slot_hi = _mm256_shuffle_epi8( + local_slot, _mm256_setr_epi32(0x80808004, 0x80808080, 0x80808005, 0x80808080, + 0x80808006, 0x80808080, 0x80808007, 0x80808080)); + local_slot_lo = _mm256_mul_epu32(local_slot_lo, _mm256_set1_epi32(byte_size)); + local_slot_hi = _mm256_mul_epu32(local_slot_hi, _mm256_set1_epi32(byte_size)); + __m256i pos_lo = _mm256_srli_epi64(hash_lo, bits_hash_ - log_blocks_); + __m256i pos_hi = _mm256_srli_epi64(hash_hi, bits_hash_ - log_blocks_); + pos_lo = _mm256_mul_epu32(pos_lo, _mm256_set1_epi32(byte_multiplier)); + pos_hi = _mm256_mul_epu32(pos_hi, _mm256_set1_epi32(byte_multiplier)); + pos_lo = _mm256_add_epi64(pos_lo, local_slot_lo); + pos_hi = _mm256_add_epi64(pos_hi, local_slot_hi); + __m128i group_id_lo = _mm256_i64gather_epi32(elements, pos_lo, 1); + __m128i group_id_hi = _mm256_i64gather_epi32(elements, pos_hi, 1); + __m256i group_id = _mm256_set_m128i(group_id_hi, group_id_lo); group_id = _mm256_and_si256(group_id, _mm256_set1_epi32(mask)); _mm256_storeu_si256(reinterpret_cast<__m256i*>(out_group_ids) + i, group_id); } From f1f860d99497de370ea2439a41b0bfff6b588ea5 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Tue, 21 Jan 2025 17:28:43 +0800 Subject: [PATCH 04/17] GH-45283: [C++][Parquet] Omit level histogram when max level is 0 (#45285) The level histogram of size statistics can be omitted if its max level is 0. We haven't implemented this yet and enforces histogram size to be equal to `max_level + 1`. However, when reading a Parquet file with omitted level histogram, exception will be thrown. Omit level histogram when max level is 0. Yes, a test case has been added to reflect the change. No. * GitHub Issue: #45283 Lead-authored-by: Gang Wu Co-authored-by: Antoine Pitrou Signed-off-by: Gang Wu --- cpp/src/parquet/column_writer.cc | 9 +- cpp/src/parquet/size_statistics.cc | 40 +++++---- cpp/src/parquet/size_statistics_test.cc | 105 +++++++++++++++++++++--- 3 files changed, 126 insertions(+), 28 deletions(-) diff --git a/cpp/src/parquet/column_writer.cc b/cpp/src/parquet/column_writer.cc index 12cbcf20affa..5525c9131686 100644 --- a/cpp/src/parquet/column_writer.cc +++ b/cpp/src/parquet/column_writer.cc @@ -1606,11 +1606,12 @@ class TypedColumnWriterImpl : public ColumnWriterImpl, public TypedColumnWriter< } auto add_levels = [](std::vector& level_histogram, - ::arrow::util::span levels) { - for (int16_t level : levels) { - ARROW_DCHECK_LT(level, static_cast(level_histogram.size())); - ++level_histogram[level]; + ::arrow::util::span levels, int16_t max_level) { + if (max_level == 0) { + return; } + ARROW_DCHECK_EQ(static_cast(max_level) + 1, level_histogram.size()); + ::parquet::UpdateLevelHistogram(levels, level_histogram); }; if (descr_->max_definition_level() > 0) { diff --git a/cpp/src/parquet/size_statistics.cc b/cpp/src/parquet/size_statistics.cc index a02cef7aba46..7efc2777b5b3 100644 --- a/cpp/src/parquet/size_statistics.cc +++ b/cpp/src/parquet/size_statistics.cc @@ -54,23 +54,28 @@ void SizeStatistics::IncrementUnencodedByteArrayDataBytes(int64_t value) { } void SizeStatistics::Validate(const ColumnDescriptor* descr) const { - if (repetition_level_histogram.size() != - static_cast(descr->max_repetition_level() + 1)) { - throw ParquetException("Repetition level histogram size mismatch"); - } - if (definition_level_histogram.size() != - static_cast(descr->max_definition_level() + 1)) { - throw ParquetException("Definition level histogram size mismatch"); - } + auto validate_histogram = [](const std::vector& histogram, int16_t max_level, + const std::string& name) { + if (histogram.empty()) { + // A levels histogram is always allowed to be missing. + return; + } + if (histogram.size() != static_cast(max_level + 1)) { + std::stringstream ss; + ss << name << " level histogram size mismatch, size: " << histogram.size() + << ", expected: " << (max_level + 1); + throw ParquetException(ss.str()); + } + }; + validate_histogram(repetition_level_histogram, descr->max_repetition_level(), + "Repetition"); + validate_histogram(definition_level_histogram, descr->max_definition_level(), + "Definition"); if (unencoded_byte_array_data_bytes.has_value() && descr->physical_type() != Type::BYTE_ARRAY) { throw ParquetException("Unencoded byte array data bytes does not support " + TypeToString(descr->physical_type())); } - if (!unencoded_byte_array_data_bytes.has_value() && - descr->physical_type() == Type::BYTE_ARRAY) { - throw ParquetException("Missing unencoded byte array data bytes"); - } } void SizeStatistics::Reset() { @@ -83,8 +88,15 @@ void SizeStatistics::Reset() { std::unique_ptr SizeStatistics::Make(const ColumnDescriptor* descr) { auto size_stats = std::make_unique(); - size_stats->repetition_level_histogram.resize(descr->max_repetition_level() + 1, 0); - size_stats->definition_level_histogram.resize(descr->max_definition_level() + 1, 0); + // If the max level is 0, the level histogram can be omitted because it contains + // only single level (a.k.a. 0) and its count is equivalent to `num_values` of the + // column chunk or data page. + if (descr->max_repetition_level() != 0) { + size_stats->repetition_level_histogram.resize(descr->max_repetition_level() + 1, 0); + } + if (descr->max_definition_level() != 0) { + size_stats->definition_level_histogram.resize(descr->max_definition_level() + 1, 0); + } if (descr->physical_type() == Type::BYTE_ARRAY) { size_stats->unencoded_byte_array_data_bytes = 0; } diff --git a/cpp/src/parquet/size_statistics_test.cc b/cpp/src/parquet/size_statistics_test.cc index cefd31dce285..ff79e5c35a01 100644 --- a/cpp/src/parquet/size_statistics_test.cc +++ b/cpp/src/parquet/size_statistics_test.cc @@ -168,12 +168,22 @@ class SizeStatisticsRoundTripTest : public ::testing::Test { } } - void Reset() { - buffer_.reset(); - row_group_stats_.clear(); - page_stats_.clear(); + void ReadData() { + auto reader = + ParquetFileReader::Open(std::make_shared<::arrow::io::BufferReader>(buffer_)); + auto metadata = reader->metadata(); + for (int i = 0; i < metadata->num_row_groups(); ++i) { + int64_t num_rows = metadata->RowGroup(i)->num_rows(); + auto row_group_reader = reader->RowGroup(i); + for (int j = 0; j < metadata->num_columns(); ++j) { + auto column_reader = row_group_reader->RecordReader(j); + ASSERT_EQ(column_reader->ReadRecords(num_rows + 1), num_rows); + } + } } + void Reset() { buffer_.reset(); } + protected: std::shared_ptr buffer_; std::vector row_group_stats_; @@ -256,24 +266,99 @@ TEST_F(SizeStatisticsRoundTripTest, WriteDictionaryArray) { ReadSizeStatistics(); EXPECT_THAT(row_group_stats_, ::testing::ElementsAre(SizeStatistics{/*def_levels=*/{0, 2}, - /*rep_levels=*/{2}, + /*rep_levels=*/{}, /*byte_array_bytes=*/5}, SizeStatistics{/*def_levels=*/{1, 1}, - /*rep_levels=*/{2}, + /*rep_levels=*/{}, /*byte_array_bytes=*/1}, SizeStatistics{/*def_levels=*/{0, 2}, - /*rep_levels=*/{2}, + /*rep_levels=*/{}, /*byte_array_bytes=*/4})); EXPECT_THAT(page_stats_, ::testing::ElementsAre(PageSizeStatistics{/*def_levels=*/{0, 2}, - /*rep_levels=*/{2}, + /*rep_levels=*/{}, /*byte_array_bytes=*/{5}}, PageSizeStatistics{/*def_levels=*/{1, 1}, - /*rep_levels=*/{2}, + /*rep_levels=*/{}, /*byte_array_bytes=*/{1}}, PageSizeStatistics{/*def_levels=*/{0, 2}, - /*rep_levels=*/{2}, + /*rep_levels=*/{}, /*byte_array_bytes=*/{4}})); } +TEST_F(SizeStatisticsRoundTripTest, WritePageInBatches) { + // Rep/def level histograms are updates in batches of `write_batch_size` levels + // inside a single page. Exercise the logic with more than one batch per page. + auto schema = ::arrow::schema({::arrow::field("a", ::arrow::list(::arrow::utf8()))}); + auto table = ::arrow::TableFromJSON(schema, {R"([ + [ [null,"a","ab"] ], + [ null ], + [ [] ], + [ [null,"d","de"] ], + [ ["g","gh",null] ], + [ ["j","jk",null] ] + ])"}); + for (int write_batch_size : {100, 5, 4, 3, 2, 1}) { + ARROW_SCOPED_TRACE("write_batch_size = ", write_batch_size); + WriteFile(SizeStatisticsLevel::PageAndColumnChunk, table, + /*max_row_group_length=*/1000, /*page_size=*/1000, write_batch_size); + ReadSizeStatistics(); + EXPECT_THAT(row_group_stats_, + ::testing::ElementsAre(SizeStatistics{/*def_levels=*/{1, 1, 4, 8}, + /*rep_levels=*/{6, 8}, + /*byte_array_bytes=*/12})); + EXPECT_THAT(page_stats_, + ::testing::ElementsAre(PageSizeStatistics{/*def_levels=*/{1, 1, 4, 8}, + /*rep_levels=*/{6, 8}, + /*byte_array_bytes=*/{12}})); + } +} + +TEST_F(SizeStatisticsRoundTripTest, LargePage) { + // When max_level is 1, the levels are summed in 2**30 chunks, exercise this + // by testing with a 90000 rows table; + auto schema = ::arrow::schema({::arrow::field("a", ::arrow::utf8())}); + auto seed_batch = ::arrow::RecordBatchFromJSON(schema, R"([ + [ "a" ], + [ "bc" ], + [ null ] + ])"); + ASSERT_OK_AND_ASSIGN(auto table, ::arrow::Table::FromRecordBatches( + ::arrow::RecordBatchVector(30000, seed_batch))); + ASSERT_OK_AND_ASSIGN(table, table->CombineChunks()); + ASSERT_EQ(table->num_rows(), 90000); + + WriteFile(SizeStatisticsLevel::PageAndColumnChunk, table, + /*max_row_group_length=*/1 << 30, /*page_size=*/1 << 30, + /*write_batch_size=*/50000); + ReadSizeStatistics(); + EXPECT_THAT(row_group_stats_, + ::testing::ElementsAre(SizeStatistics{/*def_levels=*/{30000, 60000}, + /*rep_levels=*/{}, + /*byte_array_bytes=*/90000})); + EXPECT_THAT(page_stats_, + ::testing::ElementsAre(PageSizeStatistics{/*def_levels=*/{30000, 60000}, + /*rep_levels=*/{}, + /*byte_array_bytes=*/{90000}})); +} + +TEST_F(SizeStatisticsRoundTripTest, MaxLevelZero) { + auto schema = + ::arrow::schema({::arrow::field("a", ::arrow::utf8(), /*nullable=*/false)}); + WriteFile(SizeStatisticsLevel::PageAndColumnChunk, + ::arrow::TableFromJSON(schema, {R"([["foo"],["bar"]])"}), + /*max_row_group_length=*/2, + /*page_size=*/1024); + ASSERT_NO_FATAL_FAILURE(ReadSizeStatistics()); + ASSERT_NO_FATAL_FAILURE(ReadData()); + EXPECT_THAT(row_group_stats_, + ::testing::ElementsAre(SizeStatistics{/*def_levels=*/{}, + /*rep_levels=*/{}, + /*byte_array_bytes=*/6})); + EXPECT_THAT(page_stats_, + ::testing::ElementsAre(PageSizeStatistics{/*def_levels=*/{}, + /*rep_levels=*/{}, + /*byte_array_bytes=*/{6}})); +} + } // namespace parquet From 4be13f21a3321784ff16d4e93544a85a3d3c0458 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Wed, 22 Jan 2025 17:43:33 +0100 Subject: [PATCH 05/17] GH-45304: [C++][S3] Workaround compatibility issue between AWS SDK and MinIO (#45310) ### Rationale for this change Some AWS SDK versions have faulty chunked encoding when the body is 0 bytes: https://github.com/aws/aws-sdk-cpp/issues/3259 ### What changes are included in this PR? Work around faulty chunked encoding implementation by only setting a body stream if non-empty. ### Are these changes tested? Locally for now, but will be picked by CI (and conda-forge) at some point. ### Are there any user-facing changes? No. * GitHub Issue: #45304 Authored-by: Antoine Pitrou Signed-off-by: Antoine Pitrou --- cpp/src/arrow/filesystem/s3fs.cc | 29 ++++++++++++++++----------- cpp/src/arrow/filesystem/s3fs_test.cc | 1 - 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/cpp/src/arrow/filesystem/s3fs.cc b/cpp/src/arrow/filesystem/s3fs.cc index b6a928ecdd34..773ef84d2407 100644 --- a/cpp/src/arrow/filesystem/s3fs.cc +++ b/cpp/src/arrow/filesystem/s3fs.cc @@ -1983,27 +1983,33 @@ class ObjectOutputStream final : public io::OutputStream { const void* data, int64_t nbytes, std::shared_ptr owned_buffer = nullptr) { req.SetBucket(ToAwsString(path_.bucket)); req.SetKey(ToAwsString(path_.key)); - req.SetBody(std::make_shared(data, nbytes)); req.SetContentLength(nbytes); RETURN_NOT_OK(SetSSECustomerKey(&req, sse_customer_key_)); if (!background_writes_) { - req.SetBody(std::make_shared(data, nbytes)); + // GH-45304: avoid setting a body stream if length is 0. + // This workaround can be removed once we require AWS SDK 1.11.489 or later. + if (nbytes != 0) { + req.SetBody(std::make_shared(data, nbytes)); + } ARROW_ASSIGN_OR_RAISE(auto outcome, TriggerUploadRequest(req, holder_)); RETURN_NOT_OK(sync_result_callback(req, upload_state_, part_number_, outcome)); } else { - // If the data isn't owned, make an immutable copy for the lifetime of the closure - if (owned_buffer == nullptr) { - ARROW_ASSIGN_OR_RAISE(owned_buffer, AllocateBuffer(nbytes, io_context_.pool())); - memcpy(owned_buffer->mutable_data(), data, nbytes); - } else { - DCHECK_EQ(data, owned_buffer->data()); - DCHECK_EQ(nbytes, owned_buffer->size()); + // (GH-45304: avoid setting a body stream if length is 0, see above) + if (nbytes != 0) { + // If the data isn't owned, make an immutable copy for the lifetime of the closure + if (owned_buffer == nullptr) { + ARROW_ASSIGN_OR_RAISE(owned_buffer, AllocateBuffer(nbytes, io_context_.pool())); + memcpy(owned_buffer->mutable_data(), data, nbytes); + } else { + DCHECK_EQ(data, owned_buffer->data()); + DCHECK_EQ(nbytes, owned_buffer->size()); + } + req.SetBody(std::make_shared(owned_buffer->data(), + owned_buffer->size())); } - req.SetBody( - std::make_shared(owned_buffer->data(), owned_buffer->size())); { std::unique_lock lock(upload_state_->mutex); @@ -2345,7 +2351,6 @@ class S3FileSystem::Impl : public std::enable_shared_from_this("")); return OutcomeToStatus( std::forward_as_tuple("When creating key '", key, "' in bucket '", bucket, "': "), "PutObject", client_lock.Move()->PutObject(req)); diff --git a/cpp/src/arrow/filesystem/s3fs_test.cc b/cpp/src/arrow/filesystem/s3fs_test.cc index 3082ecb7843b..370f3b26852a 100644 --- a/cpp/src/arrow/filesystem/s3fs_test.cc +++ b/cpp/src/arrow/filesystem/s3fs_test.cc @@ -526,7 +526,6 @@ class TestS3FS : public S3TestMixin { Aws::S3::Model::PutObjectRequest req; req.SetBucket(ToAwsString("bucket")); req.SetKey(ToAwsString("emptydir/")); - req.SetBody(std::make_shared("")); RETURN_NOT_OK(OutcomeToStatus("PutObject", client_->PutObject(req))); // NOTE: no need to create intermediate "directories" somedir/ and // somedir/subdir/ From 80f56ce7c824e8aef91789b91561b9c9735e71df Mon Sep 17 00:00:00 2001 From: David Li Date: Mon, 27 Jan 2025 05:04:23 -0500 Subject: [PATCH 06/17] GH-45357: [C++] Disable Flight test (#45232) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Rationale for this change See https://github.com/apache/arrow/issues/45120 ### What changes are included in this PR? Disable pointless test ### Are these changes tested? N/A ### Are there any user-facing changes? No * GitHub Issue: #45357 Lead-authored-by: David Li Co-authored-by: Raúl Cumplido Signed-off-by: Raúl Cumplido --- cpp/src/arrow/flight/test_definitions.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cpp/src/arrow/flight/test_definitions.h b/cpp/src/arrow/flight/test_definitions.h index 1e0e8c209ac9..1391ffc40bd8 100644 --- a/cpp/src/arrow/flight/test_definitions.h +++ b/cpp/src/arrow/flight/test_definitions.h @@ -306,12 +306,13 @@ class ARROW_FLIGHT_EXPORT AsyncClientTest : public FlightTest { std::unique_ptr server_; }; +// DISABLED TestListenerLifetime: https://github.com/apache/arrow/issues/45120 #define ARROW_FLIGHT_TEST_ASYNC_CLIENT(FIXTURE) \ static_assert(std::is_base_of::value, \ ARROW_STRINGIFY(FIXTURE) " must inherit from AsyncClientTest"); \ TEST_F(FIXTURE, TestGetFlightInfo) { TestGetFlightInfo(); } \ TEST_F(FIXTURE, TestGetFlightInfoFuture) { TestGetFlightInfoFuture(); } \ - TEST_F(FIXTURE, TestListenerLifetime) { TestListenerLifetime(); } + TEST_F(FIXTURE, DISABLED_TestListenerLifetime) { TestListenerLifetime(); } } // namespace flight } // namespace arrow From b1737ca80a0d66d92a35d7879b5799c8218e7b77 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Thu, 30 Jan 2025 13:27:08 +0900 Subject: [PATCH 07/17] GH-45339: [Parquet][C++] Fix statistics load logic for no row group and multiple row groups (#45350) ### Rationale for this change Loading `arrow::ArrayStatistics` logic depends on `parquet::ColumnChunkMetaData`. We can't get `parquet::ColumnChunkMetaData` when requested row groups are empty because no associated row group and column chunk exist. We can't use multiple `parquet::ColumnChunkMetaData`s for now because we don't have statistics merge logic. So we can't load statistics when we use multiple row groups. ### What changes are included in this PR? * Don't load statistics when no row groups are used * Don't load statistics when multiple row groups are used * Add `parquet::ArrowReaderProperties::{set_,}should_load_statistics()` to enforce loading statistics by loading row group one by one ### Are these changes tested? Yes. ### Are there any user-facing changes? Yes. * GitHub Issue: #45339 Authored-by: Sutou Kouhei Signed-off-by: Sutou Kouhei --- .../parquet/arrow/arrow_reader_writer_test.cc | 102 ++++++++++++++++++ .../parquet/arrow/arrow_statistics_test.cc | 55 ++++++++-- cpp/src/parquet/arrow/reader.cc | 20 +++- cpp/src/parquet/arrow/reader_internal.cc | 4 + cpp/src/parquet/arrow/reader_internal.h | 1 + cpp/src/parquet/arrow/test_util.h | 4 +- cpp/src/parquet/properties.h | 13 ++- 7 files changed, 187 insertions(+), 12 deletions(-) diff --git a/cpp/src/parquet/arrow/arrow_reader_writer_test.cc b/cpp/src/parquet/arrow/arrow_reader_writer_test.cc index 856c032c3588..b84e4a41f137 100644 --- a/cpp/src/parquet/arrow/arrow_reader_writer_test.cc +++ b/cpp/src/parquet/arrow/arrow_reader_writer_test.cc @@ -4296,6 +4296,108 @@ TEST(TestArrowReaderAdHoc, ReadFloat16Files) { } } +TEST(TestArrowFileReader, RecordBatchReaderEmptyRowGroups) { + const int num_columns = 1; + const int num_rows = 3; + const int num_chunks = 1; + + std::shared_ptr table; + ASSERT_NO_FATAL_FAILURE(MakeDoubleTable(num_columns, num_rows, num_chunks, &table)); + + const int64_t row_group_size = num_rows; + std::shared_ptr buffer; + ASSERT_NO_FATAL_FAILURE(WriteTableToBuffer(table, row_group_size, + default_arrow_writer_properties(), &buffer)); + + auto reader = ParquetFileReader::Open(std::make_shared(buffer)); + std::unique_ptr file_reader; + ASSERT_OK( + FileReader::Make(::arrow::default_memory_pool(), std::move(reader), &file_reader)); + // This is the important part in this test. + std::vector row_group_indices = {}; + ASSERT_OK_AND_ASSIGN(auto record_batch_reader, + file_reader->GetRecordBatchReader(row_group_indices)); + std::shared_ptr<::arrow::RecordBatch> record_batch; + ASSERT_OK(record_batch_reader->ReadNext(&record_batch)); + // No read record batch for empty row groups request. + ASSERT_FALSE(record_batch); +} + +TEST(TestArrowFileReader, RecordBatchReaderEmptyInput) { + const int num_columns = 1; + // This is the important part in this test. + const int num_rows = 0; + const int num_chunks = 1; + + std::shared_ptr
table; + ASSERT_NO_FATAL_FAILURE(MakeDoubleTable(num_columns, num_rows, num_chunks, &table)); + + const int64_t row_group_size = num_rows; + std::shared_ptr buffer; + ASSERT_NO_FATAL_FAILURE(WriteTableToBuffer(table, row_group_size, + default_arrow_writer_properties(), &buffer)); + + auto reader = ParquetFileReader::Open(std::make_shared(buffer)); + std::unique_ptr file_reader; + ASSERT_OK( + FileReader::Make(::arrow::default_memory_pool(), std::move(reader), &file_reader)); + ASSERT_OK_AND_ASSIGN(auto record_batch_reader, file_reader->GetRecordBatchReader()); + std::shared_ptr<::arrow::RecordBatch> record_batch; + ASSERT_OK(record_batch_reader->ReadNext(&record_batch)); + // No read record batch for empty data. + ASSERT_FALSE(record_batch); +} + +TEST(TestArrowColumnReader, NextBatchZeroBatchSize) { + const int num_columns = 1; + const int num_rows = 3; + const int num_chunks = 1; + + std::shared_ptr
table; + ASSERT_NO_FATAL_FAILURE(MakeDoubleTable(num_columns, num_rows, num_chunks, &table)); + + const int64_t row_group_size = num_rows; + std::shared_ptr buffer; + ASSERT_NO_FATAL_FAILURE(WriteTableToBuffer(table, row_group_size, + default_arrow_writer_properties(), &buffer)); + + auto reader = ParquetFileReader::Open(std::make_shared(buffer)); + std::unique_ptr file_reader; + ASSERT_OK( + FileReader::Make(::arrow::default_memory_pool(), std::move(reader), &file_reader)); + std::unique_ptr column_reader; + ASSERT_OK(file_reader->GetColumn(0, &column_reader)); + std::shared_ptr chunked_array; + // This is the important part in this test. + ASSERT_OK(column_reader->NextBatch(0, &chunked_array)); + ASSERT_EQ(0, chunked_array->length()); +} + +TEST(TestArrowColumnReader, NextBatchEmptyInput) { + const int num_columns = 1; + // This is the important part in this test. + const int num_rows = 0; + const int num_chunks = 1; + + std::shared_ptr
table; + ASSERT_NO_FATAL_FAILURE(MakeDoubleTable(num_columns, num_rows, num_chunks, &table)); + + const int64_t row_group_size = num_rows; + std::shared_ptr buffer; + ASSERT_NO_FATAL_FAILURE(WriteTableToBuffer(table, row_group_size, + default_arrow_writer_properties(), &buffer)); + + auto reader = ParquetFileReader::Open(std::make_shared(buffer)); + std::unique_ptr file_reader; + ASSERT_OK( + FileReader::Make(::arrow::default_memory_pool(), std::move(reader), &file_reader)); + std::unique_ptr column_reader; + ASSERT_OK(file_reader->GetColumn(0, &column_reader)); + std::shared_ptr chunked_array; + ASSERT_OK(column_reader->NextBatch(10, &chunked_array)); + ASSERT_EQ(0, chunked_array->length()); +} + // direct-as-possible translation of // pyarrow/tests/test_parquet.py::test_validate_schema_write_table TEST(TestArrowWriterAdHoc, SchemaMismatch) { diff --git a/cpp/src/parquet/arrow/arrow_statistics_test.cc b/cpp/src/parquet/arrow/arrow_statistics_test.cc index a8e2287d3708..048518644c6e 100644 --- a/cpp/src/parquet/arrow/arrow_statistics_test.cc +++ b/cpp/src/parquet/arrow/arrow_statistics_test.cc @@ -185,16 +185,17 @@ TEST(StatisticsTest, TruncateOnlyHalfMinMax) { namespace { ::arrow::Result> StatisticsReadArray( - std::shared_ptr<::arrow::DataType> data_type, std::shared_ptr<::arrow::Array> array) { + std::shared_ptr<::arrow::DataType> data_type, std::shared_ptr<::arrow::Array> array, + std::shared_ptr writer_properties = default_writer_properties(), + const ArrowReaderProperties& reader_properties = default_arrow_reader_properties()) { auto schema = ::arrow::schema({::arrow::field("column", data_type)}); auto record_batch = ::arrow::RecordBatch::Make(schema, array->length(), {array}); ARROW_ASSIGN_OR_RAISE(auto sink, ::arrow::io::BufferOutputStream::Create()); const auto arrow_writer_properties = parquet::ArrowWriterProperties::Builder().store_schema()->build(); - ARROW_ASSIGN_OR_RAISE( - auto writer, - FileWriter::Open(*schema, ::arrow::default_memory_pool(), sink, - default_writer_properties(), arrow_writer_properties)); + ARROW_ASSIGN_OR_RAISE(auto writer, + FileWriter::Open(*schema, ::arrow::default_memory_pool(), sink, + writer_properties, arrow_writer_properties)); ARROW_RETURN_NOT_OK(writer->WriteRecordBatch(*record_batch)); ARROW_RETURN_NOT_OK(writer->Close()); ARROW_ASSIGN_OR_RAISE(auto buffer, sink->Finish()); @@ -202,8 +203,8 @@ ::arrow::Result> StatisticsReadArray( auto reader = ParquetFileReader::Open(std::make_shared<::arrow::io::BufferReader>(buffer)); std::unique_ptr file_reader; - ARROW_RETURN_NOT_OK( - FileReader::Make(::arrow::default_memory_pool(), std::move(reader), &file_reader)); + ARROW_RETURN_NOT_OK(FileReader::Make(::arrow::default_memory_pool(), std::move(reader), + reader_properties, &file_reader)); std::shared_ptr<::arrow::ChunkedArray> chunked_array; ARROW_RETURN_NOT_OK(file_reader->ReadColumn(0, &chunked_array)); return chunked_array->chunk(0); @@ -326,4 +327,44 @@ TEST(TestStatisticsRead, Duration) { ::arrow::duration(::arrow::TimeUnit::NANO)); } +TEST(TestStatisticsRead, MultipleRowGroupsDefault) { + auto arrow_type = ::arrow::int32(); + auto built_array = ArrayFromJSON(arrow_type, R"([1, null, -1])"); + auto writer_properties = WriterProperties::Builder().max_row_group_length(2)->build(); + ASSERT_OK_AND_ASSIGN( + auto read_array, + StatisticsReadArray(arrow_type, std::move(built_array), writer_properties)); + auto typed_read_array = std::static_pointer_cast<::arrow::Int32Array>(read_array); + auto statistics = typed_read_array->statistics(); + ASSERT_EQ(nullptr, statistics); +} + +TEST(TestStatisticsRead, MultipleRowGroupsShouldLoadStatistics) { + auto arrow_type = ::arrow::int32(); + auto built_array = ArrayFromJSON(arrow_type, R"([1, null, -1])"); + auto writer_properties = WriterProperties::Builder().max_row_group_length(2)->build(); + ArrowReaderProperties reader_properties; + reader_properties.set_should_load_statistics(true); + ASSERT_OK_AND_ASSIGN(auto read_array, + StatisticsReadArray(arrow_type, std::move(built_array), + writer_properties, reader_properties)); + // If we use should_load_statistics, reader doesn't load multiple + // row groups at once. So the first array in the read chunked array + // has only 2 elements. + ASSERT_EQ(2, read_array->length()); + auto typed_read_array = std::static_pointer_cast<::arrow::Int32Array>(read_array); + auto statistics = typed_read_array->statistics(); + ASSERT_NE(nullptr, statistics); + ASSERT_EQ(true, statistics->null_count.has_value()); + ASSERT_EQ(1, statistics->null_count.value()); + ASSERT_EQ(false, statistics->distinct_count.has_value()); + ASSERT_EQ(true, statistics->min.has_value()); + // This is not -1 because this array has only the first 2 elements. + ASSERT_EQ(1, std::get(*statistics->min)); + ASSERT_EQ(true, statistics->is_min_exact); + ASSERT_EQ(true, statistics->max.has_value()); + ASSERT_EQ(1, std::get(*statistics->max)); + ASSERT_EQ(true, statistics->is_max_exact); +} + } // namespace parquet::arrow diff --git a/cpp/src/parquet/arrow/reader.cc b/cpp/src/parquet/arrow/reader.cc index 465ad5844d31..03b725beb2a0 100644 --- a/cpp/src/parquet/arrow/reader.cc +++ b/cpp/src/parquet/arrow/reader.cc @@ -218,6 +218,7 @@ class FileReaderImpl : public FileReader { ctx->iterator_factory = SomeRowGroupsFactory(row_groups); ctx->filter_leaves = true; ctx->included_leaves = included_leaves; + ctx->reader_properties = &reader_properties_; return GetReader(manifest_.schema_fields[i], ctx, out); } @@ -475,6 +476,8 @@ class LeafReader : public ColumnReaderImpl { record_reader_->Reset(); // Pre-allocation gives much better performance for flat columns record_reader_->Reserve(records_to_read); + const bool should_load_statistics = ctx_->reader_properties->should_load_statistics(); + int64_t num_target_row_groups = 0; while (records_to_read > 0) { if (!record_reader_->HasMoreData()) { break; @@ -483,11 +486,21 @@ class LeafReader : public ColumnReaderImpl { records_to_read -= records_read; if (records_read == 0) { NextRowGroup(); + } else { + num_target_row_groups++; + // We can't mix multiple row groups when we load statistics + // because statistics are associated with a row group. If we + // want to mix multiple row groups and keep valid statistics, + // we need to implement a statistics merge logic. + if (should_load_statistics) { + break; + } } } - RETURN_NOT_OK(TransferColumnData(record_reader_.get(), - input_->column_chunk_metadata(), field_, descr_, - ctx_.get(), &out_)); + RETURN_NOT_OK(TransferColumnData( + record_reader_.get(), + num_target_row_groups == 1 ? input_->column_chunk_metadata() : nullptr, field_, + descr_, ctx_.get(), &out_)); return Status::OK(); END_PARQUET_CATCH_EXCEPTIONS } @@ -1214,6 +1227,7 @@ Status FileReaderImpl::GetColumn(int i, FileColumnIteratorFactory iterator_facto ctx->pool = pool_; ctx->iterator_factory = iterator_factory; ctx->filter_leaves = false; + ctx->reader_properties = &reader_properties_; std::unique_ptr result; RETURN_NOT_OK(GetReader(manifest_.schema_fields[i], ctx, &result)); *out = std::move(result); diff --git a/cpp/src/parquet/arrow/reader_internal.cc b/cpp/src/parquet/arrow/reader_internal.cc index 9d3171ea1a95..59fe2b460020 100644 --- a/cpp/src/parquet/arrow/reader_internal.cc +++ b/cpp/src/parquet/arrow/reader_internal.cc @@ -322,6 +322,10 @@ template void AttachStatistics(::arrow::ArrayData* data, std::unique_ptr<::parquet::ColumnChunkMetaData> metadata, const ReaderContext* ctx) { + if (!metadata) { + return; + } + using ArrowCType = typename ArrowType::c_type; auto statistics = metadata->statistics().get(); diff --git a/cpp/src/parquet/arrow/reader_internal.h b/cpp/src/parquet/arrow/reader_internal.h index fab56c888045..4ee3bf98bc54 100644 --- a/cpp/src/parquet/arrow/reader_internal.h +++ b/cpp/src/parquet/arrow/reader_internal.h @@ -117,6 +117,7 @@ struct ReaderContext { FileColumnIteratorFactory iterator_factory; bool filter_leaves; std::shared_ptr> included_leaves; + ArrowReaderProperties* reader_properties; bool IncludesLeaf(int leaf_index) const { if (this->filter_leaves) { diff --git a/cpp/src/parquet/arrow/test_util.h b/cpp/src/parquet/arrow/test_util.h index c8fcbbb65d1b..cfc57ce6ea74 100644 --- a/cpp/src/parquet/arrow/test_util.h +++ b/cpp/src/parquet/arrow/test_util.h @@ -229,7 +229,9 @@ ::arrow::enable_if_floating_point NullableArray( } ::arrow::NumericBuilder builder; - RETURN_NOT_OK(builder.AppendValues(values.data(), values.size(), valid_bytes.data())); + if (values.size() > 0) { + RETURN_NOT_OK(builder.AppendValues(values.data(), values.size(), valid_bytes.data())); + } return builder.Finish(out); } diff --git a/cpp/src/parquet/properties.h b/cpp/src/parquet/properties.h index edaf28cd92ae..46f3ae378dc6 100644 --- a/cpp/src/parquet/properties.h +++ b/cpp/src/parquet/properties.h @@ -911,7 +911,8 @@ class PARQUET_EXPORT ArrowReaderProperties { pre_buffer_(true), cache_options_(::arrow::io::CacheOptions::LazyDefaults()), coerce_int96_timestamp_unit_(::arrow::TimeUnit::NANO), - arrow_extensions_enabled_(false) {} + arrow_extensions_enabled_(false), + should_load_statistics_(false) {} /// \brief Set whether to use the IO thread pool to parse columns in parallel. /// @@ -994,6 +995,15 @@ class PARQUET_EXPORT ArrowReaderProperties { } bool get_arrow_extensions_enabled() const { return arrow_extensions_enabled_; } + /// \brief Set whether to load statistics as much as possible. + /// + /// Default is false. + void set_should_load_statistics(bool should_load_statistics) { + should_load_statistics_ = should_load_statistics; + } + /// Return whether loading statistics as much as possible. + bool should_load_statistics() const { return should_load_statistics_; } + private: bool use_threads_; std::unordered_set read_dict_indices_; @@ -1003,6 +1013,7 @@ class PARQUET_EXPORT ArrowReaderProperties { ::arrow::io::CacheOptions cache_options_; ::arrow::TimeUnit::type coerce_int96_timestamp_unit_; bool arrow_extensions_enabled_; + bool should_load_statistics_; }; /// EXPERIMENTAL: Constructs the default ArrowReaderProperties From e696b2612fef0c3474fa2df6548df30464f7654f Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Thu, 30 Jan 2025 13:16:04 +0100 Subject: [PATCH 08/17] GH-45296: [Python] Only enable the string dtype on pandas export for pandas>=2.3 (#45383) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The option already exists in pandas 2.2, but for that version our code does not work, so restricting it to pandas >= 2.3 * GitHub Issue: #45296 Authored-by: Joris Van den Bossche Signed-off-by: Raúl Cumplido --- python/pyarrow/pandas-shim.pxi | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/python/pyarrow/pandas-shim.pxi b/python/pyarrow/pandas-shim.pxi index 5be6f03f86ed..aab9cf1079e9 100644 --- a/python/pyarrow/pandas-shim.pxi +++ b/python/pyarrow/pandas-shim.pxi @@ -38,7 +38,7 @@ cdef class _PandasAPIShim(object): object _array_like_types, _is_extension_array_dtype, _lock bint has_sparse bint _pd024 - bint _is_v1, _is_ge_v21, _is_ge_v3, _is_ge_v3_strict + bint _is_v1, _is_ge_v21, _is_ge_v23, _is_ge_v3, _is_ge_v3_strict def __init__(self): self._lock = Lock() @@ -79,6 +79,7 @@ cdef class _PandasAPIShim(object): self._is_v1 = self._loose_version < Version('2.0.0') self._is_ge_v21 = self._loose_version >= Version('2.1.0') + self._is_ge_v23 = self._loose_version >= Version('2.3.0') self._is_ge_v3 = self._loose_version >= Version('3.0.0.dev0') self._is_ge_v3_strict = self._loose_version >= Version('3.0.0') @@ -171,6 +172,10 @@ cdef class _PandasAPIShim(object): self._check_import() return self._is_ge_v21 + def is_ge_v23(self): + self._check_import() + return self._is_ge_v23 + def is_ge_v3(self): self._check_import() return self._is_ge_v3 @@ -183,7 +188,7 @@ cdef class _PandasAPIShim(object): if self.is_ge_v3_strict(): return True try: - if self.pd.options.future.infer_string: + if self.is_ge_v23() and self.pd.options.future.infer_string: return True except: pass From 1b9079c96cdb4a589915c6494cfe26609ab40712 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Thu, 9 Jan 2025 15:57:04 +0100 Subject: [PATCH 09/17] GH-45201: [C++][Parquet] Improve performance of generating size statistics (#45202) We found out in https://github.com/apache/arrow/pull/45085 that there is a non-trivial overhead when writing size statistics is enabled. Dramatically reduce overhead by speeding up def/rep levels histogram updates. Performance results on the author's machine: ``` ------------------------------------------------------------------------------------------------------------------------------------------------ Benchmark Time CPU Iterations UserCounters... ------------------------------------------------------------------------------------------------------------------------------------------------ BM_WritePrimitiveColumn 8103053 ns 8098569 ns 86 bytes_per_second=1003.26Mi/s items_per_second=129.477M/s output_size=537.472k page_index_size=33 BM_WritePrimitiveColumn 8153499 ns 8148492 ns 86 bytes_per_second=997.117Mi/s items_per_second=128.683M/s output_size=537.488k page_index_size=33 BM_WritePrimitiveColumn 8212560 ns 8207754 ns 83 bytes_per_second=989.918Mi/s items_per_second=127.754M/s output_size=537.502k page_index_size=47 BM_WritePrimitiveColumn 10405020 ns 10400775 ns 67 bytes_per_second=444.142Mi/s items_per_second=100.817M/s output_size=848.305k page_index_size=34 BM_WritePrimitiveColumn 10464784 ns 10460778 ns 66 bytes_per_second=441.594Mi/s items_per_second=100.239M/s output_size=848.325k page_index_size=34 BM_WritePrimitiveColumn 10469832 ns 10465739 ns 67 bytes_per_second=441.385Mi/s items_per_second=100.191M/s output_size=848.344k page_index_size=48 BM_WriteListColumn 13004962 ns 12992678 ns 52 bytes_per_second=657.101Mi/s items_per_second=80.7052M/s output_size=617.464k page_index_size=34 BM_WriteListColumn 13718352 ns 13705599 ns 50 bytes_per_second=622.921Mi/s items_per_second=76.5071M/s output_size=617.486k page_index_size=34 BM_WriteListColumn 13845553 ns 13832138 ns 52 bytes_per_second=617.222Mi/s items_per_second=75.8072M/s output_size=617.506k page_index_size=54 BM_WriteListColumn 15715263 ns 15702707 ns 44 bytes_per_second=320.449Mi/s items_per_second=66.7768M/s output_size=927.326k page_index_size=35 BM_WriteListColumn 16507328 ns 16493800 ns 43 bytes_per_second=305.079Mi/s items_per_second=63.5739M/s output_size=927.352k page_index_size=35 BM_WriteListColumn 16575359 ns 16561311 ns 42 bytes_per_second=303.836Mi/s items_per_second=63.3148M/s output_size=927.377k page_index_size=55 ``` Performance results without this PR: ``` ------------------------------------------------------------------------------------------------------------------------------------------------ Benchmark Time CPU Iterations UserCounters... ------------------------------------------------------------------------------------------------------------------------------------------------ BM_WritePrimitiveColumn 8042576 ns 8037678 ns 87 bytes_per_second=1010.86Mi/s items_per_second=130.458M/s output_size=537.472k page_index_size=33 BM_WritePrimitiveColumn 9576627 ns 9571279 ns 73 bytes_per_second=848.894Mi/s items_per_second=109.554M/s output_size=537.488k page_index_size=33 BM_WritePrimitiveColumn 9570204 ns 9563595 ns 73 bytes_per_second=849.576Mi/s items_per_second=109.642M/s output_size=537.502k page_index_size=47 BM_WritePrimitiveColumn 10165397 ns 10160868 ns 69 bytes_per_second=454.628Mi/s items_per_second=103.197M/s output_size=848.305k page_index_size=34 BM_WritePrimitiveColumn 11662568 ns 11657396 ns 60 bytes_per_second=396.265Mi/s items_per_second=89.9494M/s output_size=848.325k page_index_size=34 BM_WritePrimitiveColumn 11657135 ns 11653063 ns 60 bytes_per_second=396.412Mi/s items_per_second=89.9829M/s output_size=848.344k page_index_size=48 BM_WriteListColumn 13182006 ns 13168704 ns 51 bytes_per_second=648.318Mi/s items_per_second=79.6264M/s output_size=617.464k page_index_size=34 BM_WriteListColumn 16438205 ns 16421762 ns 43 bytes_per_second=519.89Mi/s items_per_second=63.8528M/s output_size=617.486k page_index_size=34 BM_WriteListColumn 16424615 ns 16409032 ns 42 bytes_per_second=520.293Mi/s items_per_second=63.9024M/s output_size=617.506k page_index_size=54 BM_WriteListColumn 15387808 ns 15373086 ns 46 bytes_per_second=327.32Mi/s items_per_second=68.2086M/s output_size=927.326k page_index_size=35 BM_WriteListColumn 18319628 ns 18302938 ns 37 bytes_per_second=274.924Mi/s items_per_second=57.29M/s output_size=927.352k page_index_size=35 BM_WriteListColumn 18346665 ns 18329336 ns 37 bytes_per_second=274.528Mi/s items_per_second=57.2075M/s output_size=927.377k page_index_size=55 ``` Tested by existing tests, validated by existing benchmarks. No. * GitHub Issue: #45201 Authored-by: Antoine Pitrou Signed-off-by: Antoine Pitrou --- cpp/src/parquet/column_writer.cc | 45 +++++----- cpp/src/parquet/size_statistics.cc | 106 ++++++++++++++++++++++-- cpp/src/parquet/size_statistics.h | 10 +++ cpp/src/parquet/size_statistics_test.cc | 70 +++++++++++++--- 4 files changed, 189 insertions(+), 42 deletions(-) diff --git a/cpp/src/parquet/column_writer.cc b/cpp/src/parquet/column_writer.cc index 5525c9131686..4998e6f301a0 100644 --- a/cpp/src/parquet/column_writer.cc +++ b/cpp/src/parquet/column_writer.cc @@ -1468,42 +1468,43 @@ class TypedColumnWriterImpl : public ColumnWriterImpl, public TypedColumnWriter< // which case we call back to the dense write path) std::shared_ptr<::arrow::Array> preserved_dictionary_; - int64_t WriteLevels(int64_t num_values, const int16_t* def_levels, + int64_t WriteLevels(int64_t num_levels, const int16_t* def_levels, const int16_t* rep_levels) { + // Update histograms now, to maximize cache efficiency. + UpdateLevelHistogram(num_levels, def_levels, rep_levels); + int64_t values_to_write = 0; // If the field is required and non-repeated, there are no definition levels if (descr_->max_definition_level() > 0) { - for (int64_t i = 0; i < num_values; ++i) { + for (int64_t i = 0; i < num_levels; ++i) { if (def_levels[i] == descr_->max_definition_level()) { ++values_to_write; } } - WriteDefinitionLevels(num_values, def_levels); + WriteDefinitionLevels(num_levels, def_levels); } else { // Required field, write all values - values_to_write = num_values; + values_to_write = num_levels; } // Not present for non-repeated fields if (descr_->max_repetition_level() > 0) { // A row could include more than one value // Count the occasions where we start a new row - for (int64_t i = 0; i < num_values; ++i) { + for (int64_t i = 0; i < num_levels; ++i) { if (rep_levels[i] == 0) { rows_written_++; num_buffered_rows_++; } } - WriteRepetitionLevels(num_values, rep_levels); + WriteRepetitionLevels(num_levels, rep_levels); } else { // Each value is exactly one row - rows_written_ += num_values; - num_buffered_rows_ += num_values; + rows_written_ += num_levels; + num_buffered_rows_ += num_levels; } - - UpdateLevelHistogram(num_values, def_levels, rep_levels); return values_to_write; } @@ -1575,6 +1576,9 @@ class TypedColumnWriterImpl : public ColumnWriterImpl, public TypedColumnWriter< void WriteLevelsSpaced(int64_t num_levels, const int16_t* def_levels, const int16_t* rep_levels) { + // Update histograms now, to maximize cache efficiency. + UpdateLevelHistogram(num_levels, def_levels, rep_levels); + // If the field is required and non-repeated, there are no definition levels if (descr_->max_definition_level() > 0) { WriteDefinitionLevels(num_levels, def_levels); @@ -1595,8 +1599,6 @@ class TypedColumnWriterImpl : public ColumnWriterImpl, public TypedColumnWriter< rows_written_ += num_levels; num_buffered_rows_ += num_levels; } - - UpdateLevelHistogram(num_levels, def_levels, rep_levels); } void UpdateLevelHistogram(int64_t num_levels, const int16_t* def_levels, @@ -1614,19 +1616,12 @@ class TypedColumnWriterImpl : public ColumnWriterImpl, public TypedColumnWriter< ::parquet::UpdateLevelHistogram(levels, level_histogram); }; - if (descr_->max_definition_level() > 0) { - add_levels(page_size_statistics_->definition_level_histogram, - {def_levels, static_cast(num_levels)}); - } else { - page_size_statistics_->definition_level_histogram[0] += num_levels; - } - - if (descr_->max_repetition_level() > 0) { - add_levels(page_size_statistics_->repetition_level_histogram, - {rep_levels, static_cast(num_levels)}); - } else { - page_size_statistics_->repetition_level_histogram[0] += num_levels; - } + add_levels(page_size_statistics_->definition_level_histogram, + {def_levels, static_cast(num_levels)}, + descr_->max_definition_level()); + add_levels(page_size_statistics_->repetition_level_histogram, + {rep_levels, static_cast(num_levels)}, + descr_->max_repetition_level()); } // Update the unencoded data bytes for ByteArray only per the specification. diff --git a/cpp/src/parquet/size_statistics.cc b/cpp/src/parquet/size_statistics.cc index 7efc2777b5b3..1ce6c937ad5e 100644 --- a/cpp/src/parquet/size_statistics.cc +++ b/cpp/src/parquet/size_statistics.cc @@ -18,6 +18,9 @@ #include "parquet/size_statistics.h" #include +#include +#include +#include #include "arrow/util/logging.h" #include "parquet/exception.h" @@ -25,6 +28,17 @@ namespace parquet { +namespace { + +void MergeLevelHistogram(::arrow::util::span histogram, + ::arrow::util::span other) { + ARROW_DCHECK_EQ(histogram.size(), other.size()); + std::transform(histogram.begin(), histogram.end(), other.begin(), histogram.begin(), + std::plus<>()); +} + +} // namespace + void SizeStatistics::Merge(const SizeStatistics& other) { if (repetition_level_histogram.size() != other.repetition_level_histogram.size()) { throw ParquetException("Repetition level histogram size mismatch"); @@ -36,12 +50,8 @@ void SizeStatistics::Merge(const SizeStatistics& other) { other.unencoded_byte_array_data_bytes.has_value()) { throw ParquetException("Unencoded byte array data bytes are not consistent"); } - std::transform(repetition_level_histogram.begin(), repetition_level_histogram.end(), - other.repetition_level_histogram.begin(), - repetition_level_histogram.begin(), std::plus<>()); - std::transform(definition_level_histogram.begin(), definition_level_histogram.end(), - other.definition_level_histogram.begin(), - definition_level_histogram.begin(), std::plus<>()); + MergeLevelHistogram(repetition_level_histogram, other.repetition_level_histogram); + MergeLevelHistogram(definition_level_histogram, other.definition_level_histogram); if (unencoded_byte_array_data_bytes.has_value()) { unencoded_byte_array_data_bytes = unencoded_byte_array_data_bytes.value() + other.unencoded_byte_array_data_bytes.value(); @@ -103,4 +113,88 @@ std::unique_ptr SizeStatistics::Make(const ColumnDescriptor* des return size_stats; } +std::ostream& operator<<(std::ostream& os, const SizeStatistics& size_stats) { + constexpr std::string_view kComma = ", "; + os << "SizeStatistics{"; + std::string_view sep = ""; + if (size_stats.unencoded_byte_array_data_bytes.has_value()) { + os << "unencoded_byte_array_data_bytes=" + << *size_stats.unencoded_byte_array_data_bytes; + sep = kComma; + } + auto print_histogram = [&](std::string_view name, + const std::vector& histogram) { + if (!histogram.empty()) { + os << sep << name << "={"; + sep = kComma; + std::string_view value_sep = ""; + for (int64_t v : histogram) { + os << value_sep << v; + value_sep = kComma; + } + os << "}"; + } + }; + print_histogram("repetition_level_histogram", size_stats.repetition_level_histogram); + print_histogram("definition_level_histogram", size_stats.definition_level_histogram); + os << "}"; + return os; +} + +void UpdateLevelHistogram(::arrow::util::span levels, + ::arrow::util::span histogram) { + const int64_t num_levels = static_cast(levels.size()); + DCHECK_GE(histogram.size(), 1); + const int16_t max_level = static_cast(histogram.size() - 1); + if (max_level == 0) { + histogram[0] += num_levels; + return; + } + +#ifndef NDEBUG + for (auto level : levels) { + ARROW_DCHECK_LE(level, max_level); + } +#endif + + if (max_level == 1) { + // Specialize the common case for non-repeated non-nested columns. + // Summing the levels gives us the number of 1s, and the number of 0s follows. + // We do repeated sums in the int16_t space, which the compiler is likely + // to vectorize efficiently. + constexpr int64_t kChunkSize = 1 << 14; // to avoid int16_t overflows + int64_t hist1 = 0; + auto it = levels.begin(); + while (it != levels.end()) { + const auto chunk_size = std::min(levels.end() - it, kChunkSize); + hist1 += std::accumulate(levels.begin(), levels.begin() + chunk_size, int16_t{0}); + it += chunk_size; + } + histogram[0] += num_levels - hist1; + histogram[1] += hist1; + return; + } + + // The generic implementation issues a series of histogram load-stores. + // However, it limits store-to-load dependencies by interleaving partial histogram + // updates. + constexpr int kUnroll = 4; + std::array, kUnroll> partial_hist; + for (auto& hist : partial_hist) { + hist.assign(histogram.size(), 0); + } + int64_t i = 0; + for (; i <= num_levels - kUnroll; i += kUnroll) { + for (int j = 0; j < kUnroll; ++j) { + ++partial_hist[j][levels[i + j]]; + } + } + for (; i < num_levels; ++i) { + ++partial_hist[0][levels[i]]; + } + for (const auto& hist : partial_hist) { + MergeLevelHistogram(histogram, hist); + } +} + } // namespace parquet diff --git a/cpp/src/parquet/size_statistics.h b/cpp/src/parquet/size_statistics.h index c25e70ee36d8..ec79b8c4f8b8 100644 --- a/cpp/src/parquet/size_statistics.h +++ b/cpp/src/parquet/size_statistics.h @@ -17,9 +17,12 @@ #pragma once +#include +#include #include #include +#include "arrow/util/span.h" #include "parquet/platform.h" #include "parquet/type_fwd.h" @@ -89,4 +92,11 @@ struct PARQUET_EXPORT SizeStatistics { static std::unique_ptr Make(const ColumnDescriptor* descr); }; +PARQUET_EXPORT +std::ostream& operator<<(std::ostream&, const SizeStatistics&); + +PARQUET_EXPORT +void UpdateLevelHistogram(::arrow::util::span levels, + ::arrow::util::span histogram); + } // namespace parquet diff --git a/cpp/src/parquet/size_statistics_test.cc b/cpp/src/parquet/size_statistics_test.cc index ff79e5c35a01..90d6df57e7f4 100644 --- a/cpp/src/parquet/size_statistics_test.cc +++ b/cpp/src/parquet/size_statistics_test.cc @@ -19,16 +19,14 @@ #include "gtest/gtest.h" #include +#include #include #include "arrow/buffer.h" #include "arrow/table.h" -#include "arrow/testing/builder.h" #include "arrow/testing/gtest_util.h" -#include "arrow/util/bit_util.h" #include "arrow/util/span.h" #include "parquet/arrow/reader.h" -#include "parquet/arrow/reader_internal.h" #include "parquet/arrow/schema.h" #include "parquet/arrow/writer.h" #include "parquet/column_writer.h" @@ -42,6 +40,29 @@ namespace parquet { +TEST(SizeStatistics, UpdateLevelHistogram) { + { + // max_level = 1 + std::vector histogram(2, 0); + UpdateLevelHistogram(std::vector{0, 1, 1, 1, 0}, histogram); + EXPECT_THAT(histogram, ::testing::ElementsAre(2, 3)); + UpdateLevelHistogram(std::vector{1, 1, 0}, histogram); + EXPECT_THAT(histogram, ::testing::ElementsAre(3, 5)); + UpdateLevelHistogram(std::vector{}, histogram); + EXPECT_THAT(histogram, ::testing::ElementsAre(3, 5)); + } + { + // max_level > 1 + std::vector histogram(3, 0); + UpdateLevelHistogram(std::vector{0, 1, 2, 2, 0}, histogram); + EXPECT_THAT(histogram, ::testing::ElementsAre(2, 1, 2)); + UpdateLevelHistogram(std::vector{1, 1, 0}, histogram); + EXPECT_THAT(histogram, ::testing::ElementsAre(3, 3, 2)); + UpdateLevelHistogram(std::vector{}, histogram); + EXPECT_THAT(histogram, ::testing::ElementsAre(3, 3, 2)); + } +} + TEST(SizeStatistics, ThriftSerDe) { const std::vector kDefLevels = {128, 64, 32, 16}; const std::vector kRepLevels = {100, 80, 60, 40, 20}; @@ -88,13 +109,38 @@ struct PageSizeStatistics { } }; +std::ostream& operator<<(std::ostream& os, const PageSizeStatistics& page_stats) { + constexpr std::string_view kComma = ", "; + os << "PageSizeStatistics{"; + std::string_view sep = ""; + auto print_vector = [&](std::string_view name, const std::vector& values) { + if (!values.empty()) { + os << sep << name << "={"; + sep = kComma; + std::string_view value_sep = ""; + for (int64_t v : values) { + os << value_sep << v; + value_sep = kComma; + } + os << "}"; + } + }; + print_vector("def_levels", page_stats.def_levels); + print_vector("rep_levels", page_stats.rep_levels); + print_vector("byte_array_bytes", page_stats.byte_array_bytes); + os << "}"; + return os; +} + class SizeStatisticsRoundTripTest : public ::testing::Test { public: - void WriteFile(SizeStatisticsLevel level, - const std::shared_ptr<::arrow::Table>& table) { + void WriteFile(SizeStatisticsLevel level, const std::shared_ptr<::arrow::Table>& table, + int max_row_group_length, int page_size, + int write_batch_size = DEFAULT_WRITE_BATCH_SIZE) { auto writer_properties = WriterProperties::Builder() - .max_row_group_length(2) /* every row group has 2 rows */ - ->data_pagesize(1) /* every page has 1 row */ + .max_row_group_length(max_row_group_length) + ->data_pagesize(page_size) + ->write_batch_size(write_batch_size) ->enable_write_page_index() ->enable_statistics() ->set_size_statistics_level(level) @@ -127,6 +173,7 @@ class SizeStatisticsRoundTripTest : public ::testing::Test { ParquetFileReader::Open(std::make_shared<::arrow::io::BufferReader>(buffer_)); // Read row group size statistics in order. + row_group_stats_.clear(); auto metadata = reader->metadata(); for (int i = 0; i < metadata->num_row_groups(); ++i) { auto row_group_metadata = metadata->RowGroup(i); @@ -138,6 +185,7 @@ class SizeStatisticsRoundTripTest : public ::testing::Test { } // Read page size statistics in order. + page_stats_.clear(); auto page_index_reader = reader->GetPageIndexReader(); ASSERT_NE(page_index_reader, nullptr); @@ -197,7 +245,7 @@ TEST_F(SizeStatisticsRoundTripTest, EnableSizeStats) { ::arrow::field("a", ::arrow::list(::arrow::list(::arrow::int32()))), ::arrow::field("b", ::arrow::list(::arrow::list(::arrow::utf8()))), }); - // First two rows are in one row group, and the other two rows are in another row group. + // First two rows will be in one row group, and the other two rows in another row group. auto table = ::arrow::TableFromJSON(schema, {R"([ [ [[1],[1,1],[1,1,1]], [["a"],["a","a"],["a","a","a"]] ], [ [[0,1,null]], [["foo","bar",null]] ], @@ -208,7 +256,7 @@ TEST_F(SizeStatisticsRoundTripTest, EnableSizeStats) { for (auto size_stats_level : {SizeStatisticsLevel::None, SizeStatisticsLevel::ColumnChunk, SizeStatisticsLevel::PageAndColumnChunk}) { - WriteFile(size_stats_level, table); + WriteFile(size_stats_level, table, /*max_row_group_length=*/2, /*page_size=*/1); ReadSizeStatistics(); if (size_stats_level == SizeStatisticsLevel::None) { @@ -261,8 +309,8 @@ TEST_F(SizeStatisticsRoundTripTest, WriteDictionaryArray) { {::arrow::field("a", ::arrow::dictionary(::arrow::int16(), ::arrow::utf8()))}); WriteFile( SizeStatisticsLevel::PageAndColumnChunk, - ::arrow::TableFromJSON(schema, {R"([["aa"],["aaa"],[null],["a"],["aaa"],["a"]])"})); - + ::arrow::TableFromJSON(schema, {R"([["aa"],["aaa"],[null],["a"],["aaa"],["a"]])"}), + /*max_row_group_length=*/2, /*page_size=*/1); ReadSizeStatistics(); EXPECT_THAT(row_group_stats_, ::testing::ElementsAre(SizeStatistics{/*def_levels=*/{0, 2}, From a37799a6fd8a94d0202113abbae9249f40e38e39 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Tue, 21 Jan 2025 17:49:59 +0100 Subject: [PATCH 10/17] GH-45305: [CI] Bump Minio version and unpin boto3 (#45320) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use latest Minio server release, which includes a fix for https://github.com/minio/minio/issues/20845 This allows us to remove the boto3 version constraint. Yes, by existing CI tests. Yes. * GitHub Issue: #45305 Authored-by: Antoine Pitrou Signed-off-by: Raúl Cumplido --- ci/appveyor-cpp-setup.bat | 2 +- ci/conda_env_python.txt | 6 ++++-- ci/scripts/install_minio.sh | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ci/appveyor-cpp-setup.bat b/ci/appveyor-cpp-setup.bat index 912b130acff4..a5ca7f76bd19 100644 --- a/ci/appveyor-cpp-setup.bat +++ b/ci/appveyor-cpp-setup.bat @@ -86,7 +86,7 @@ set CXX=cl.exe @rem Download Minio somewhere on PATH, for unit tests @rem if "%ARROW_S3%" == "ON" ( - appveyor DownloadFile https://dl.min.io/server/minio/release/windows-amd64/archive/minio.RELEASE.2024-09-13T20-26-02Z -FileName C:\Windows\Minio.exe || exit /B + appveyor DownloadFile https://dl.min.io/server/minio/release/windows-amd64/archive/minio.RELEASE.2025-01-20T14-49-07Z -FileName C:\Windows\Minio.exe || exit /B ) @rem diff --git a/ci/conda_env_python.txt b/ci/conda_env_python.txt index bf915493de30..ed595d05eee5 100644 --- a/ci/conda_env_python.txt +++ b/ci/conda_env_python.txt @@ -15,8 +15,10 @@ # specific language governing permissions and limitations # under the License. -# don't add pandas here, because it is not a mandatory test dependency -boto3 # not a direct dependency of s3fs, but needed for our s3fs fixture +# Don't add pandas here, because it is not a mandatory test dependency + +# Not a direct dependency of s3fs, but needed for our s3fs fixture +boto3 cffi cython>=0.29.31 cloudpickle diff --git a/ci/scripts/install_minio.sh b/ci/scripts/install_minio.sh index 6f9701ab5a15..8685ced0bd1a 100755 --- a/ci/scripts/install_minio.sh +++ b/ci/scripts/install_minio.sh @@ -63,7 +63,7 @@ if [ "${version}" != "latest" ]; then fi # Use specific versions for minio server and client to avoid CI failures on new releases. -minio_version="minio.RELEASE.2024-09-13T20-26-02Z" +minio_version="minio.RELEASE.2025-01-20T14-49-07Z" mc_version="mc.RELEASE.2024-09-16T17-43-14Z" download() From 411189f8664d200fec6e6004f5e49cb9fcb63c50 Mon Sep 17 00:00:00 2001 From: Bryce Mecum Date: Sun, 2 Feb 2025 18:02:38 -0800 Subject: [PATCH 11/17] MINOR: [Release] Update CHANGELOG.md for 19.0.1 --- CHANGELOG.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5774601dab83..39d3d64cd9ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,25 @@ +# Apache Arrow 19.0.1 (2025-01-30 08:00:00+00:00) + +## Bug Fixes + +* [GH-44513](https://github.com/apache/arrow/issues/44513) - [C++][Python] Pyarrow.Table.join() breaks on large tables v.18.0.0.dev486 +* [GH-45180](https://github.com/apache/arrow/issues/45180) - [C++][Fuzzing] Fix bug discovered by fuzzing +* [GH-45230](https://github.com/apache/arrow/issues/45230) - [Docs] Add LinkedIn social link and fix top nav scaling problems +* [GH-45283](https://github.com/apache/arrow/issues/45283) - [Python][C++][Parquet] "OSError: Repetition level histogram size mismatch" when reading parquet file in pyarrow since 19.0.0 +* [GH-45296](https://github.com/apache/arrow/issues/45296) - [Python] to\_pandas() fails when pandas option 'future.infer\_string' is True +* [GH-45339](https://github.com/apache/arrow/issues/45339) - [Parquet][C++] Reading parquet with an empty list of row group indices fails +* [GH-45357](https://github.com/apache/arrow/issues/45357) - [C++] Disable failing arrow-flight-test when misusing the library + + +## New Features and Improvements + +* [GH-45201](https://github.com/apache/arrow/issues/45201) - [C++][Parquet] Improve performance of writing size statistics +* [GH-45304](https://github.com/apache/arrow/issues/45304) - [C++] Compatibility with newer aws sdk +* [GH-45305](https://github.com/apache/arrow/issues/45305) - [Python] Compatibility with boto 1.36 + + + # Apache Arrow 19.0.0 (2025-01-10) ## New Features and Improvements From 0a5b4b85778d1adc3148d6d3456d434779ee36b4 Mon Sep 17 00:00:00 2001 From: Bryce Mecum Date: Sun, 2 Feb 2025 18:02:38 -0800 Subject: [PATCH 12/17] MINOR: [Release] Update .deb/.rpm changelogs for 19.0.1 --- .../linux-packages/apache-arrow-apt-source/debian/changelog | 6 ++++++ .../apache-arrow-release/yum/apache-arrow-release.spec.in | 3 +++ dev/tasks/linux-packages/apache-arrow/debian/changelog | 6 ++++++ dev/tasks/linux-packages/apache-arrow/yum/arrow.spec.in | 3 +++ 4 files changed, 18 insertions(+) diff --git a/dev/tasks/linux-packages/apache-arrow-apt-source/debian/changelog b/dev/tasks/linux-packages/apache-arrow-apt-source/debian/changelog index da35e4a4f8de..eb6a6bc37d4c 100644 --- a/dev/tasks/linux-packages/apache-arrow-apt-source/debian/changelog +++ b/dev/tasks/linux-packages/apache-arrow-apt-source/debian/changelog @@ -1,3 +1,9 @@ +apache-arrow-apt-source (19.0.1-1) unstable; urgency=low + + * New upstream release. + + -- Bryce Mecum Mon, 03 Feb 2025 02:02:38 -0000 + apache-arrow-apt-source (19.0.0-1) unstable; urgency=low * New upstream release. diff --git a/dev/tasks/linux-packages/apache-arrow-release/yum/apache-arrow-release.spec.in b/dev/tasks/linux-packages/apache-arrow-release/yum/apache-arrow-release.spec.in index 6f826ad0a360..8c8e95dde69d 100644 --- a/dev/tasks/linux-packages/apache-arrow-release/yum/apache-arrow-release.spec.in +++ b/dev/tasks/linux-packages/apache-arrow-release/yum/apache-arrow-release.spec.in @@ -102,6 +102,9 @@ else fi %changelog +* Mon Feb 03 2025 Bryce Mecum - 19.0.1-1 +- New upstream release. + * Sat Jan 11 2025 Bryce Mecum - 19.0.0-1 - New upstream release. diff --git a/dev/tasks/linux-packages/apache-arrow/debian/changelog b/dev/tasks/linux-packages/apache-arrow/debian/changelog index 10acb10b28ec..e9846c4bbe2d 100644 --- a/dev/tasks/linux-packages/apache-arrow/debian/changelog +++ b/dev/tasks/linux-packages/apache-arrow/debian/changelog @@ -1,3 +1,9 @@ +apache-arrow (19.0.1-1) unstable; urgency=low + + * New upstream release. + + -- Bryce Mecum Mon, 03 Feb 2025 02:02:38 -0000 + apache-arrow (19.0.0-1) unstable; urgency=low * New upstream release. diff --git a/dev/tasks/linux-packages/apache-arrow/yum/arrow.spec.in b/dev/tasks/linux-packages/apache-arrow/yum/arrow.spec.in index 9ca9898fa9b1..0cc9763d5b31 100644 --- a/dev/tasks/linux-packages/apache-arrow/yum/arrow.spec.in +++ b/dev/tasks/linux-packages/apache-arrow/yum/arrow.spec.in @@ -894,6 +894,9 @@ Documentation for Apache Parquet GLib. %endif %changelog +* Mon Feb 03 2025 Bryce Mecum - 19.0.1-1 +- New upstream release. + * Sat Jan 11 2025 Bryce Mecum - 19.0.0-1 - New upstream release. From cbb438ed45debe91e7839ac194456b16c0a9d2be Mon Sep 17 00:00:00 2001 From: Bryce Mecum Date: Sun, 2 Feb 2025 18:02:39 -0800 Subject: [PATCH 13/17] MINOR: [Release] Update versions for 19.0.1 --- c_glib/meson.build | 2 +- c_glib/vcpkg.json | 2 +- ci/scripts/PKGBUILD | 2 +- cpp/CMakeLists.txt | 2 +- cpp/vcpkg.json | 2 +- csharp/Directory.Build.props | 2 +- dev/tasks/homebrew-formulae/apache-arrow-glib.rb | 2 +- dev/tasks/homebrew-formulae/apache-arrow.rb | 2 +- js/package.json | 2 +- matlab/CMakeLists.txt | 2 +- python/CMakeLists.txt | 2 +- python/pyproject.toml | 2 +- r/DESCRIPTION | 2 +- r/NEWS.md | 2 +- r/pkgdown/assets/versions.html | 4 ++-- r/pkgdown/assets/versions.json | 4 ++-- ruby/red-arrow-cuda/lib/arrow-cuda/version.rb | 2 +- ruby/red-arrow-dataset/lib/arrow-dataset/version.rb | 2 +- ruby/red-arrow-flight-sql/lib/arrow-flight-sql/version.rb | 2 +- ruby/red-arrow-flight/lib/arrow-flight/version.rb | 2 +- ruby/red-arrow/lib/arrow/version.rb | 2 +- ruby/red-gandiva/lib/gandiva/version.rb | 2 +- ruby/red-parquet/lib/parquet/version.rb | 2 +- 23 files changed, 25 insertions(+), 25 deletions(-) diff --git a/c_glib/meson.build b/c_glib/meson.build index c668e30e6736..453d38e14cb7 100644 --- a/c_glib/meson.build +++ b/c_glib/meson.build @@ -35,7 +35,7 @@ project('arrow-glib', 'c', 'cpp', # * 22.04: 0.61.2 meson_version: '>=0.53.2') -version = '19.0.0' +version = '19.0.1' if version.endswith('-SNAPSHOT') version_numbers = version.split('-')[0].split('.') version_tag = version.split('-')[1] diff --git a/c_glib/vcpkg.json b/c_glib/vcpkg.json index 88b010d1b3e9..139589ad3ea7 100644 --- a/c_glib/vcpkg.json +++ b/c_glib/vcpkg.json @@ -1,6 +1,6 @@ { "name": "arrow-glib", - "version-string": "19.0.0", + "version-string": "19.0.1", "dependencies": [ "glib", "gobject-introspection", diff --git a/ci/scripts/PKGBUILD b/ci/scripts/PKGBUILD index 792df1376d90..2651f3e9f021 100644 --- a/ci/scripts/PKGBUILD +++ b/ci/scripts/PKGBUILD @@ -18,7 +18,7 @@ _realname=arrow pkgbase=mingw-w64-${_realname} pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}" -pkgver=19.0.0 +pkgver=19.0.1 pkgrel=8000 pkgdesc="Apache Arrow is a cross-language development platform for in-memory data (mingw-w64)" arch=("any") diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 67189526eff7..b2a2731636ad 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -79,7 +79,7 @@ if(POLICY CMP0170) cmake_policy(SET CMP0170 NEW) endif() -set(ARROW_VERSION "19.0.0") +set(ARROW_VERSION "19.0.1") string(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+" ARROW_BASE_VERSION "${ARROW_VERSION}") diff --git a/cpp/vcpkg.json b/cpp/vcpkg.json index 75264a31b849..e9c87c1df0ee 100644 --- a/cpp/vcpkg.json +++ b/cpp/vcpkg.json @@ -1,6 +1,6 @@ { "name": "arrow", - "version-string": "19.0.0", + "version-string": "19.0.1", "dependencies": [ "abseil", { diff --git a/csharp/Directory.Build.props b/csharp/Directory.Build.props index 993ca1a59582..5279fd8c6eac 100644 --- a/csharp/Directory.Build.props +++ b/csharp/Directory.Build.props @@ -29,7 +29,7 @@ Apache Arrow library Copyright 2016-2024 The Apache Software Foundation The Apache Software Foundation - 19.0.0 + 19.0.1 diff --git a/dev/tasks/homebrew-formulae/apache-arrow-glib.rb b/dev/tasks/homebrew-formulae/apache-arrow-glib.rb index 9c6ed8c58742..582361b58545 100644 --- a/dev/tasks/homebrew-formulae/apache-arrow-glib.rb +++ b/dev/tasks/homebrew-formulae/apache-arrow-glib.rb @@ -29,7 +29,7 @@ class ApacheArrowGlib < Formula desc "GLib bindings for Apache Arrow" homepage "https://arrow.apache.org/" - url "https://www.apache.org/dyn/closer.lua?path=arrow/arrow-19.0.0/apache-arrow-19.0.0.tar.gz" + url "https://www.apache.org/dyn/closer.lua?path=arrow/arrow-19.0.1/apache-arrow-19.0.1.tar.gz" sha256 "9948ddb6d4798b51552d0dca3252dd6e3a7d0f9702714fc6f5a1b59397ce1d28" license "Apache-2.0" head "https://github.com/apache/arrow.git", branch: "main" diff --git a/dev/tasks/homebrew-formulae/apache-arrow.rb b/dev/tasks/homebrew-formulae/apache-arrow.rb index 2400461c156b..7f8e8556be5b 100644 --- a/dev/tasks/homebrew-formulae/apache-arrow.rb +++ b/dev/tasks/homebrew-formulae/apache-arrow.rb @@ -29,7 +29,7 @@ class ApacheArrow < Formula desc "Columnar in-memory analytics layer designed to accelerate big data" homepage "https://arrow.apache.org/" - url "https://www.apache.org/dyn/closer.lua?path=arrow/arrow-19.0.0/apache-arrow-19.0.0.tar.gz" + url "https://www.apache.org/dyn/closer.lua?path=arrow/arrow-19.0.1/apache-arrow-19.0.1.tar.gz" sha256 "9948ddb6d4798b51552d0dca3252dd6e3a7d0f9702714fc6f5a1b59397ce1d28" license "Apache-2.0" head "https://github.com/apache/arrow.git", branch: "main" diff --git a/js/package.json b/js/package.json index 7aba1c1fee3a..29b6ae5852e3 100644 --- a/js/package.json +++ b/js/package.json @@ -120,5 +120,5 @@ "engines": { "node": ">=12.0" }, - "version": "19.0.0" + "version": "19.0.1" } diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index fb02a40a771b..c0f0abcf04d4 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -100,7 +100,7 @@ endfunction() set(CMAKE_CXX_STANDARD 17) -set(MLARROW_VERSION "19.0.0") +set(MLARROW_VERSION "19.0.1") string(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+" MLARROW_BASE_VERSION "${MLARROW_VERSION}") project(mlarrow VERSION "${MLARROW_BASE_VERSION}") diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 714c6448453f..58e2cdcf0739 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -28,7 +28,7 @@ project(pyarrow) # which in turn meant that Py_GIL_DISABLED was not set. set(CMAKE_NO_SYSTEM_FROM_IMPORTED ON) -set(PYARROW_VERSION "19.0.0") +set(PYARROW_VERSION "19.0.1") string(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+" PYARROW_BASE_VERSION "${PYARROW_VERSION}") # Generate SO version and full SO version diff --git a/python/pyproject.toml b/python/pyproject.toml index ef2043f6d0b7..212ea926bd65 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -81,4 +81,4 @@ root = '..' version_file = 'pyarrow/_generated_version.py' version_scheme = 'guess-next-dev' git_describe_command = 'git describe --dirty --tags --long --match "apache-arrow-[0-9]*.*"' -fallback_version = '19.0.0' +fallback_version = '19.0.1' diff --git a/r/DESCRIPTION b/r/DESCRIPTION index cd57f9a524a5..a31e832519d7 100644 --- a/r/DESCRIPTION +++ b/r/DESCRIPTION @@ -1,6 +1,6 @@ Package: arrow Title: Integration to 'Apache' 'Arrow' -Version: 19.0.0 +Version: 19.0.1 Authors@R: c( person("Neal", "Richardson", email = "neal.p.richardson@gmail.com", role = c("aut")), person("Ian", "Cook", email = "ianmcook@gmail.com", role = c("aut")), diff --git a/r/NEWS.md b/r/NEWS.md index 437867d3ad48..343ce0547495 100644 --- a/r/NEWS.md +++ b/r/NEWS.md @@ -17,7 +17,7 @@ under the License. --> -# arrow 19.0.0 +# arrow 19.0.1 # arrow 18.1.0 diff --git a/r/pkgdown/assets/versions.html b/r/pkgdown/assets/versions.html index cbeff74fa4ce..db8a97badb97 100644 --- a/r/pkgdown/assets/versions.html +++ b/r/pkgdown/assets/versions.html @@ -1,7 +1,7 @@ -

19.0.0.9000 (dev)

-

19.0.0 (release)

+

19.0.1.9000 (dev)

+

19.0.1 (release)

18.1.0

17.0.0

16.1.0

diff --git a/r/pkgdown/assets/versions.json b/r/pkgdown/assets/versions.json index 105c4d2f3d0e..ea0d663b2a6f 100644 --- a/r/pkgdown/assets/versions.json +++ b/r/pkgdown/assets/versions.json @@ -1,10 +1,10 @@ [ { - "name": "19.0.0.9000 (dev)", + "name": "19.0.1.9000 (dev)", "version": "dev/" }, { - "name": "19.0.0 (release)", + "name": "19.0.1 (release)", "version": "" }, { diff --git a/ruby/red-arrow-cuda/lib/arrow-cuda/version.rb b/ruby/red-arrow-cuda/lib/arrow-cuda/version.rb index 2a659bdca193..4888deb0a169 100644 --- a/ruby/red-arrow-cuda/lib/arrow-cuda/version.rb +++ b/ruby/red-arrow-cuda/lib/arrow-cuda/version.rb @@ -16,7 +16,7 @@ # under the License. module ArrowCUDA - VERSION = "19.0.0" + VERSION = "19.0.1" module Version numbers, TAG = VERSION.split("-") diff --git a/ruby/red-arrow-dataset/lib/arrow-dataset/version.rb b/ruby/red-arrow-dataset/lib/arrow-dataset/version.rb index 9b70cd29321f..71822d8088ff 100644 --- a/ruby/red-arrow-dataset/lib/arrow-dataset/version.rb +++ b/ruby/red-arrow-dataset/lib/arrow-dataset/version.rb @@ -16,7 +16,7 @@ # under the License. module ArrowDataset - VERSION = "19.0.0" + VERSION = "19.0.1" module Version numbers, TAG = VERSION.split("-") diff --git a/ruby/red-arrow-flight-sql/lib/arrow-flight-sql/version.rb b/ruby/red-arrow-flight-sql/lib/arrow-flight-sql/version.rb index f2cd2f517586..f42312670eaa 100644 --- a/ruby/red-arrow-flight-sql/lib/arrow-flight-sql/version.rb +++ b/ruby/red-arrow-flight-sql/lib/arrow-flight-sql/version.rb @@ -16,7 +16,7 @@ # under the License. module ArrowFlightSQL - VERSION = "19.0.0" + VERSION = "19.0.1" module Version numbers, TAG = VERSION.split("-") diff --git a/ruby/red-arrow-flight/lib/arrow-flight/version.rb b/ruby/red-arrow-flight/lib/arrow-flight/version.rb index 70e896ce3d43..e5b58e0b42a6 100644 --- a/ruby/red-arrow-flight/lib/arrow-flight/version.rb +++ b/ruby/red-arrow-flight/lib/arrow-flight/version.rb @@ -16,7 +16,7 @@ # under the License. module ArrowFlight - VERSION = "19.0.0" + VERSION = "19.0.1" module Version numbers, TAG = VERSION.split("-") diff --git a/ruby/red-arrow/lib/arrow/version.rb b/ruby/red-arrow/lib/arrow/version.rb index f369fd223a93..56a1393e4039 100644 --- a/ruby/red-arrow/lib/arrow/version.rb +++ b/ruby/red-arrow/lib/arrow/version.rb @@ -16,7 +16,7 @@ # under the License. module Arrow - VERSION = "19.0.0" + VERSION = "19.0.1" module Version numbers, TAG = VERSION.split("-") diff --git a/ruby/red-gandiva/lib/gandiva/version.rb b/ruby/red-gandiva/lib/gandiva/version.rb index 5226a34f1e01..ea2591701e2d 100644 --- a/ruby/red-gandiva/lib/gandiva/version.rb +++ b/ruby/red-gandiva/lib/gandiva/version.rb @@ -16,7 +16,7 @@ # under the License. module Gandiva - VERSION = "19.0.0" + VERSION = "19.0.1" module Version numbers, TAG = VERSION.split("-") diff --git a/ruby/red-parquet/lib/parquet/version.rb b/ruby/red-parquet/lib/parquet/version.rb index e5c905074416..4109fc404348 100644 --- a/ruby/red-parquet/lib/parquet/version.rb +++ b/ruby/red-parquet/lib/parquet/version.rb @@ -16,7 +16,7 @@ # under the License. module Parquet - VERSION = "19.0.0" + VERSION = "19.0.1" module Version numbers, TAG = VERSION.split("-") From 7722b62f50336ee0b31f17b41acc77c9d6c9fb25 Mon Sep 17 00:00:00 2001 From: Bryce Mecum Date: Mon, 3 Feb 2025 08:20:32 -0800 Subject: [PATCH 14/17] Update header in CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39d3d64cd9ce..fe364eb970c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ * [GH-45357](https://github.com/apache/arrow/issues/45357) - [C++] Disable failing arrow-flight-test when misusing the library -## New Features and Improvements +## Improvements * [GH-45201](https://github.com/apache/arrow/issues/45201) - [C++][Parquet] Improve performance of writing size statistics * [GH-45304](https://github.com/apache/arrow/issues/45304) - [C++] Compatibility with newer aws sdk From d94cf52297a2b0b33229f2d5a141c6c4db3f2d85 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Mon, 20 Jan 2025 13:29:17 +0100 Subject: [PATCH 15/17] GH-45305: [CI][Python] Temporarily avoid newer boto3 version (#45311) Until Minio gets fixed. * GitHub Issue: #45305 Authored-by: Antoine Pitrou Signed-off-by: Antoine Pitrou --- ci/appveyor-cpp-setup.bat | 1 - 1 file changed, 1 deletion(-) diff --git a/ci/appveyor-cpp-setup.bat b/ci/appveyor-cpp-setup.bat index a5ca7f76bd19..ff159bd0b4b5 100644 --- a/ci/appveyor-cpp-setup.bat +++ b/ci/appveyor-cpp-setup.bat @@ -70,7 +70,6 @@ conda create -n arrow ^ "ninja" ^ "nomkl" ^ "pandas" ^ - "fsspec" ^ "python=%PYTHON%" ^ || exit /B conda list -n arrow From 13a63b2197bf5090f2dadd2ba2fc2a954ee2964d Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Wed, 5 Feb 2025 15:44:30 +0100 Subject: [PATCH 16/17] GH-45427: [Python] Fix version comparison in pandas compat for pandas 2.3 dev version (#45428) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Rationale for this change Small follow-up on https://github.com/apache/arrow/pull/45383 to ensure this version comparison also does the right thing for the currently not-yet-released dev version of 2.3.0 * GitHub Issue: #45427 Authored-by: Joris Van den Bossche Signed-off-by: Raúl Cumplido --- python/pyarrow/pandas-shim.pxi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/pyarrow/pandas-shim.pxi b/python/pyarrow/pandas-shim.pxi index aab9cf1079e9..18de584bff83 100644 --- a/python/pyarrow/pandas-shim.pxi +++ b/python/pyarrow/pandas-shim.pxi @@ -79,7 +79,7 @@ cdef class _PandasAPIShim(object): self._is_v1 = self._loose_version < Version('2.0.0') self._is_ge_v21 = self._loose_version >= Version('2.1.0') - self._is_ge_v23 = self._loose_version >= Version('2.3.0') + self._is_ge_v23 = self._loose_version >= Version('2.3.0.dev0') self._is_ge_v3 = self._loose_version >= Version('3.0.0.dev0') self._is_ge_v3_strict = self._loose_version >= Version('3.0.0') From 4a8fdc50bd513fc887be80cc8ffe2f0840d25d09 Mon Sep 17 00:00:00 2001 From: Bryce Mecum Date: Mon, 10 Feb 2025 17:49:34 -0800 Subject: [PATCH 17/17] GH-45295: [Python][CI] Make download_tzdata_on_windows more robust and use tzdata package for tzinfo database on Windows for ORC (#45425) We have two Windows issues and this PR is addressing both: 1. PyArrow's `download_tzdata_on_windows` can fail due to TLS issues in certain CI environments. 2. The Python wheel test infrastructure needs a tzinfo database for ORC and the automation fetching that started failing because the URL was made invalid upstream. These two issues are being solved in one PR simply because they appeared together during the 19.0.1 release process but they're separate. 1. Makes `download_tzdata_on_windows` more robust to TLS errors by attempting to use `requests` if it's available and falling back to urllib otherwise. 2. Switches our Windows wheel test infrastructure to grab a tzinfo database from the tzdata package on PyPi instead of from a mirror URL. This should be much more stable for us over time. Yes. No. * GitHub Issue: #45295 Lead-authored-by: Bryce Mecum Co-authored-by: Joris Van den Bossche Signed-off-by: Bryce Mecum --- ci/scripts/python_wheel_windows_test.bat | 6 ---- python/pyarrow/tests/conftest.py | 16 ++++++++++ python/pyarrow/util.py | 40 +++++++++++++++++------- python/requirements-wheel-test.txt | 1 + 4 files changed, 46 insertions(+), 17 deletions(-) diff --git a/ci/scripts/python_wheel_windows_test.bat b/ci/scripts/python_wheel_windows_test.bat index 12d35216b1ca..dfb8120c3241 100755 --- a/ci/scripts/python_wheel_windows_test.bat +++ b/ci/scripts/python_wheel_windows_test.bat @@ -67,11 +67,5 @@ set PYTHON_CMD=py -%PYTHON% @REM Validate wheel contents %PYTHON_CMD% C:\arrow\ci\scripts\python_wheel_validate_contents.py --path C:\arrow\python\repaired_wheels || exit /B 1 -@rem Download IANA Timezone Database for ORC C++ -curl https://cygwin.osuosl.org/noarch/release/tzdata/tzdata-2024a-1.tar.xz --output tzdata.tar.xz || exit /B -mkdir %USERPROFILE%\Downloads\test\tzdata -arc unarchive tzdata.tar.xz %USERPROFILE%\Downloads\test\tzdata -set TZDIR=%USERPROFILE%\Downloads\test\tzdata\usr\share\zoneinfo - @REM Execute unittest %PYTHON_CMD% -m pytest -r s --pyargs pyarrow || exit /B 1 diff --git a/python/pyarrow/tests/conftest.py b/python/pyarrow/tests/conftest.py index 63518beebae9..53b54bb494da 100644 --- a/python/pyarrow/tests/conftest.py +++ b/python/pyarrow/tests/conftest.py @@ -55,6 +55,22 @@ set_timezone_db_path(tzdata_set_path) +# GH-45295: For ORC, try to populate TZDIR env var from tzdata package resource +# path. +# +# Note this is a different kind of database than what we allow to be set by +# `PYARROW_TZDATA_PATH` and passed to set_timezone_db_path. +if sys.platform == 'win32': + if os.environ.get('TZDIR', None) is None: + from importlib import resources + try: + os.environ['TZDIR'] = os.path.join(resources.files('tzdata'), 'zoneinfo') + except ModuleNotFoundError: + print( + 'Package "tzdata" not found. Not setting TZDIR environment variable.' + ) + + def pytest_addoption(parser): # Create options to selectively enable test groups def bool_env(name, default=None): diff --git a/python/pyarrow/util.py b/python/pyarrow/util.py index 89780da10f7c..5878d1f90262 100644 --- a/python/pyarrow/util.py +++ b/python/pyarrow/util.py @@ -230,6 +230,20 @@ def _break_traceback_cycle_from_frame(frame): refs = frame = this_frame = None +def _download_urllib(url, out_path): + from urllib.request import urlopen + with urlopen(url) as response: + with open(out_path, 'wb') as f: + f.write(response.read()) + + +def _download_requests(url, out_path): + import requests + with requests.get(url) as response: + with open(out_path, 'wb') as f: + f.write(response.content) + + def download_tzdata_on_windows(): r""" Download and extract latest IANA timezone database into the @@ -240,19 +254,23 @@ def download_tzdata_on_windows(): import tarfile + tzdata_url = "https://data.iana.org/time-zones/tzdata-latest.tar.gz" tzdata_path = os.path.expandvars(r"%USERPROFILE%\Downloads\tzdata") - tzdata_compressed = os.path.join(tzdata_path, "tzdata.tar.gz") + tzdata_compressed_path = os.path.join(tzdata_path, "tzdata.tar.gz") + windows_zones_url = "https://raw.githubusercontent.com/unicode-org/cldr/master/common/supplemental/windowsZones.xml" # noqa + windows_zones_path = os.path.join(tzdata_path, "windowsZones.xml") os.makedirs(tzdata_path, exist_ok=True) - from urllib.request import urlopen - with urlopen('https://data.iana.org/time-zones/tzdata-latest.tar.gz') as response: - with open(tzdata_compressed, 'wb') as f: - f.write(response.read()) - - assert os.path.exists(tzdata_compressed) + # Try to download the files with requests and then fall back to urllib. This + # works around possible issues in certain older environment (GH-45295) + try: + _download_requests(tzdata_url, tzdata_compressed_path) + _download_requests(windows_zones_url, windows_zones_path) + except ImportError: + _download_urllib(tzdata_url, tzdata_compressed_path) + _download_urllib(windows_zones_url, windows_zones_path) - tarfile.open(tzdata_compressed).extractall(tzdata_path) + assert os.path.exists(tzdata_compressed_path) + assert os.path.exists(windows_zones_path) - with urlopen('https://raw.githubusercontent.com/unicode-org/cldr/master/common/supplemental/windowsZones.xml') as response_zones: # noqa - with open(os.path.join(tzdata_path, "windowsZones.xml"), 'wb') as f: - f.write(response_zones.read()) + tarfile.open(tzdata_compressed_path).extractall(tzdata_path) diff --git a/python/requirements-wheel-test.txt b/python/requirements-wheel-test.txt index c051efb0aaab..ad81586d37ef 100644 --- a/python/requirements-wheel-test.txt +++ b/python/requirements-wheel-test.txt @@ -4,6 +4,7 @@ hypothesis pytest pytz pyuwsgi; sys.platform != 'win32' and python_version < '3.13' +requests; sys_platform == 'win32' tzdata; sys_platform == 'win32' # We generally test with the oldest numpy version that supports a given Python