diff --git a/packages/client/test/unit/util/typeCasting.test.ts b/packages/client/test/unit/util/typeCasting.test.ts index 783074e..51902cb 100644 --- a/packages/client/test/unit/util/typeCasting.test.ts +++ b/packages/client/test/unit/util/typeCasting.test.ts @@ -1,4 +1,13 @@ -import {Bool, Field, Float64, Int64, Uint64, Utf8} from 'apache-arrow' +import { + Bool, + Field, + Float64, + Int64, + Timestamp, + TimeUnit, + Uint64, + Utf8, +} from 'apache-arrow' import {getMappedValue} from '../../../src/util/TypeCasting' import {expect} from 'chai' @@ -30,6 +39,21 @@ describe('Type casting test', () => { field = generateStringField(fieldName) expect(getMappedValue(field, 'a')).to.equal('a') expect(getMappedValue(field, true)).to.equal(true) + + field = generateTimeStamp(fieldName) + const nowNanoSecond = Date.now() * 1_000_000 + expect(getMappedValue(field, nowNanoSecond)).to.equal(nowNanoSecond) + + field = generateIntFieldTestTypeMeta(fieldName) + expect(getMappedValue(field, 1)).to.equal(1) + + // If metadata is null return the value + field = new Field(fieldName, new Int64(), true, null) + expect(getMappedValue(field, 1)).to.equal(1) + + // If value is null return null + field = new Field(fieldName, new Int64(), true, null) + expect(getMappedValue(field, null)).to.equal(null) }) }) @@ -62,3 +86,15 @@ function generateBooleanField(name: string): Field { map.set('iox::column::type', 'iox::column_type::field::boolean') return new Field(name, new Bool(), true, map) } + +function generateIntFieldTestTypeMeta(name: string): Field { + const map = new Map() + map.set('iox::column::type', 'iox::column_type::field::test') + return new Field(name, new Int64(), true, map) +} + +function generateTimeStamp(name: string): Field { + const map = new Map() + map.set('iox::column::type', 'iox::column_type::timestamp') + return new Field(name, new Timestamp(TimeUnit.NANOSECOND), true, map) +}