From 639e8b69881af4d31ff927536f0efb4a2e98fbba Mon Sep 17 00:00:00 2001 From: erezrokah Date: Mon, 14 Aug 2023 15:55:34 +0200 Subject: [PATCH] fix: Extension types null values --- src/memdb/tables.ts | 1 + src/scalar/json.ts | 8 +++++--- src/scalar/list.ts | 6 +++--- src/scalar/scalar.ts | 8 +++----- src/scalar/uuid.ts | 8 +++++--- src/schema/resource.ts | 4 ++-- 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/memdb/tables.ts b/src/memdb/tables.ts index d8cb6e0..3b4f615 100644 --- a/src/memdb/tables.ts +++ b/src/memdb/tables.ts @@ -15,6 +15,7 @@ export const createTables = () => { resolver: (clientMeta, parent, stream) => { stream.write({ id: 'id-1', json: '{ "a": 1 }' }); stream.write({ id: 'id-2', json: [1, 2, 3] }); + stream.write({ id: 'id-3' }); return Promise.resolve(); }, columns: [ diff --git a/src/scalar/json.ts b/src/scalar/json.ts index 4a941de..6ebe7ed 100644 --- a/src/scalar/json.ts +++ b/src/scalar/json.ts @@ -1,5 +1,7 @@ import { Utf8 as ArrowString } from '@apache-arrow/esnext-esm'; +import { Nullable } from '../schema/types.js'; + import { Scalar } from './scalar.js'; import { isInvalid, NULL_VALUE } from './util.js'; @@ -12,9 +14,9 @@ const validate = (value: string) => { } }; -class JSONType implements Scalar { +class JSONType implements Scalar> { private _valid = false; - private _value = new TextEncoder().encode(NULL_VALUE); + private _value: Nullable = null; public constructor(v?: unknown) { this.value = v; @@ -29,7 +31,7 @@ class JSONType implements Scalar { return this._valid; } - public get value(): Uint8Array { + public get value(): Nullable { return this._value; } diff --git a/src/scalar/list.ts b/src/scalar/list.ts index 78fa613..86659df 100644 --- a/src/scalar/list.ts +++ b/src/scalar/list.ts @@ -1,11 +1,11 @@ import { DataType, List as ArrowList } from '@apache-arrow/esnext-esm'; -import { Scalar, Stringable } from './scalar.js'; +import { Scalar } from './scalar.js'; import { isInvalid, NULL_VALUE } from './util.js'; -type TVector> = T[]; +type TVector> = T[]; -export class List> implements Scalar> { +export class List> implements Scalar> { private _childScalarInstance: T; private _valid = false; private _value: TVector = []; diff --git a/src/scalar/scalar.ts b/src/scalar/scalar.ts index 903e326..259a228 100644 --- a/src/scalar/scalar.ts +++ b/src/scalar/scalar.ts @@ -19,9 +19,7 @@ import { Uint32 } from './uint32.js'; import { Uint64 } from './uint64.js'; import { UUID } from './uuid.js'; -export type Stringable = { toString: () => string }; - -export interface Scalar { +export interface Scalar { toString: () => string; get valid(): boolean; get value(): T; @@ -29,9 +27,9 @@ export interface Scalar { get dataType(): DataType; } -export type Vector = Scalar[]; +export type Vector = Scalar[]; -export const newScalar = (dataType: DataType): Scalar => { +export const newScalar = (dataType: DataType): Scalar => { if (DataType.isBool(dataType)) { return new Bool(); } diff --git a/src/scalar/uuid.ts b/src/scalar/uuid.ts index e87d008..aeadaea 100644 --- a/src/scalar/uuid.ts +++ b/src/scalar/uuid.ts @@ -1,12 +1,14 @@ import { FixedSizeBinary } from '@apache-arrow/esnext-esm'; import { validate } from 'uuid'; +import { Nullable } from '../schema/types.js'; + import { Scalar } from './scalar.js'; import { isInvalid, NULL_VALUE } from './util.js'; -export class UUID implements Scalar { +export class UUID implements Scalar> { private _valid = false; - private _value = new TextEncoder().encode(NULL_VALUE); + private _value: Nullable = null; public constructor(v?: unknown) { this.value = v; @@ -20,7 +22,7 @@ export class UUID implements Scalar { return this._valid; } - public get value(): Uint8Array { + public get value(): Nullable { return this._value; } diff --git a/src/schema/resource.ts b/src/schema/resource.ts index 5c90a84..67a9812 100644 --- a/src/schema/resource.ts +++ b/src/schema/resource.ts @@ -1,6 +1,6 @@ import { tableToIPC, Table as ArrowTable, RecordBatch, vectorFromArray } from '@apache-arrow/esnext-esm'; -import { Scalar, Vector, newScalar, Stringable } from '../scalar/scalar.js'; +import { Scalar, Vector, newScalar } from '../scalar/scalar.js'; import { isExtensionType } from '../types/extensions.js'; import { cqIDColumn } from './meta.js'; @@ -20,7 +20,7 @@ export class Resource { this.data = table.columns.map((column) => newScalar(column.type)); } - getColumnData(columnName: string): Scalar { + getColumnData(columnName: string): Scalar { const columnIndex = this.table.columns.findIndex((c) => c.name === columnName); if (columnIndex === undefined) { throw new Error(`Column '${columnName}' not found`);