Skip to content

Commit e8bb0a0

Browse files
authored
fix: Extension types null values (#58)
1 parent daa0dea commit e8bb0a0

File tree

6 files changed

+19
-16
lines changed

6 files changed

+19
-16
lines changed

src/memdb/tables.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const createTables = () => {
1515
resolver: (clientMeta, parent, stream) => {
1616
stream.write({ id: 'id-1', json: '{ "a": 1 }' });
1717
stream.write({ id: 'id-2', json: [1, 2, 3] });
18+
stream.write({ id: 'id-3' });
1819
return Promise.resolve();
1920
},
2021
columns: [

src/scalar/json.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Utf8 as ArrowString } from '@apache-arrow/esnext-esm';
22

3+
import { Nullable } from '../schema/types.js';
4+
35
import { Scalar } from './scalar.js';
46
import { isInvalid, NULL_VALUE } from './util.js';
57

@@ -12,9 +14,9 @@ const validate = (value: string) => {
1214
}
1315
};
1416

15-
class JSONType implements Scalar<Uint8Array> {
17+
class JSONType implements Scalar<Nullable<Uint8Array>> {
1618
private _valid = false;
17-
private _value = new TextEncoder().encode(NULL_VALUE);
19+
private _value: Nullable<Uint8Array> = null;
1820

1921
public constructor(v?: unknown) {
2022
this.value = v;
@@ -29,7 +31,7 @@ class JSONType implements Scalar<Uint8Array> {
2931
return this._valid;
3032
}
3133

32-
public get value(): Uint8Array {
34+
public get value(): Nullable<Uint8Array> {
3335
return this._value;
3436
}
3537

src/scalar/list.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { DataType, List as ArrowList } from '@apache-arrow/esnext-esm';
22

3-
import { Scalar, Stringable } from './scalar.js';
3+
import { Scalar } from './scalar.js';
44
import { isInvalid, NULL_VALUE } from './util.js';
55

6-
type TVector<T extends Scalar<Stringable>> = T[];
6+
type TVector<T extends Scalar<unknown>> = T[];
77

8-
export class List<T extends Scalar<Stringable>> implements Scalar<TVector<T>> {
8+
export class List<T extends Scalar<unknown>> implements Scalar<TVector<T>> {
99
private _childScalarInstance: T;
1010
private _valid = false;
1111
private _value: TVector<T> = [];

src/scalar/scalar.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,17 @@ import { Uint32 } from './uint32.js';
1919
import { Uint64 } from './uint64.js';
2020
import { UUID } from './uuid.js';
2121

22-
export type Stringable = { toString: () => string };
23-
24-
export interface Scalar<T extends Stringable> {
22+
export interface Scalar<T> {
2523
toString: () => string;
2624
get valid(): boolean;
2725
get value(): T;
2826
set value(value: unknown);
2927
get dataType(): DataType;
3028
}
3129

32-
export type Vector = Scalar<Stringable>[];
30+
export type Vector = Scalar<unknown>[];
3331

34-
export const newScalar = (dataType: DataType): Scalar<Stringable> => {
32+
export const newScalar = (dataType: DataType): Scalar<unknown> => {
3533
if (DataType.isBool(dataType)) {
3634
return new Bool();
3735
}

src/scalar/uuid.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { FixedSizeBinary } from '@apache-arrow/esnext-esm';
22
import { validate } from 'uuid';
33

4+
import { Nullable } from '../schema/types.js';
5+
46
import { Scalar } from './scalar.js';
57
import { isInvalid, NULL_VALUE } from './util.js';
68

7-
export class UUID implements Scalar<Uint8Array> {
9+
export class UUID implements Scalar<Nullable<Uint8Array>> {
810
private _valid = false;
9-
private _value = new TextEncoder().encode(NULL_VALUE);
11+
private _value: Nullable<Uint8Array> = null;
1012

1113
public constructor(v?: unknown) {
1214
this.value = v;
@@ -20,7 +22,7 @@ export class UUID implements Scalar<Uint8Array> {
2022
return this._valid;
2123
}
2224

23-
public get value(): Uint8Array {
25+
public get value(): Nullable<Uint8Array> {
2426
return this._value;
2527
}
2628

src/schema/resource.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { tableToIPC, Table as ArrowTable, RecordBatch, vectorFromArray } from '@apache-arrow/esnext-esm';
22

3-
import { Scalar, Vector, newScalar, Stringable } from '../scalar/scalar.js';
3+
import { Scalar, Vector, newScalar } from '../scalar/scalar.js';
44
import { isExtensionType } from '../types/extensions.js';
55

66
import { cqIDColumn } from './meta.js';
@@ -20,7 +20,7 @@ export class Resource {
2020
this.data = table.columns.map((column) => newScalar(column.type));
2121
}
2222

23-
getColumnData(columnName: string): Scalar<Stringable> {
23+
getColumnData(columnName: string): Scalar<unknown> {
2424
const columnIndex = this.table.columns.findIndex((c) => c.name === columnName);
2525
if (columnIndex === undefined) {
2626
throw new Error(`Column '${columnName}' not found`);

0 commit comments

Comments
 (0)