Skip to content

Commit

Permalink
test: add more test case getMappedValue
Browse files Browse the repository at this point in the history
  • Loading branch information
NguyenHoangSon96 committed Dec 16, 2024
1 parent 1996fff commit 3d45dff
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion packages/client/test/unit/util/typeCasting.test.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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)
})
})

Expand Down Expand Up @@ -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<string, string>()
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<string, string>()
map.set('iox::column::type', 'iox::column_type::timestamp')
return new Field(name, new Timestamp(TimeUnit.NANOSECOND), true, map)
}

0 comments on commit 3d45dff

Please sign in to comment.