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

[PR] GH-38860: [C++][Parquet] Using length to optimize bloom filter read [arrow]

mapleFU opened a new pull request, #38863:
URL: https://github.com/apache/arrow/pull/38863

   <!--
   Thanks for opening a pull request!
   If this is your first pull request you can find detailed information on how 
   to contribute here:
     * [New Contributor's Guide](https://arrow.apache.org/docs/dev/developers/guide/step_by_step/pr_lifecycle.html#reviews-and-merge-of-the-pull-request)
     * [Contributing Overview](https://arrow.apache.org/docs/dev/developers/overview.html)
   
   
   If this is not a [minor PR](https://github.com/apache/arrow/blob/main/CONTRIBUTING.md#Minor-Fixes). Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose
   
   Opening GitHub issues ahead of time contributes to the [Openness](http://theapacheway.com/open/#:~:text=Openness%20allows%20new%20users%20the,must%20happen%20in%20the%20open.) of the Apache Arrow project.
   
   Then could you also rename the pull request title in the following format?
   
       GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
   
   or
   
       MINOR: [${COMPONENT}] ${SUMMARY}
   
   In the case of PARQUET issues on JIRA the title also supports:
   
       PARQUET-${JIRA_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
   
   -->
   
   ### Rationale for this change
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   Parquet supports a bloom_filter_length in 2.10[1]. We'd like to using this length for read.
   
   The current implemention [2] using the code below:
   
   1. Using a "guessed" header length to read the header. The header is likely to be 40B, but we use a larger value to avoid it evolves
   2. From the header, we get the bloom filter length, and load it from input.
   
   Now, we can directly load the whole bloom-filter, without reading twice. We shouldn't remove the stale code because we need to read the stale file.
   
   We also need to generate a new parquet-testing file ( I can do this ASAP )
   
   [1] https://github.com/apache/parquet-format/blob/master/src/main/thrift/parquet.thrift#L824
   [2] https://github.com/apache/arrow/blob/main/cpp/src/parquet/bloom_filter.cc#L117
   
   ### What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   * [x] Support Basic read with `bloom_filter_length`
   * [x] Enhance the JsonPrinter
   * [ ] testing
   
   ### Are these changes tested?
   
   * [ ] testing using parquet-testing
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   ### Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please uncomment the line below and explain which changes are breaking.
   -->
   <!-- **This PR includes breaking changes to public APIs.** -->
   
   <!--
   Please uncomment the line below (and provide explanation) if the changes fix either (a) a security vulnerability, (b) a bug that caused incorrect or invalid data to be produced, or (c) a bug that causes a crash (even when the API contract is upheld). We use this to highlight fixes to issues that may affect users without their knowledge. For this reason, fixing bugs that cause errors don't count, since those are usually obvious.
   -->
   <!-- **This PR contains a "Critical Fix".** -->


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-38860: [C++][Parquet] Using length to optimize bloom filter read [arrow]

Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #38863:
URL: https://github.com/apache/arrow/pull/38863#discussion_r1404377372


##########
cpp/src/parquet/bloom_filter.cc:
##########
@@ -105,16 +105,24 @@ static ::arrow::Status ValidateBloomFilterHeader(
 }
 
 BlockSplitBloomFilter BlockSplitBloomFilter::Deserialize(
-    const ReaderProperties& properties, ArrowInputStream* input) {
-  // NOTE: we don't know the bloom filter header size upfront, and we can't rely on
-  // InputStream::Peek() which isn't always implemented. Therefore, we must first
-  // Read() with an upper bound estimate of the header size, then once we know
-  // the bloom filter data size, we can Read() the exact number of remaining data bytes.
+    const ReaderProperties& properties, ArrowInputStream* input,
+    std::optional<int64_t> bloom_filter_length) {
   ThriftDeserializer deserializer(properties);
   format::BloomFilterHeader header;
+  int64_t bloom_filter_header_read_size = 0;
+  if (bloom_filter_length.has_value()) {
+    bloom_filter_header_read_size = bloom_filter_length.value();
+  } else {
+    // NOTE: we don't know the bloom filter header size upfront without
+    // bloom_filter_length, and we can't rely on InputStream::Peek() which isn't always
+    // implemented. Therefore, we must first Read() with an upper bound estimate of the
+    // header size, then once we know the bloom filter data size, we can Read() the exact
+    // number of remaining data bytes.
+    bloom_filter_header_read_size = kBloomFilterHeaderSizeGuess;
+  }
 
   // Read and deserialize bloom filter header
-  PARQUET_ASSIGN_OR_THROW(auto header_buf, input->Read(kBloomFilterHeaderSizeGuess));
+  PARQUET_ASSIGN_OR_THROW(auto header_buf, input->Read(bloom_filter_header_read_size));
   // This gets used, then set by DeserializeThriftMsg
   uint32_t header_size = static_cast<uint32_t>(header_buf->size());
   try {

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-38860: [C++][Parquet] Using length to optimize bloom filter read [arrow]

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #38863:
URL: https://github.com/apache/arrow/pull/38863#discussion_r1409071192


##########
cpp/src/parquet/bloom_filter.cc:
##########
@@ -136,6 +144,15 @@ BlockSplitBloomFilter BlockSplitBloomFilter::Deserialize(
     bloom_filter.Init(header_buf->data() + header_size, bloom_filter_size);
     return bloom_filter;
   }
+  if (bloom_filter_length && *bloom_filter_length < bloom_filter_size + header_size) {

Review Comment:
   The code is getting a bit confusing with `bloom_filter_length` vs. `bloom_filter_size`. Perhaps rename the latter to `bloom_filter_data_size`?



##########
cpp/src/parquet/bloom_filter_reader_test.cc:
##########
@@ -25,31 +25,41 @@
 namespace parquet::test {
 
 TEST(BloomFilterReader, ReadBloomFilter) {
-  std::string dir_string(parquet::test::get_data_dir());
-  std::string path = dir_string + "/data_index_bloom_encoding_stats.parquet";
-  auto reader = ParquetFileReader::OpenFile(path, false);
-  auto file_metadata = reader->metadata();
-  EXPECT_FALSE(file_metadata->is_encryption_algorithm_set());
-  auto& bloom_filter_reader = reader->GetBloomFilterReader();
-  auto row_group_0 = bloom_filter_reader.RowGroup(0);
-  ASSERT_NE(nullptr, row_group_0);
-  EXPECT_THROW(bloom_filter_reader.RowGroup(1), ParquetException);
-  auto bloom_filter = row_group_0->GetColumnBloomFilter(0);
-  ASSERT_NE(nullptr, bloom_filter);
-  EXPECT_THROW(row_group_0->GetColumnBloomFilter(1), ParquetException);
+  struct BloomFilterTestFile {
+    std::string filename;
+    bool has_bloom_filter_length;
+  };
+  std::vector<BloomFilterTestFile> files = {
+      {"data_index_bloom_encoding_stats.parquet", false},
+      {"data_index_bloom_encoding_with_length.parquet", false},

Review Comment:
   Why `false` here?



##########
cpp/src/parquet/bloom_filter_reader_test.cc:
##########
@@ -25,31 +25,41 @@
 namespace parquet::test {
 
 TEST(BloomFilterReader, ReadBloomFilter) {
-  std::string dir_string(parquet::test::get_data_dir());
-  std::string path = dir_string + "/data_index_bloom_encoding_stats.parquet";
-  auto reader = ParquetFileReader::OpenFile(path, false);
-  auto file_metadata = reader->metadata();
-  EXPECT_FALSE(file_metadata->is_encryption_algorithm_set());
-  auto& bloom_filter_reader = reader->GetBloomFilterReader();
-  auto row_group_0 = bloom_filter_reader.RowGroup(0);
-  ASSERT_NE(nullptr, row_group_0);
-  EXPECT_THROW(bloom_filter_reader.RowGroup(1), ParquetException);
-  auto bloom_filter = row_group_0->GetColumnBloomFilter(0);
-  ASSERT_NE(nullptr, bloom_filter);
-  EXPECT_THROW(row_group_0->GetColumnBloomFilter(1), ParquetException);
+  struct BloomFilterTestFile {
+    std::string filename;
+    bool has_bloom_filter_length;
+  };
+  std::vector<BloomFilterTestFile> files = {
+      {"data_index_bloom_encoding_stats.parquet", false},
+      {"data_index_bloom_encoding_with_length.parquet", false},
+  };
+  for (const auto& test_file : files) {
+    std::string dir_string(parquet::test::get_data_dir());
+    std::string path = dir_string + "/" + test_file.filename;
+    auto reader = ParquetFileReader::OpenFile(path, false);

Review Comment:
   What is `false` here? Let's make code more readable.
   ```suggestion
       auto reader = ParquetFileReader::OpenFile(path, /*xxx=*/false);
   ```



##########
cpp/src/parquet/bloom_filter_reader_test.cc:
##########
@@ -25,31 +25,41 @@
 namespace parquet::test {
 
 TEST(BloomFilterReader, ReadBloomFilter) {
-  std::string dir_string(parquet::test::get_data_dir());
-  std::string path = dir_string + "/data_index_bloom_encoding_stats.parquet";
-  auto reader = ParquetFileReader::OpenFile(path, false);
-  auto file_metadata = reader->metadata();
-  EXPECT_FALSE(file_metadata->is_encryption_algorithm_set());
-  auto& bloom_filter_reader = reader->GetBloomFilterReader();
-  auto row_group_0 = bloom_filter_reader.RowGroup(0);
-  ASSERT_NE(nullptr, row_group_0);
-  EXPECT_THROW(bloom_filter_reader.RowGroup(1), ParquetException);
-  auto bloom_filter = row_group_0->GetColumnBloomFilter(0);
-  ASSERT_NE(nullptr, bloom_filter);
-  EXPECT_THROW(row_group_0->GetColumnBloomFilter(1), ParquetException);
+  struct BloomFilterTestFile {
+    std::string filename;
+    bool has_bloom_filter_length;
+  };
+  std::vector<BloomFilterTestFile> files = {
+      {"data_index_bloom_encoding_stats.parquet", false},
+      {"data_index_bloom_encoding_with_length.parquet", false},
+  };
+  for (const auto& test_file : files) {
+    std::string dir_string(parquet::test::get_data_dir());
+    std::string path = dir_string + "/" + test_file.filename;
+    auto reader = ParquetFileReader::OpenFile(path, false);
+    auto file_metadata = reader->metadata();
+    EXPECT_FALSE(file_metadata->is_encryption_algorithm_set());
+    auto& bloom_filter_reader = reader->GetBloomFilterReader();
+    auto row_group_0 = bloom_filter_reader.RowGroup(0);
+    ASSERT_NE(nullptr, row_group_0);
+    EXPECT_THROW(bloom_filter_reader.RowGroup(1), ParquetException);
+    auto bloom_filter = row_group_0->GetColumnBloomFilter(0);
+    ASSERT_NE(nullptr, bloom_filter);
+    EXPECT_THROW(row_group_0->GetColumnBloomFilter(1), ParquetException);

Review Comment:
   Same question here.



##########
cpp/src/parquet/bloom_filter_reader_test.cc:
##########
@@ -25,31 +25,41 @@
 namespace parquet::test {
 
 TEST(BloomFilterReader, ReadBloomFilter) {
-  std::string dir_string(parquet::test::get_data_dir());
-  std::string path = dir_string + "/data_index_bloom_encoding_stats.parquet";
-  auto reader = ParquetFileReader::OpenFile(path, false);
-  auto file_metadata = reader->metadata();
-  EXPECT_FALSE(file_metadata->is_encryption_algorithm_set());
-  auto& bloom_filter_reader = reader->GetBloomFilterReader();
-  auto row_group_0 = bloom_filter_reader.RowGroup(0);
-  ASSERT_NE(nullptr, row_group_0);
-  EXPECT_THROW(bloom_filter_reader.RowGroup(1), ParquetException);
-  auto bloom_filter = row_group_0->GetColumnBloomFilter(0);
-  ASSERT_NE(nullptr, bloom_filter);
-  EXPECT_THROW(row_group_0->GetColumnBloomFilter(1), ParquetException);
+  struct BloomFilterTestFile {
+    std::string filename;
+    bool has_bloom_filter_length;
+  };
+  std::vector<BloomFilterTestFile> files = {
+      {"data_index_bloom_encoding_stats.parquet", false},
+      {"data_index_bloom_encoding_with_length.parquet", false},
+  };
+  for (const auto& test_file : files) {
+    std::string dir_string(parquet::test::get_data_dir());
+    std::string path = dir_string + "/" + test_file.filename;
+    auto reader = ParquetFileReader::OpenFile(path, false);
+    auto file_metadata = reader->metadata();
+    EXPECT_FALSE(file_metadata->is_encryption_algorithm_set());
+    auto& bloom_filter_reader = reader->GetBloomFilterReader();
+    auto row_group_0 = bloom_filter_reader.RowGroup(0);
+    ASSERT_NE(nullptr, row_group_0);
+    EXPECT_THROW(bloom_filter_reader.RowGroup(1), ParquetException);

Review Comment:
   Why does it throw? Is it possible to check the exception message, or at least add a comment?



##########
cpp/src/parquet/bloom_filter.cc:
##########
@@ -136,6 +144,15 @@ BlockSplitBloomFilter BlockSplitBloomFilter::Deserialize(
     bloom_filter.Init(header_buf->data() + header_size, bloom_filter_size);
     return bloom_filter;
   }
+  if (bloom_filter_length && *bloom_filter_length < bloom_filter_size + header_size) {

Review Comment:
   Also, why the inequality? We should have `*bloom_filter_length == bloom_filter_data_size + header_size`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-38860: [C++][Parquet] Using length to optimize bloom filter read [arrow]

Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on PR #38863:
URL: https://github.com/apache/arrow/pull/38863#issuecomment-1827117993

   Also cc @emkornfield 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-38860: [C++][Parquet] Using length to optimize bloom filter read [arrow]

Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #38863:
URL: https://github.com/apache/arrow/pull/38863#discussion_r1409118921


##########
cpp/src/parquet/bloom_filter.cc:
##########
@@ -136,6 +144,15 @@ BlockSplitBloomFilter BlockSplitBloomFilter::Deserialize(
     bloom_filter.Init(header_buf->data() + header_size, bloom_filter_size);
     return bloom_filter;
   }
+  if (bloom_filter_length && *bloom_filter_length < bloom_filter_size + header_size) {

Review Comment:
   Checked now



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-38860: [C++][Parquet] Using length to optimize bloom filter read [arrow]

Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #38863:
URL: https://github.com/apache/arrow/pull/38863#discussion_r1409119364


##########
cpp/src/parquet/bloom_filter_reader_test.cc:
##########
@@ -25,31 +25,41 @@
 namespace parquet::test {
 
 TEST(BloomFilterReader, ReadBloomFilter) {
-  std::string dir_string(parquet::test::get_data_dir());
-  std::string path = dir_string + "/data_index_bloom_encoding_stats.parquet";
-  auto reader = ParquetFileReader::OpenFile(path, false);
-  auto file_metadata = reader->metadata();
-  EXPECT_FALSE(file_metadata->is_encryption_algorithm_set());
-  auto& bloom_filter_reader = reader->GetBloomFilterReader();
-  auto row_group_0 = bloom_filter_reader.RowGroup(0);
-  ASSERT_NE(nullptr, row_group_0);
-  EXPECT_THROW(bloom_filter_reader.RowGroup(1), ParquetException);
-  auto bloom_filter = row_group_0->GetColumnBloomFilter(0);
-  ASSERT_NE(nullptr, bloom_filter);
-  EXPECT_THROW(row_group_0->GetColumnBloomFilter(1), ParquetException);
+  struct BloomFilterTestFile {
+    std::string filename;
+    bool has_bloom_filter_length;
+  };
+  std::vector<BloomFilterTestFile> files = {
+      {"data_index_bloom_encoding_stats.parquet", false},
+      {"data_index_bloom_encoding_with_length.parquet", false},

Review Comment:
   Hmmm this is unused, because it will handled by `BloomFilterReader` internal



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-38860: [C++][Parquet] Using length to optimize bloom filter read [arrow]

Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #38863:
URL: https://github.com/apache/arrow/pull/38863#discussion_r1403915078


##########
cpp/src/parquet/bloom_filter_reader.cc:
##########
@@ -63,9 +63,16 @@ std::unique_ptr<BloomFilter> RowGroupBloomFilterReaderImpl::GetColumnBloomFilter
   if (file_size <= *bloom_filter_offset) {
     throw ParquetException("file size less or equal than bloom offset");
   }
+  std::optional<int64_t> bloom_filter_length = col_chunk->bloom_filter_length();
+  if (bloom_filter_length.has_value() &&
+      *bloom_filter_length + *bloom_filter_offset > file_size) {
+    throw ParquetException(
+        "bloom filter length + bloom filter offset greater than file size");
+  }

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-38860: [C++][Parquet] Using length to optimize bloom filter read [arrow]

Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #38863:
URL: https://github.com/apache/arrow/pull/38863#discussion_r1409081601


##########
cpp/src/parquet/bloom_filter.cc:
##########
@@ -136,6 +144,15 @@ BlockSplitBloomFilter BlockSplitBloomFilter::Deserialize(
     bloom_filter.Init(header_buf->data() + header_size, bloom_filter_size);
     return bloom_filter;
   }
+  if (bloom_filter_length && *bloom_filter_length < bloom_filter_size + header_size) {

Review Comment:
   They should be equal. let me check them



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-38860: [C++][Parquet] Using length to optimize bloom filter read [arrow]

Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #38863:
URL: https://github.com/apache/arrow/pull/38863#discussion_r1403914664


##########
cpp/src/parquet/bloom_filter.cc:
##########
@@ -105,16 +105,24 @@ static ::arrow::Status ValidateBloomFilterHeader(
 }
 
 BlockSplitBloomFilter BlockSplitBloomFilter::Deserialize(
-    const ReaderProperties& properties, ArrowInputStream* input) {
-  // NOTE: we don't know the bloom filter header size upfront, and we can't rely on
-  // InputStream::Peek() which isn't always implemented. Therefore, we must first
-  // Read() with an upper bound estimate of the header size, then once we know
-  // the bloom filter data size, we can Read() the exact number of remaining data bytes.
+    const ReaderProperties& properties, ArrowInputStream* input,
+    std::optional<int64_t> bloom_filter_length) {
   ThriftDeserializer deserializer(properties);
   format::BloomFilterHeader header;
+  int64_t bloom_filter_header_read_size = 0;
+  if (bloom_filter_length.has_value()) {
+    bloom_filter_header_read_size = bloom_filter_length.value();
+  } else {
+    // NOTE: we don't know the bloom filter header size upfront without
+    // bloom_filter_length, and we can't rely on InputStream::Peek() which isn't always
+    // implemented. Therefore, we must first Read() with an upper bound estimate of the
+    // header size, then once we know the bloom filter data size, we can Read() the exact
+    // number of remaining data bytes.
+    bloom_filter_header_read_size = kBloomFilterHeaderSizeGuess;
+  }
 
   // Read and deserialize bloom filter header
-  PARQUET_ASSIGN_OR_THROW(auto header_buf, input->Read(kBloomFilterHeaderSizeGuess));
+  PARQUET_ASSIGN_OR_THROW(auto header_buf, input->Read(bloom_filter_header_read_size));
   // This gets used, then set by DeserializeThriftMsg
   uint32_t header_size = static_cast<uint32_t>(header_buf->size());
   try {

Review Comment:
   I think it's ok but it make things more complex.
   
   ```
     /// \brief Read data from current file position.
     ///
     /// Read at most `nbytes` from the current file position. Less bytes may
     /// be read if EOF is reached. This method updates the current file position.
     ///
     /// In some cases (e.g. a memory-mapped file), this method may avoid a
     /// memory copy.
     virtual Result<std::shared_ptr<Buffer>> Read(int64_t nbytes) = 0;
   ```
   
   `Read` just think it will read at-most `nbytes`. Checking length is ok but it might making impl complex if we just read less than nbytes?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-38860: [C++][Parquet] Using length to optimize bloom filter read [arrow]

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on PR #38863:
URL: https://github.com/apache/arrow/pull/38863#issuecomment-1831847652

   Thank you @mapleFU !


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-38860: [C++][Parquet] Using length to optimize bloom filter read [arrow]

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #38863:
URL: https://github.com/apache/arrow/pull/38863#discussion_r1409217559


##########
cpp/src/parquet/bloom_filter.cc:
##########
@@ -136,6 +144,14 @@ BlockSplitBloomFilter BlockSplitBloomFilter::Deserialize(
     bloom_filter.Init(header_buf->data() + header_size, bloom_filter_size);
     return bloom_filter;
   }
+  if (bloom_filter_length && *bloom_filter_length != bloom_filter_size + header_size) {
+    // We know the bloom filter data size, but the real size is different.
+    std::stringstream ss;
+    ss << "Bloom filter length (" << bloom_filter_length.value()
+       << ") is not enough to read the entire bloom filter (size: "
+       << bloom_filter_size + header_size << ").";

Review Comment:
   ```suggestion
       ss << "Bloom filter length (" << bloom_filter_length.value()
          << ") does not match the actual bloom filter (size: "
          << bloom_filter_size + header_size << ").";
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-38860: [C++][Parquet] Using length to optimize bloom filter read [arrow]

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou merged PR #38863:
URL: https://github.com/apache/arrow/pull/38863


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-38860: [C++][Parquet] Using length to optimize bloom filter read [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #38863:
URL: https://github.com/apache/arrow/pull/38863#issuecomment-1824367126

   :warning: GitHub issue #38860 **has been automatically assigned in GitHub** to PR creator.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-38860: [C++][Parquet] Using length to optimize bloom filter read [arrow]

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #38863:
URL: https://github.com/apache/arrow/pull/38863#discussion_r1403503630


##########
cpp/src/parquet/bloom_filter_reader.cc:
##########
@@ -63,9 +63,16 @@ std::unique_ptr<BloomFilter> RowGroupBloomFilterReaderImpl::GetColumnBloomFilter
   if (file_size <= *bloom_filter_offset) {
     throw ParquetException("file size less or equal than bloom offset");
   }
+  std::optional<int64_t> bloom_filter_length = col_chunk->bloom_filter_length();
+  if (bloom_filter_length.has_value() &&
+      *bloom_filter_length + *bloom_filter_offset > file_size) {
+    throw ParquetException(
+        "bloom filter length + bloom filter offset greater than file size");
+  }

Review Comment:
   Also check that `bloom_filter_length` is >= 0?



##########
cpp/src/parquet/bloom_filter.cc:
##########
@@ -105,16 +105,24 @@ static ::arrow::Status ValidateBloomFilterHeader(
 }
 
 BlockSplitBloomFilter BlockSplitBloomFilter::Deserialize(
-    const ReaderProperties& properties, ArrowInputStream* input) {
-  // NOTE: we don't know the bloom filter header size upfront, and we can't rely on
-  // InputStream::Peek() which isn't always implemented. Therefore, we must first
-  // Read() with an upper bound estimate of the header size, then once we know
-  // the bloom filter data size, we can Read() the exact number of remaining data bytes.
+    const ReaderProperties& properties, ArrowInputStream* input,
+    std::optional<int64_t> bloom_filter_length) {
   ThriftDeserializer deserializer(properties);
   format::BloomFilterHeader header;
+  int64_t bloom_filter_header_read_size = 0;
+  if (bloom_filter_length.has_value()) {
+    bloom_filter_header_read_size = bloom_filter_length.value();
+  } else {
+    // NOTE: we don't know the bloom filter header size upfront without
+    // bloom_filter_length, and we can't rely on InputStream::Peek() which isn't always
+    // implemented. Therefore, we must first Read() with an upper bound estimate of the
+    // header size, then once we know the bloom filter data size, we can Read() the exact
+    // number of remaining data bytes.
+    bloom_filter_header_read_size = kBloomFilterHeaderSizeGuess;
+  }
 
   // Read and deserialize bloom filter header
-  PARQUET_ASSIGN_OR_THROW(auto header_buf, input->Read(kBloomFilterHeaderSizeGuess));
+  PARQUET_ASSIGN_OR_THROW(auto header_buf, input->Read(bloom_filter_header_read_size));
   // This gets used, then set by DeserializeThriftMsg
   uint32_t header_size = static_cast<uint32_t>(header_buf->size());
   try {

Review Comment:
   Can we also validate `bloom_filter_size` below?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-38860: [C++][Parquet] Using length to optimize bloom filter read [arrow]

Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #38863:
URL: https://github.com/apache/arrow/pull/38863#issuecomment-1833959028

   After merging your PR, Conbench analyzed the 6 benchmarking runs that have been run so far on merge-commit be1dcdb96b030639c0b56955c4c62f9d6b03f473.
   
   There were 3 benchmark results indicating a performance regression:
   
   - Commit Run on `ursa-i9-9960x` at [2023-11-30 12:41:02Z](https://conbench.ursa.dev/compare/runs/53ee5493b1d741bfb74ab6270f94a19f...b6ae5f571c074172992837e47140dfe9/)
     - [`file-read` (R) with compression=lz4, dataset=nyctaxi_2010-01, file_type=feather, language=R, output_type=table](https://conbench.ursa.dev/compare/benchmarks/0656867aac4579c680005f524655f4f6...06568913c46974bd800014d756448136)
     - [`file-read` (R) with compression=lz4, dataset=nyctaxi_2010-01, file_type=feather, language=R, output_type=dataframe](https://conbench.ursa.dev/compare/benchmarks/0656867b764276968000002fdebf9026...06568914fd8076e680008857891616cc)
   - and 1 more (see the report linked below)
   
   The [full Conbench report](https://github.com/apache/arrow/runs/19184301550) has more details. It also includes information about 4 possible false positives for unstable benchmarks that are known to sometimes produce them.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-38860: [C++][Parquet] Using length to optimize bloom filter read [arrow]

Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on PR #38863:
URL: https://github.com/apache/arrow/pull/38863#issuecomment-1831235118

   @pitrou I've resolved the comments, would you mind take a look?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-38860: [C++][Parquet] Using length to optimize bloom filter read [arrow]

Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #38863:
URL: https://github.com/apache/arrow/pull/38863#discussion_r1403940197


##########
cpp/src/parquet/bloom_filter.cc:
##########
@@ -105,16 +105,24 @@ static ::arrow::Status ValidateBloomFilterHeader(
 }
 
 BlockSplitBloomFilter BlockSplitBloomFilter::Deserialize(
-    const ReaderProperties& properties, ArrowInputStream* input) {
-  // NOTE: we don't know the bloom filter header size upfront, and we can't rely on
-  // InputStream::Peek() which isn't always implemented. Therefore, we must first
-  // Read() with an upper bound estimate of the header size, then once we know
-  // the bloom filter data size, we can Read() the exact number of remaining data bytes.
+    const ReaderProperties& properties, ArrowInputStream* input,
+    std::optional<int64_t> bloom_filter_length) {
   ThriftDeserializer deserializer(properties);
   format::BloomFilterHeader header;
+  int64_t bloom_filter_header_read_size = 0;
+  if (bloom_filter_length.has_value()) {
+    bloom_filter_header_read_size = bloom_filter_length.value();
+  } else {
+    // NOTE: we don't know the bloom filter header size upfront without
+    // bloom_filter_length, and we can't rely on InputStream::Peek() which isn't always
+    // implemented. Therefore, we must first Read() with an upper bound estimate of the
+    // header size, then once we know the bloom filter data size, we can Read() the exact
+    // number of remaining data bytes.
+    bloom_filter_header_read_size = kBloomFilterHeaderSizeGuess;
+  }
 
   // Read and deserialize bloom filter header
-  PARQUET_ASSIGN_OR_THROW(auto header_buf, input->Read(kBloomFilterHeaderSizeGuess));
+  PARQUET_ASSIGN_OR_THROW(auto header_buf, input->Read(bloom_filter_header_read_size));
   // This gets used, then set by DeserializeThriftMsg
   uint32_t header_size = static_cast<uint32_t>(header_buf->size());
   try {

Review Comment:
   Perhaps check `header_size + header.numBytes <= bloom_filter_length.value()`? 



##########
cpp/src/parquet/bloom_filter.h:
##########
@@ -311,9 +311,12 @@ class PARQUET_EXPORT BlockSplitBloomFilter : public BloomFilter {
   ///
   /// @param properties The parquet reader properties.
   /// @param input_stream The input stream from which to construct the Bloom filter.
+  /// @param bloom_filter_length The length of the Serialized Bloom filter including

Review Comment:
   ```suggestion
     /// @param bloom_filter_length The length of the serialized bloom filter including
   ```
   
   The capitalization of `Bloom` in the above line also looks strange to me. It would either be `Bloom Filter` or `bloom filter`.



##########
cpp/src/parquet/printer.cc:
##########
@@ -314,6 +314,34 @@ void ParquetFilePrinter::JSONPrint(std::ostream& stream, std::list<int> selected
              << "\"UncompressedSize\": \"" << column_chunk->total_uncompressed_size()
              << "\", \"CompressedSize\": \"" << column_chunk->total_compressed_size();
 
+      if (column_chunk->bloom_filter_offset()) {
+        // Output BloomFilter {offset, length}
+        stream << "\", BloomFilter {"
+               << "\"offset\": \"" << column_chunk->bloom_filter_offset().value();
+        if (column_chunk->bloom_filter_length()) {
+          stream << "\", \"length\": \"" << column_chunk->bloom_filter_length().value();
+        }
+        stream << "\"}";
+      }
+
+      if (column_chunk->GetOffsetIndexLocation()) {
+        auto location = column_chunk->GetOffsetIndexLocation().value();
+        // Output OffsetIndex {offset, length}
+        stream << "\", OffsetIndex {"
+               << "\"offset\": \"" << location.offset;
+        stream << "\", \"length\": \"" << location.length;
+        stream << "\"}";
+      }
+
+      if (column_chunk->GetColumnIndexLocation()) {

Review Comment:
   Should we put ColumnIndex before OffsetIndex? At least in most implementations, their offsets are ordered as ColumnIndex, OffsetIndex and BloomFilter



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

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


Re: [PR] GH-38860: [C++][Parquet] Using length to optimize bloom filter read [arrow]

Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #38863:
URL: https://github.com/apache/arrow/pull/38863#discussion_r1404369051


##########
cpp/src/parquet/printer.cc:
##########
@@ -314,6 +314,34 @@ void ParquetFilePrinter::JSONPrint(std::ostream& stream, std::list<int> selected
              << "\"UncompressedSize\": \"" << column_chunk->total_uncompressed_size()
              << "\", \"CompressedSize\": \"" << column_chunk->total_compressed_size();
 
+      if (column_chunk->bloom_filter_offset()) {
+        // Output BloomFilter {offset, length}
+        stream << "\", BloomFilter {"
+               << "\"offset\": \"" << column_chunk->bloom_filter_offset().value();
+        if (column_chunk->bloom_filter_length()) {
+          stream << "\", \"length\": \"" << column_chunk->bloom_filter_length().value();
+        }
+        stream << "\"}";
+      }
+
+      if (column_chunk->GetOffsetIndexLocation()) {
+        auto location = column_chunk->GetOffsetIndexLocation().value();
+        // Output OffsetIndex {offset, length}
+        stream << "\", OffsetIndex {"
+               << "\"offset\": \"" << location.offset;
+        stream << "\", \"length\": \"" << location.length;
+        stream << "\"}";
+      }
+
+      if (column_chunk->GetColumnIndexLocation()) {

Review Comment:
   Aha...I don't know this



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

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