You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "wgtmac (via GitHub)" <gi...@apache.org> on 2023/03/25 13:59:57 UTC

[GitHub] [arrow] wgtmac commented on a diff in pull request #34728: GH-34665: [Parquet][C++] Allow Reading BloomFilter

wgtmac commented on code in PR #34728:
URL: https://github.com/apache/arrow/pull/34728#discussion_r1148373819


##########
cpp/src/parquet/bloom_filter_reader.h:
##########
@@ -0,0 +1,51 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#pragma once
+
+#include "parquet/bloom_filter.h"
+#include "parquet/encryption/internal_file_decryptor.h"
+
+namespace parquet {
+
+class PARQUET_EXPORT RowGroupBloomFilterReader {
+ public:
+  virtual ~RowGroupBloomFilterReader() = default;
+
+  virtual std::unique_ptr<BloomFilter> GetColumnBloomFilter(int i) = 0;
+};
+
+/// \brief Interface for reading the bloom filter for a Parquet file.
+class PARQUET_EXPORT BloomFilterReader {
+ public:
+  virtual ~BloomFilterReader() = default;
+
+  /// \brief Create a BloomFilterReader instance.
+  /// \returns a BloomFilterReader instance.
+  /// WARNING: The returned BloomFilterReader references to all the input parameters, so
+  /// it must not outlive all of the input parameters. Usually these input parameters
+  /// come from the same ParquetFileReader object, so it must not outlive the reader
+  /// that creates this BloomFilterReader.
+  static std::shared_ptr<BloomFilterReader> Make(
+      std::shared_ptr<::arrow::io::RandomAccessFile> input,
+      std::shared_ptr<FileMetaData> file_metadata, const ReaderProperties& properties,
+      std::shared_ptr<InternalFileDecryptor> file_decryptor = NULLPTR);
+
+  virtual std::shared_ptr<RowGroupBloomFilterReader> RowGroup(int i) = 0;

Review Comment:
   Please add doc string for the public api.



##########
cpp/src/parquet/bloom_filter_reader.cc:
##########
@@ -0,0 +1,114 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "parquet/bloom_filter_reader.h"
+#include "metadata.h"
+#include "parquet/exception.h"
+
+namespace parquet {
+
+class RowGroupBloomFilterReaderImpl final : public RowGroupBloomFilterReader {
+ public:
+  RowGroupBloomFilterReaderImpl(std::shared_ptr<::arrow::io::RandomAccessFile> input,
+                                std::shared_ptr<RowGroupMetaData> row_group_metadata,
+                                const ReaderProperties& properties)
+      : input_(std::move(input)),
+        row_group_metadata_(std::move(row_group_metadata)),
+        properties_(properties) {}
+
+  std::unique_ptr<BloomFilter> GetColumnBloomFilter(int i) override;
+
+ private:
+  /// The input stream that can perform random access read.
+  std::shared_ptr<::arrow::io::RandomAccessFile> input_;
+
+  /// The row group metadata to get column chunk metadata.
+  std::shared_ptr<RowGroupMetaData> row_group_metadata_;
+
+  /// Reader properties used to deserialize thrift object.
+  const ReaderProperties& properties_;
+};
+
+std::unique_ptr<BloomFilter> RowGroupBloomFilterReaderImpl::GetColumnBloomFilter(int i) {
+  if (i < 0 || i >= row_group_metadata_->num_columns()) {
+    throw ParquetException("Invalid column index at column ordinal ", i);
+  }
+
+  auto col_chunk = row_group_metadata_->ColumnChunk(i);
+  std::unique_ptr<ColumnCryptoMetaData> crypto_metadata = col_chunk->crypto_metadata();
+  if (crypto_metadata != nullptr) {
+    ParquetException::NYI("Cannot read encrypted bloom filter yet");
+  }
+
+  auto bloom_filter_offset = col_chunk->bloom_filter_offset();
+  if (!bloom_filter_offset.has_value()) {
+    return nullptr;
+  }
+  PARQUET_ASSIGN_OR_THROW(auto file_size, input_->GetSize());
+  if (file_size <= *bloom_filter_offset) {
+    throw ParquetException("file size less or equal than bloom offset");
+  }
+  auto stream = ::arrow::io::RandomAccessFile::GetStream(
+      input_, *bloom_filter_offset, file_size - *bloom_filter_offset);
+  auto bloom_filter = BlockSplitBloomFilter::Deserialize(properties_, stream->get());
+  return std::make_unique<BlockSplitBloomFilter>(std::move(bloom_filter));
+}
+
+class BloomFilterReaderImpl final : public BloomFilterReader {
+ public:
+  BloomFilterReaderImpl(std::shared_ptr<::arrow::io::RandomAccessFile> input,
+                        std::shared_ptr<FileMetaData> file_metadata,
+                        const ReaderProperties& properties,
+                        std::shared_ptr<InternalFileDecryptor> file_decryptor)
+      : input_(std::move(input)),
+        file_metadata_(std::move(file_metadata)),
+        properties_(properties) {
+    if (file_decryptor != nullptr) {
+      ParquetException::NYI("BloomFilter encryption not support");
+    }
+  }
+
+  std::shared_ptr<RowGroupBloomFilterReader> RowGroup(int i) {
+    if (i < 0 || i >= file_metadata_->num_row_groups()) {
+      throw ParquetException("Invalid row group ordinal: ", i);
+    }
+
+    auto row_group_metadata = file_metadata_->RowGroup(i);
+    return std::make_shared<RowGroupBloomFilterReaderImpl>(

Review Comment:
   Should we check if none of bloom filter exists and return nullptr?



##########
cpp/src/parquet/bloom_filter_reader.h:
##########
@@ -0,0 +1,51 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#pragma once
+
+#include "parquet/bloom_filter.h"
+#include "parquet/encryption/internal_file_decryptor.h"
+
+namespace parquet {
+
+class PARQUET_EXPORT RowGroupBloomFilterReader {
+ public:
+  virtual ~RowGroupBloomFilterReader() = default;
+
+  virtual std::unique_ptr<BloomFilter> GetColumnBloomFilter(int i) = 0;

Review Comment:
   +1 for adding comment for every public api.



##########
cpp/src/parquet/bloom_filter_reader.cc:
##########
@@ -0,0 +1,114 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "parquet/bloom_filter_reader.h"
+#include "metadata.h"

Review Comment:
   ```suggestion
   #include "parquet/metadata.h"
   ```



##########
cpp/src/parquet/bloom_filter_reader.h:
##########
@@ -0,0 +1,51 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#pragma once
+
+#include "parquet/bloom_filter.h"
+#include "parquet/encryption/internal_file_decryptor.h"
+
+namespace parquet {
+
+class PARQUET_EXPORT RowGroupBloomFilterReader {
+ public:
+  virtual ~RowGroupBloomFilterReader() = default;
+
+  virtual std::unique_ptr<BloomFilter> GetColumnBloomFilter(int i) = 0;
+};
+
+/// \brief Interface for reading the bloom filter for a Parquet file.
+class PARQUET_EXPORT BloomFilterReader {

Review Comment:
   Do you plan to support an api to provide hints of successive reads for better I/O planning?



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