Parse metadata TimeUnit

This commit is contained in:
Kenny Daniel 2024-05-24 15:06:46 -07:00
parent 9aebdb2917
commit a56420de2f
No known key found for this signature in database
GPG Key ID: 90AB653A8CAD7E45
3 changed files with 14 additions and 6 deletions

@ -214,12 +214,12 @@ function logicalType(logicalType) {
if (logicalType?.field_7) return {
type: 'TIME',
isAdjustedToUTC: logicalType.field_7.field_1,
unit: logicalType.field_7.field_2,
unit: timeUnit(logicalType.field_7.field_2),
}
if (logicalType?.field_8) return {
type: 'TIMESTAMP',
isAdjustedToUTC: logicalType.field_8.field_1,
unit: logicalType.field_8.field_2,
unit: timeUnit(logicalType.field_8.field_2),
}
if (logicalType?.field_10) return {
type: 'INTEGER',
@ -234,6 +234,16 @@ function logicalType(logicalType) {
return logicalType
}
/**
* @param {any} unit
* @returns {import("./types.d.ts").TimeUnit | undefined}
*/
function timeUnit(unit) {
if (unit.field_1) return 'MILLIS'
if (unit.field_2) return 'MICROS'
if (unit.field_3) return 'NANOS'
}
/**
* Convert column statistics based on column type.
*

2
src/types.d.ts vendored

@ -92,7 +92,7 @@ type LogicalDecimalType = {
scale: number
}
type TimeUnit = 'MILLIS' | 'MICROS' | 'NANOS'
export type TimeUnit = 'MILLIS' | 'MICROS' | 'NANOS'
type LogicalTimeType = {
type: 'TIME'

@ -12,9 +12,7 @@
"logical_type": {
"type": "TIMESTAMP",
"isAdjustedToUTC": false,
"unit": {
"field_1": {}
}
"unit": "MILLIS"
}
},
{