From 3d45dff16d5034fc1f95d2b60d6defdb2d742f57 Mon Sep 17 00:00:00 2001 From: NguyenHoangSon96 Date: Mon, 16 Dec 2024 15:57:23 +0700 Subject: [PATCH] test: add more test case getMappedValue --- .../client/test/unit/util/typeCasting.test.ts | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) 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) +}