mirror of
https://github.com/asadbek064/hyparquet.git
synced 2026-01-04 18:46:37 +00:00
Parse logical types
This commit is contained in:
parent
b01fbe7b75
commit
892c933a05
9
demo.js
9
demo.js
@ -218,7 +218,7 @@ function renderTable(header, data) {
|
||||
const tr = document.createElement('tr')
|
||||
for (const value of Object.values(row)) {
|
||||
const td = document.createElement('td')
|
||||
td.innerText = value
|
||||
td.innerText = stringify(value)
|
||||
tr.appendChild(td)
|
||||
}
|
||||
tbody.appendChild(tr)
|
||||
@ -226,3 +226,10 @@ function renderTable(header, data) {
|
||||
table.appendChild(tbody)
|
||||
return table
|
||||
}
|
||||
|
||||
function stringify(value) {
|
||||
if (value === undefined) return ''
|
||||
if (typeof value === 'string') return value
|
||||
if (typeof value === 'object') return JSON.stringify(value)
|
||||
return value
|
||||
}
|
||||
|
||||
@ -194,32 +194,41 @@ export function parquetSchema(metadata) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse logical type by type.
|
||||
*
|
||||
* @typedef {import("./types.d.ts").LogicalType} LogicalType
|
||||
* @param {any} logicalType
|
||||
* @returns {LogicalType | undefined}
|
||||
* @returns {import("./types.d.ts").LogicalType | undefined}
|
||||
*/
|
||||
function logicalType(logicalType) {
|
||||
if (logicalType?.field_5) {
|
||||
return {
|
||||
logicalType: 'DECIMAL',
|
||||
scale: logicalType.field_5.field_1,
|
||||
precision: logicalType.field_5.field_2,
|
||||
}
|
||||
if (logicalType?.field_1) return { type: 'STRING' }
|
||||
if (logicalType?.field_2) return { type: 'MAP' }
|
||||
if (logicalType?.field_3) return { type: 'LIST' }
|
||||
if (logicalType?.field_4) return { type: 'ENUM' }
|
||||
if (logicalType?.field_5) return {
|
||||
type: 'DECIMAL',
|
||||
scale: logicalType.field_5.field_1,
|
||||
precision: logicalType.field_5.field_2,
|
||||
}
|
||||
// TODO: TimestampType
|
||||
// TODO: TimeType
|
||||
if (logicalType?.field_10) {
|
||||
return {
|
||||
logicalType: 'INTEGER',
|
||||
bitWidth: logicalType.field_10.field_1,
|
||||
isSigned: logicalType.field_10.field_2,
|
||||
}
|
||||
if (logicalType?.field_6) return { type: 'DATE' }
|
||||
if (logicalType?.field_7) return {
|
||||
type: 'TIME',
|
||||
isAdjustedToUTC: logicalType.field_7.field_1,
|
||||
unit: logicalType.field_7.field_2,
|
||||
}
|
||||
if (logicalType) {
|
||||
return logicalType
|
||||
if (logicalType?.field_8) return {
|
||||
type: 'TIMESTAMP',
|
||||
isAdjustedToUTC: logicalType.field_8.field_1,
|
||||
unit: logicalType.field_8.field_2,
|
||||
}
|
||||
if (logicalType?.field_10) return {
|
||||
type: 'INTEGER',
|
||||
bitWidth: logicalType.field_10.field_1,
|
||||
isSigned: logicalType.field_10.field_2,
|
||||
}
|
||||
if (logicalType?.field_11) return { type: 'NULL' }
|
||||
if (logicalType?.field_12) return { type: 'JSON' }
|
||||
if (logicalType?.field_13) return { type: 'BSON' }
|
||||
if (logicalType?.field_14) return { type: 'UUID' }
|
||||
if (logicalType?.field_15) return { type: 'FLOAT16' }
|
||||
return logicalType
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
22
src/types.d.ts
vendored
22
src/types.d.ts
vendored
@ -86,20 +86,36 @@ export type ConvertedType =
|
||||
'INTERVAL'
|
||||
|
||||
type LogicalDecimalType = {
|
||||
logicalType: 'DECIMAL'
|
||||
type: 'DECIMAL'
|
||||
precision: number
|
||||
scale: number
|
||||
}
|
||||
|
||||
type TimeUnit = 'MILLIS' | 'MICROS' | 'NANOS'
|
||||
|
||||
type LogicalTimeType = {
|
||||
type: 'TIME'
|
||||
isAdjustedToUTC: boolean
|
||||
unit: TimeUnit
|
||||
}
|
||||
|
||||
type LogicalTimestampType = {
|
||||
type: 'TIMESTAMP'
|
||||
isAdjustedToUTC: boolean
|
||||
unit: TimeUnit
|
||||
}
|
||||
|
||||
type LogicalIntType = {
|
||||
logicalType: 'INTEGER'
|
||||
type: 'INTEGER'
|
||||
bitWidth: number
|
||||
isSigned: boolean
|
||||
}
|
||||
|
||||
export type LogicalType =
|
||||
{ logicalType: LogicalTypeType } |
|
||||
{ type: LogicalTypeType } |
|
||||
LogicalDecimalType |
|
||||
LogicalTimeType |
|
||||
LogicalTimestampType |
|
||||
LogicalIntType
|
||||
|
||||
export type LogicalTypeType =
|
||||
|
||||
@ -42,7 +42,7 @@
|
||||
{
|
||||
"converted_type": "UINT_64",
|
||||
"logical_type": {
|
||||
"logicalType": "INTEGER",
|
||||
"type": "INTEGER",
|
||||
"bitWidth": 64,
|
||||
"isSigned": false
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user