Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-07 10:25:41

0001 // Licensed to the Apache Software Foundation (ASF) under one
0002 // or more contributor license agreements.  See the NOTICE file
0003 // distributed with this work for additional information
0004 // regarding copyright ownership.  The ASF licenses this file
0005 // to you under the Apache License, Version 2.0 (the
0006 // "License"); you may not use this file except in compliance
0007 // with the License.  You may obtain a copy of the License at
0008 //
0009 //   http://www.apache.org/licenses/LICENSE-2.0
0010 //
0011 // Unless required by applicable law or agreed to in writing,
0012 // software distributed under the License is distributed on an
0013 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0014 // KIND, either express or implied.  See the License for the
0015 // specific language governing permissions and limitations
0016 // under the License.
0017 
0018 #pragma once
0019 
0020 #include "arrow/type_fwd.h"
0021 
0022 #include "parquet/bloom_filter.h"
0023 #include "parquet/index_location.h"
0024 #include "parquet/type_fwd.h"
0025 
0026 namespace parquet {
0027 
0028 /// \brief Writer for updating a bloom filter with values of a specific Parquet type.
0029 /// \note Boolean type is not supported.
0030 template <typename ParquetType>
0031 class PARQUET_EXPORT TypedBloomFilterWriter {
0032  public:
0033   using T = typename ParquetType::c_type;
0034 
0035   /// \param descr The descriptor of the column to write. Must outlive this writer.
0036   /// \param bloom_filter The bloom filter to update. Must outlive this writer.
0037   TypedBloomFilterWriter(const ColumnDescriptor* descr, BloomFilter* bloom_filter);
0038 
0039   /// \brief Update the bloom filter with typed values.
0040   ///
0041   /// \param values The values to update the bloom filter with.
0042   /// \param num_values The number of values to update the bloom filter with.
0043   void Update(const T* values, int64_t num_values);
0044 
0045   /// \brief Update the bloom filter with typed values that have spaces.
0046   ///
0047   /// \param values The values to update the bloom filter with.
0048   /// \param num_values The number of values to update the bloom filter with.
0049   /// \param valid_bits The validity bitmap of the values.
0050   /// \param valid_bits_offset The offset of the validity bitmap.
0051   void UpdateSpaced(const T* values, int64_t num_values, const uint8_t* valid_bits,
0052                     int64_t valid_bits_offset);
0053 
0054   /// \brief Update the bloom filter with an Arrow array.
0055   ///
0056   /// \param values The Arrow array to update the bloom filter with.
0057   void Update(const ::arrow::Array& values);
0058 
0059  private:
0060   const ColumnDescriptor* descr_;
0061   BloomFilter* bloom_filter_;
0062 };
0063 
0064 /// \brief Interface for building bloom filters of a parquet file.
0065 class PARQUET_EXPORT BloomFilterBuilder {
0066  public:
0067   virtual ~BloomFilterBuilder() = default;
0068 
0069   /// \brief API to create a BloomFilterBuilder.
0070   ///
0071   /// \param schema The schema of the file and it must outlive the created builder.
0072   /// \param properties Properties to get bloom filter options. It must outlive the
0073   /// created builder.
0074   static std::unique_ptr<BloomFilterBuilder> Make(const SchemaDescriptor* schema,
0075                                                   const WriterProperties* properties);
0076 
0077   /// \brief Start a new row group to write bloom filters, meaning that next calls
0078   /// to `CreateBloomFilter` will create bloom filters for the new row group.
0079   ///
0080   /// \throws ParquetException if `WriteTo()` has been called already.
0081   virtual void AppendRowGroup() = 0;
0082 
0083   /// \brief Create a BloomFilter of the column ordinal of the current row group.
0084   ///
0085   /// \param column_ordinal Column ordinal for the bloom filter.
0086   /// \return created BloomFilter whose ownership belongs to the builder, or nullptr if
0087   /// bloom filter is not enabled for the column.
0088   /// \throws ParquetException if any condition is violated:
0089   ///   - `AppendRowGroup()` has not been called yet
0090   ///   - The column ordinal is out of bound
0091   ///   - Bloom filter already exists for the column
0092   ///   - `WriteTo()` has been called
0093   virtual BloomFilter* CreateBloomFilter(int32_t column_ordinal) = 0;
0094 
0095   /// \brief Write all bloom filters to sink.
0096   ///
0097   /// The bloom filters cannot be modified after this method is called.
0098   ///
0099   /// \param[in] sink The output stream to write the bloom filters.
0100   /// \return The location of all bloom filters.
0101   /// \throws ParquetException if `WriteTo()` has been called.
0102   virtual IndexLocations WriteTo(::arrow::io::OutputStream* sink) = 0;
0103 };
0104 
0105 }  // namespace parquet