Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate fixes for Timestamp[MICROS] and infinite loop hang when reading parquet #1460

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
22 changes: 21 additions & 1 deletion parquet/src/arrow/array_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use std::mem::size_of;
use std::result::Result::Ok;
use std::sync::Arc;
use std::vec::Vec;
use parquet_format::TimeUnit;

use arrow::array::{
new_empty_array, Array, ArrayData, ArrayDataBuilder, ArrayRef, BinaryArray,
Expand Down Expand Up @@ -50,6 +51,7 @@ use arrow::datatypes::{
TimestampMillisecondType as ArrowTimestampMillisecondType,
TimestampNanosecondType as ArrowTimestampNanosecondType,
TimestampSecondType as ArrowTimestampSecondType, ToByteSlice,
TimeUnit::{Microsecond, Nanosecond, Millisecond},
UInt16Type as ArrowUInt16Type, UInt32Type as ArrowUInt32Type,
UInt64Type as ArrowUInt64Type, UInt8Type as ArrowUInt8Type,
};
Expand All @@ -65,7 +67,7 @@ use crate::arrow::converter::{
use crate::arrow::record_reader::buffer::{ScalarValue, ValuesBuffer};
use crate::arrow::record_reader::{GenericRecordReader, RecordReader};
use crate::arrow::schema::parquet_to_arrow_field;
use crate::basic::{ConvertedType, Repetition, Type as PhysicalType};
use crate::basic::{ConvertedType, Repetition, Type as PhysicalType, LogicalType};
use crate::column::page::PageIterator;
use crate::column::reader::decoder::ColumnValueDecoder;
use crate::column::reader::ColumnReaderImpl;
Expand Down Expand Up @@ -428,6 +430,24 @@ where
}
Arc::new(builder.finish()) as ArrayRef
}
ArrowType::Timestamp(ArrowTimeUnit::Nanosecond, ref tz) => {
if let Some(LogicalType::TIMESTAMP(t)) = self.column_desc.logical_type() {
match t.unit {
TimeUnit::MICROS(_) => {
let a = arrow::compute::cast(&array, &ArrowType::Timestamp(Microsecond, tz.clone()))?;
arrow::compute::cast(&a, &ArrowType::Timestamp(Nanosecond, tz.clone()))?
}
TimeUnit::MILLIS(_) => {
let a = arrow::compute::cast(&array, &ArrowType::Timestamp(Millisecond, tz.clone()))?;
arrow::compute::cast(&a, &ArrowType::Timestamp(Nanosecond, tz.clone()))?
}
_ => arrow::compute::cast(&array, &target_type.clone())?
}
}
Copy link
Member

Choose a reason for hiding this comment

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

The logic looks correct. But we need some tests to verify them.

else {
arrow::compute::cast(&array, &target_type.clone())?
}
}
_ => arrow::compute::cast(&array, &target_type)?,
};

Expand Down
7 changes: 7 additions & 0 deletions parquet/src/encodings/rle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,13 @@ impl RleDecoder {
&mut buffer[values_read..values_read + num_values],
self.bit_width as usize,
);
if num_values == 0 {
// some writers are putting less values that could fit in the bit packed run
// in such a case bit_packed_left is unreliable as it represents max possible values left
// to avoid infinite loop we need to return so the caller could check if all expected values were read already.
self.bit_packed_left = 0;
continue;
}
self.bit_packed_left -= num_values as u32;
values_read += num_values;
} else if !self.reload() {
Expand Down