|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +use std::fs::File; |
| 19 | +use std::sync::Arc; |
| 20 | + |
| 21 | +use dsi_progress_logger::prelude::*; |
| 22 | + |
| 23 | +use arrow::array::{StructArray, UInt64Builder}; |
| 24 | +use arrow::datatypes::DataType::UInt64; |
| 25 | +use arrow::datatypes::{Field, Schema}; |
| 26 | +use parquet::arrow::ArrowWriter as ParquetWriter; |
| 27 | +use parquet::basic::Encoding; |
| 28 | +use parquet::errors::Result; |
| 29 | +use parquet::file::properties::WriterProperties; |
| 30 | + |
| 31 | +fn main() -> Result<()> { |
| 32 | + let _ = simplelog::SimpleLogger::init(simplelog::LevelFilter::Info, Default::default()); |
| 33 | + |
| 34 | + let properties = WriterProperties::builder() |
| 35 | + .set_column_bloom_filter_enabled("id".into(), true) |
| 36 | + .set_column_encoding("id".into(), Encoding::DELTA_BINARY_PACKED) |
| 37 | + .build(); |
| 38 | + let schema = Arc::new(Schema::new(vec![Field::new("id", UInt64, false)])); |
| 39 | + // Create parquet file that will be read. |
| 40 | + let path = "/tmp/test.parquet"; |
| 41 | + let file = File::create(path).unwrap(); |
| 42 | + let mut writer = ParquetWriter::try_new(file, schema.clone(), Some(properties))?; |
| 43 | + |
| 44 | + let num_iterations = 3000; |
| 45 | + let mut pl = progress_logger!( |
| 46 | + item_name = "iterations", |
| 47 | + display_memory = true, |
| 48 | + expected_updates = Some(num_iterations as usize) |
| 49 | + ); |
| 50 | + pl.start("Writing batches"); |
| 51 | + let mut array_builder = UInt64Builder::new(); |
| 52 | + for i in 0..num_iterations { |
| 53 | + pl.update(); |
| 54 | + for j in 0..1_000_000 { |
| 55 | + array_builder.append_value(i + j); |
| 56 | + } |
| 57 | + writer.write( |
| 58 | + &StructArray::new( |
| 59 | + schema.fields().clone(), |
| 60 | + vec![Arc::new(array_builder.finish())], |
| 61 | + None, |
| 62 | + ) |
| 63 | + .into(), |
| 64 | + )?; |
| 65 | + } |
| 66 | + writer.flush()?; |
| 67 | + writer.close()?; |
| 68 | + pl.done(); |
| 69 | + |
| 70 | + Ok(()) |
| 71 | +} |
0 commit comments