Skip to content

Commit 689897e

Browse files
Liyixin95liyixinalamb
authored
Support round trip reading / writing Arrow Duration type to parquet (#7482)
* fix duration conversion error * implement durtion type convert in parquet writer * Use existing tests, remove new test --------- Co-authored-by: liyixin <[email protected]> Co-authored-by: Andrew Lamb <[email protected]>
1 parent 8bed541 commit 689897e

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

parquet/src/arrow/arrow_writer/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2519,25 +2519,21 @@ mod tests {
25192519
}
25202520

25212521
#[test]
2522-
#[should_panic(expected = "Converting Duration to parquet not supported")]
25232522
fn duration_second_single_column() {
25242523
required_and_optional::<DurationSecondArray, _>(0..SMALL_SIZE as i64);
25252524
}
25262525

25272526
#[test]
2528-
#[should_panic(expected = "Converting Duration to parquet not supported")]
25292527
fn duration_millisecond_single_column() {
25302528
required_and_optional::<DurationMillisecondArray, _>(0..SMALL_SIZE as i64);
25312529
}
25322530

25332531
#[test]
2534-
#[should_panic(expected = "Converting Duration to parquet not supported")]
25352532
fn duration_microsecond_single_column() {
25362533
required_and_optional::<DurationMicrosecondArray, _>(0..SMALL_SIZE as i64);
25372534
}
25382535

25392536
#[test]
2540-
#[should_panic(expected = "Converting Duration to parquet not supported")]
25412537
fn duration_nanosecond_single_column() {
25422538
required_and_optional::<DurationNanosecondArray, _>(0..SMALL_SIZE as i64);
25432539
}

parquet/src/arrow/schema/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,10 @@ fn arrow_to_parquet_type(field: &Field, coerce_types: bool) -> Result<Type> {
586586
.with_repetition(repetition)
587587
.with_id(id)
588588
.build(),
589-
DataType::Duration(_) => Err(arrow_err!("Converting Duration to parquet not supported",)),
589+
DataType::Duration(_) => Type::primitive_type_builder(name, PhysicalType::INT64)
590+
.with_repetition(repetition)
591+
.with_id(id)
592+
.build(),
590593
DataType::Interval(_) => {
591594
Type::primitive_type_builder(name, PhysicalType::FIXED_LEN_BYTE_ARRAY)
592595
.with_converted_type(ConvertedType::INTERVAL)

parquet/src/arrow/schema/primitive.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ fn apply_hint(parquet: DataType, hint: DataType) -> DataType {
4343
(DataType::Int32 | DataType::Int64, DataType::Timestamp(_, _)) => hint,
4444
(DataType::Int32, DataType::Time32(_)) => hint,
4545
(DataType::Int64, DataType::Time64(_)) => hint,
46+
(DataType::Int64, DataType::Duration(_)) => hint,
4647

4748
// Date64 doesn't have a corresponding LogicalType / ConvertedType
4849
(DataType::Int64, DataType::Date64) => hint,

0 commit comments

Comments
 (0)