Skip to content

Commit

Permalink
supporting more physical types of parquet time columns with time zone…
Browse files Browse the repository at this point in the history
… info
  • Loading branch information
Hannes Mühleisen authored and Tmonster committed Dec 7, 2023
1 parent baf670f commit c6bf4c6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
10 changes: 9 additions & 1 deletion extension/parquet/column_reader.cpp
Expand Up @@ -1469,11 +1469,18 @@ unique_ptr<ColumnReader> ColumnReader::CreateReader(ParquetReader &reader, const
break;
}
}
throw NotImplementedException("Unsupported time encoding in Parquet file");
case LogicalTypeId::TIME_TZ:
if (schema_p.__isset.logicalType && schema_p.logicalType.__isset.TIME) {
if (schema_p.logicalType.TIME.unit.__isset.MICROS) {
if (schema_p.logicalType.TIME.unit.__isset.MILLIS) {
return make_uniq<CallbackColumnReader<int32_t, dtime_tz_t, ParquetIntToTimeMsTZ>>(
reader, type_p, schema_p, file_idx_p, max_define, max_repeat);
} else if (schema_p.logicalType.TIME.unit.__isset.MICROS) {
return make_uniq<CallbackColumnReader<int64_t, dtime_tz_t, ParquetIntToTimeTZ>>(
reader, type_p, schema_p, file_idx_p, max_define, max_repeat);
} else if (schema_p.logicalType.TIME.unit.__isset.NANOS) {
return make_uniq<CallbackColumnReader<int64_t, dtime_tz_t, ParquetIntToTimeNsTZ>>(
reader, type_p, schema_p, file_idx_p, max_define, max_repeat);
}
} else if (schema_p.__isset.converted_type) {
switch (schema_p.converted_type) {
Expand All @@ -1484,6 +1491,7 @@ unique_ptr<ColumnReader> ColumnReader::CreateReader(ParquetReader &reader, const
break;
}
}
throw NotImplementedException("Unsupported time encoding in Parquet file");
case LogicalTypeId::BLOB:
case LogicalTypeId::VARCHAR:
return make_uniq<StringColumnReader>(reader, type_p, schema_p, file_idx_p, max_define, max_repeat);
Expand Down
2 changes: 2 additions & 0 deletions extension/parquet/include/parquet_timestamp.hpp
Expand Up @@ -25,6 +25,8 @@ date_t ParquetIntToDate(const int32_t &raw_date);
dtime_t ParquetIntToTimeMs(const int32_t &raw_time);
dtime_t ParquetIntToTime(const int64_t &raw_time);
dtime_t ParquetIntToTimeNs(const int64_t &raw_time);
dtime_tz_t ParquetIntToTimeMsTZ(const int32_t &raw_time);
dtime_tz_t ParquetIntToTimeTZ(const int64_t &raw_time);
dtime_tz_t ParquetIntToTimeNsTZ(const int64_t &raw_time);

} // namespace duckdb
23 changes: 15 additions & 8 deletions extension/parquet/parquet_timestamp.cpp
Expand Up @@ -54,21 +54,28 @@ date_t ParquetIntToDate(const int32_t &raw_date) {
return date_t(raw_date);
}

dtime_t ParquetIntToTimeMs(const int32_t &raw_time) {
return Time::FromTimeMs(raw_time);
dtime_t ParquetIntToTimeMs(const int32_t &raw_millis) {
return Time::FromTimeMs(raw_millis);
}

dtime_t ParquetIntToTime(const int64_t &raw_time) {
return dtime_t(raw_time);
dtime_t ParquetIntToTime(const int64_t &raw_micros) {
return dtime_t(raw_micros);
}

dtime_t ParquetIntToTimeNs(const int64_t &raw_time) {
return Time::FromTimeNs(raw_time);
dtime_t ParquetIntToTimeNs(const int64_t &raw_nanos) {
return Time::FromTimeNs(raw_nanos);
}

dtime_tz_t ParquetIntToTimeMsTZ(const int32_t &raw_millis) {
return dtime_tz_t(Time::FromTimeMs(raw_millis), 0);
}

dtime_tz_t ParquetIntToTimeTZ(const int64_t &raw_micros) {
dtime_t t(raw_micros);
return dtime_tz_t(t, 0);
return dtime_tz_t(dtime_t(raw_micros), 0);
}

dtime_tz_t ParquetIntToTimeNsTZ(const int64_t &raw_nanos) {
return dtime_tz_t(Time::FromTimeNs(raw_nanos), 0);
}

} // namespace duckdb

0 comments on commit c6bf4c6

Please sign in to comment.