Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions parquet/src/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1331,10 +1331,10 @@ impl AsRef<[u8]> for FixedLenByteArray {

/// Macro to reduce repetition in making type assertions on the physical type against `T`
macro_rules! ensure_phys_ty {
($($ty:pat_param)|+ , $err: literal) => {
($($ty:pat_param)|+ , $($arg:tt)*) => {
match T::get_physical_type() {
$($ty => (),)*
_ => panic!($err),
_ => panic!($($arg)*),
};
}
}
Expand Down
16 changes: 7 additions & 9 deletions parquet/src/encodings/encoding/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,20 +522,18 @@ trait DeltaBitPackEncoderConversion<T: DataType> {
fn subtract_u64(&self, left: i64, right: i64) -> u64;
}

const DELTA_BIT_PACK_TYPE_ERROR: &str =
"DeltaBitPackDecoder only supports Int32Type, UInt32Type, Int64Type, and UInt64Type";

impl<T: DataType> DeltaBitPackEncoderConversion<T> for DeltaBitPackEncoder<T> {
#[inline]
fn assert_supported_type() {
ensure_phys_ty!(
Type::INT32 | Type::INT64,
"DeltaBitPackDecoder only supports Int32Type and Int64Type"
);
ensure_phys_ty!(Type::INT32 | Type::INT64, "{}", DELTA_BIT_PACK_TYPE_ERROR);
}

#[inline]
fn as_i64(&self, values: &[T::T], index: usize) -> i64 {
values[index]
.as_i64()
.expect("DeltaBitPackDecoder only supports Int32Type and Int64Type")
values[index].as_i64().expect(DELTA_BIT_PACK_TYPE_ERROR)
}

#[inline]
Expand All @@ -544,7 +542,7 @@ impl<T: DataType> DeltaBitPackEncoderConversion<T> for DeltaBitPackEncoder<T> {
match T::get_physical_type() {
Type::INT32 => (left as i32).wrapping_sub(right as i32) as i64,
Type::INT64 => left.wrapping_sub(right),
_ => panic!("DeltaBitPackDecoder only supports Int32Type and Int64Type"),
_ => panic!("{}", DELTA_BIT_PACK_TYPE_ERROR),
}
}

Expand All @@ -554,7 +552,7 @@ impl<T: DataType> DeltaBitPackEncoderConversion<T> for DeltaBitPackEncoder<T> {
// Conversion of i32 -> u32 -> u64 is to avoid non-zero left most bytes in int repr
Type::INT32 => (left as i32).wrapping_sub(right as i32) as u32 as u64,
Type::INT64 => left.wrapping_sub(right) as u64,
_ => panic!("DeltaBitPackDecoder only supports Int32Type and Int64Type"),
_ => panic!("{}", DELTA_BIT_PACK_TYPE_ERROR),
}
}
}
Expand Down
50 changes: 50 additions & 0 deletions parquet/tests/arrow_writer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Licensed to the Apache Software Foundation (ASF) under one
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it is strange to have a new integration test just for this error message, I agree starting to have an arrow_writer suite is a good step forward

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

//! Tests that the ArrowWriter correctly lays out values into multiple pages

use arrow::array::Float64Array;
use arrow::datatypes::{DataType, Field, Schema};
use arrow::record_batch::RecordBatch;
use parquet::arrow::ArrowWriter;
use parquet::basic::Encoding;
use parquet::file::properties::WriterProperties;
use std::sync::Arc;

#[test]
#[should_panic(
expected = "DeltaBitPackDecoder only supports Int32Type, UInt32Type, Int64Type, and UInt64Type"
)]
fn test_delta_bit_pack_type() {
let props = WriterProperties::builder()
.set_column_encoding("col".into(), Encoding::DELTA_BINARY_PACKED)
.build();

let record_batch = RecordBatch::try_new(
Arc::new(Schema::new(vec![Field::new(
"col",
DataType::Float64,
false,
)])),
vec![Arc::new(Float64Array::from_iter_values(vec![1., 2.]))],
)
.unwrap();

let mut buffer = Vec::new();
let mut writer = ArrowWriter::try_new(&mut buffer, record_batch.schema(), Some(props)).unwrap();
let _ = writer.write(&record_batch);
}
Loading