Skip to content

Commit

Permalink
fix: Remove date in favor of timestamp, handle interval, pass underly…
Browse files Browse the repository at this point in the history
…ing value to arrow (#62)
  • Loading branch information
erezrokah committed Aug 17, 2023
1 parent ffa3979 commit 239dccb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 92 deletions.
83 changes: 0 additions & 83 deletions src/scalar/date.ts

This file was deleted.

11 changes: 8 additions & 3 deletions src/scalar/scalar.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { DataType, Precision } from '@apache-arrow/esnext-esm';
import { DataType, Precision, TimeUnit } from '@apache-arrow/esnext-esm';

import { JSONType } from '../types/json.js';
import { UUIDType } from '../types/uuid.js';

import { Bool } from './bool.js';
import { Date } from './date.js';
import { Float32 } from './float32.js';
import { Float64 } from './float64.js';
import { Int16 } from './int16.js';
Expand Down Expand Up @@ -90,7 +89,13 @@ export const newScalar = (dataType: DataType): Scalar<unknown> => {
}

if (DataType.isDate(dataType)) {
return new Date(dataType.unit);
// TODO: Add Date support
return new Timestamp(TimeUnit.SECOND);
}

if (DataType.isInterval(dataType)) {
// TODO: Add Interval support
return new JSONScalar();
}

if (dataType instanceof UUIDType) {
Expand Down
7 changes: 1 addition & 6 deletions src/schema/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { tableToIPC, Table as ArrowTable, RecordBatch, vectorFromArray } from '@
import { ResourceError } from '../errors/errors.js';
import type { Scalar, Vector } from '../scalar/scalar.js';
import { newScalar } from '../scalar/scalar.js';
import { isExtensionType } from '../types/extensions.js';

import { cqIDColumn } from './meta.js';
import type { Table } from './table.js';
Expand Down Expand Up @@ -64,11 +63,7 @@ export const encodeResource = (resource: Resource): Uint8Array => {
let batch = new RecordBatch(schema, undefined);
for (let index = 0; index < table.columns.length; index++) {
const column = table.columns[index];
// For extension types, we need to get the underlying value
const data = isExtensionType(column.type)
? resource.getColumnData(column.name).value
: resource.getColumnData(column.name);

const data = resource.getColumnData(column.name).value;
const vector = vectorFromArray([data], column.type);
batch = batch.setChildAt(index, vector);
}
Expand Down

0 comments on commit 239dccb

Please sign in to comment.