From 4089cd3d3a772e2500456b292a000c46436bd9e5 Mon Sep 17 00:00:00 2001 From: Carlos Bardasano Date: Sat, 23 Nov 2024 10:28:50 +0100 Subject: [PATCH 1/2] Fix metadata timestamp conversion --- src/metadata.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/metadata.js b/src/metadata.js index ce2dc9e..e49803d 100644 --- a/src/metadata.js +++ b/src/metadata.js @@ -281,6 +281,9 @@ export function convertMetadata(value, schema) { if (type === 'INT32' && converted_type === 'DATE') return new Date(view.getInt32(0, true) * 86400000) if (type === 'INT64' && converted_type === 'TIMESTAMP_MICROS') return new Date(Number(view.getBigInt64(0, true) / 1000n)) if (type === 'INT64' && converted_type === 'TIMESTAMP_MILLIS') return new Date(Number(view.getBigInt64(0, true))) + if (type === 'INT64' && logical_type?.type === 'TIMESTAMP' && logical_type?.unit === 'NANOS') return new Date(Number(view.getBigInt64(0, true) / 1000000n)) + if (type === 'INT64' && logical_type?.type === 'TIMESTAMP' && logical_type?.unit === 'MICROS') return new Date(Number(view.getBigInt64(0, true) / 1000n)) + if (type === 'INT64' && logical_type?.type === 'TIMESTAMP' && logical_type?.unit === 'MILLIS') return new Date(Number(view.getBigInt64(0, true))) if (type === 'INT64' && logical_type?.type === 'TIMESTAMP') return new Date(Number(view.getBigInt64(0, true))) if (type === 'INT32' && view.byteLength === 4) return view.getInt32(0, true) if (type === 'INT64' && view.byteLength === 8) return view.getBigInt64(0, true) From 2545e6185855129e7bec545822ec99c253de43a9 Mon Sep 17 00:00:00 2001 From: Carlos Bardasano <111571912+cbardasano@users.noreply.github.com> Date: Fri, 29 Nov 2024 20:44:12 +0100 Subject: [PATCH 2/2] Remove redundant check Co-authored-by: Kenny Daniel --- src/metadata.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/metadata.js b/src/metadata.js index e49803d..9cf9b64 100644 --- a/src/metadata.js +++ b/src/metadata.js @@ -283,7 +283,6 @@ export function convertMetadata(value, schema) { if (type === 'INT64' && converted_type === 'TIMESTAMP_MILLIS') return new Date(Number(view.getBigInt64(0, true))) if (type === 'INT64' && logical_type?.type === 'TIMESTAMP' && logical_type?.unit === 'NANOS') return new Date(Number(view.getBigInt64(0, true) / 1000000n)) if (type === 'INT64' && logical_type?.type === 'TIMESTAMP' && logical_type?.unit === 'MICROS') return new Date(Number(view.getBigInt64(0, true) / 1000n)) - if (type === 'INT64' && logical_type?.type === 'TIMESTAMP' && logical_type?.unit === 'MILLIS') return new Date(Number(view.getBigInt64(0, true))) if (type === 'INT64' && logical_type?.type === 'TIMESTAMP') return new Date(Number(view.getBigInt64(0, true))) if (type === 'INT32' && view.byteLength === 4) return view.getInt32(0, true) if (type === 'INT64' && view.byteLength === 8) return view.getBigInt64(0, true)