-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
978fc97
commit d756090
Showing
18 changed files
with
1,152 additions
and
436 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import duckdb from '@duckdb/node-bindings'; | ||
|
||
export interface ExpectedSimpleLogicalType { | ||
typeId: Exclude<duckdb.Type, | ||
| duckdb.Type.ARRAY | ||
| duckdb.Type.DECIMAL | ||
| duckdb.Type.ENUM | ||
| duckdb.Type.LIST | ||
| duckdb.Type.MAP | ||
| duckdb.Type.STRUCT | ||
| duckdb.Type.UNION | ||
>; | ||
} | ||
|
||
export interface ExpectedArrayLogicalType { | ||
typeId: duckdb.Type.ARRAY; | ||
valueType: ExpectedLogicalType; | ||
size: number; | ||
} | ||
|
||
export interface ExpectedDecimalLogicalType { | ||
typeId: duckdb.Type.DECIMAL; | ||
width: number; | ||
scale: number; | ||
internalType: duckdb.Type; | ||
} | ||
|
||
export interface ExpectedEnumLogicalType { | ||
typeId: duckdb.Type.ENUM; | ||
values: string[]; | ||
internalType: duckdb.Type; | ||
} | ||
|
||
export interface ExpectedListLogicalType { | ||
typeId: duckdb.Type.LIST; | ||
valueType: ExpectedLogicalType; | ||
} | ||
|
||
export interface ExpectedMapLogicalType { | ||
typeId: duckdb.Type.MAP; | ||
keyType: ExpectedLogicalType; | ||
valueType: ExpectedLogicalType; | ||
} | ||
|
||
export interface ExpectedStructEntry { | ||
name: string; | ||
type: ExpectedLogicalType; | ||
} | ||
|
||
export interface ExpectedStructLogicalType { | ||
typeId: duckdb.Type.STRUCT; | ||
entries: ExpectedStructEntry[]; | ||
} | ||
|
||
export interface ExpectedUnionAlternative { | ||
tag: string; | ||
type: ExpectedLogicalType; | ||
} | ||
|
||
export interface ExpectedUnionLogicalType { | ||
typeId: duckdb.Type.UNION; | ||
alternatives: ExpectedUnionAlternative[]; | ||
} | ||
|
||
export type ExpectedLogicalType = | ||
| ExpectedSimpleLogicalType | ||
| ExpectedArrayLogicalType | ||
| ExpectedDecimalLogicalType | ||
| ExpectedEnumLogicalType | ||
| ExpectedListLogicalType | ||
| ExpectedMapLogicalType | ||
| ExpectedStructLogicalType | ||
| ExpectedUnionLogicalType | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import duckdb from '@duckdb/node-bindings'; | ||
import { ExpectedLogicalType } from './ExpectedLogicalType'; | ||
import { ExpectedVector } from './ExpectedVector'; | ||
|
||
export interface ExpectedColumn { | ||
name: string; | ||
logicalType: ExpectedLogicalType; | ||
} | ||
|
||
export interface ExpectedChunk { | ||
columnCount?: number; | ||
rowCount: number; | ||
vectors: ExpectedVector[]; | ||
} | ||
|
||
export interface ExpectedResult { | ||
statementType?: duckdb.StatementType; | ||
resultType?: duckdb.ResultType; | ||
rowsChanged?: number; | ||
columns: ExpectedColumn[]; | ||
chunks: ExpectedChunk[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
export interface ExpectedArrayVector { | ||
kind: 'array'; | ||
itemCount: number; | ||
validity: boolean[]; | ||
child: ExpectedVector; | ||
} | ||
|
||
export interface ExpectedDataVector { | ||
kind: 'data'; | ||
validity: boolean[]; | ||
itemBytes: number; | ||
values: any[]; | ||
} | ||
|
||
export type ExpectedListEntry = [bigint, bigint] | null; | ||
|
||
export interface ExpectedListVector { | ||
kind: 'list'; | ||
validity: boolean[]; | ||
entries: (ExpectedListEntry | null)[]; | ||
childItemCount: number; | ||
child: ExpectedVector; | ||
} | ||
|
||
export interface ExpectedMapVector { | ||
kind: 'map'; | ||
validity: boolean[]; | ||
entries: (ExpectedListEntry | null)[]; | ||
keys: ExpectedVector; | ||
values: ExpectedVector; | ||
} | ||
|
||
export interface ExpectedStructVector { | ||
kind: 'struct'; | ||
itemCount: number; | ||
validity: boolean[]; | ||
children: ExpectedVector[]; | ||
} | ||
|
||
export interface ExpectedUnionVector { | ||
kind: 'union'; | ||
children: ExpectedVector[]; | ||
} | ||
|
||
export type ExpectedVector = | ||
| ExpectedArrayVector | ||
| ExpectedDataVector | ||
| ExpectedListVector | ||
| ExpectedMapVector | ||
| ExpectedStructVector | ||
| ExpectedUnionVector | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import duckdb from '@duckdb/node-bindings'; | ||
import { expect } from 'vitest'; | ||
import { ExpectedChunk, ExpectedColumn } from './ExpectedResult'; | ||
import { expectLogicalType } from './expectLogicalType'; | ||
import { expectVector } from './expectVector'; | ||
import { withLogicalType } from './withLogicalType'; | ||
|
||
export function expectChunk(chunk: duckdb.DataChunk, expectedChunk: ExpectedChunk, expectedColumns: ExpectedColumn[]) { | ||
const chunkColumnCount = expectedChunk.columnCount ?? expectedColumns.length; | ||
expect(duckdb.data_chunk_get_column_count(chunk)).toBe(chunkColumnCount); | ||
expect(duckdb.data_chunk_get_size(chunk)).toBe(expectedChunk.rowCount); | ||
for (let col = 0; col < expectedChunk.vectors.length; col++) { | ||
const expectedVector = expectedChunk.vectors[col]; | ||
const vector = duckdb.data_chunk_get_vector(chunk, col); | ||
|
||
const expectedLogicalType = expectedColumns[col].logicalType; | ||
withLogicalType(duckdb.vector_get_column_type(vector), | ||
(logical_type) => expectLogicalType(logical_type, expectedLogicalType, `col ${col}`) | ||
); | ||
|
||
expectVector(vector, expectedVector, expectedLogicalType, `col ${col}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import duckdb from '@duckdb/node-bindings'; | ||
import { expect } from 'vitest'; | ||
import { ExpectedLogicalType } from './ExpectedLogicalType'; | ||
|
||
export function expectLogicalType(logical_type: duckdb.LogicalType, expectedLogicalType: ExpectedLogicalType, message?: string) { | ||
expect(duckdb.get_type_id(logical_type), message).toBe(expectedLogicalType.typeId); | ||
switch (expectedLogicalType.typeId) { | ||
case duckdb.Type.ARRAY: | ||
expectLogicalType(duckdb.array_type_child_type(logical_type), expectedLogicalType.valueType); | ||
expect(duckdb.array_type_array_size(logical_type)).toBe(expectedLogicalType.size); | ||
break; | ||
case duckdb.Type.DECIMAL: | ||
expect(duckdb.decimal_width(logical_type)).toBe(expectedLogicalType.width); | ||
expect(duckdb.decimal_scale(logical_type)).toBe(expectedLogicalType.scale); | ||
expect(duckdb.decimal_internal_type(logical_type)).toBe(expectedLogicalType.internalType); | ||
break; | ||
case duckdb.Type.ENUM: | ||
{ | ||
expect(duckdb.enum_internal_type(logical_type)).toBe(expectedLogicalType.internalType); | ||
expect(duckdb.enum_dictionary_size(logical_type)).toBe(expectedLogicalType.values.length); | ||
for (let i = 0; i < expectedLogicalType.values.length; i++) { | ||
expect(duckdb.enum_dictionary_value(logical_type, i)).toBe(expectedLogicalType.values[i]); | ||
} | ||
} | ||
break; | ||
case duckdb.Type.LIST: | ||
expectLogicalType(duckdb.list_type_child_type(logical_type), expectedLogicalType.valueType); | ||
break; | ||
case duckdb.Type.MAP: | ||
expectLogicalType(duckdb.map_type_key_type(logical_type), expectedLogicalType.keyType); | ||
expectLogicalType(duckdb.map_type_value_type(logical_type), expectedLogicalType.valueType); | ||
break; | ||
case duckdb.Type.STRUCT: | ||
expect(duckdb.struct_type_child_count(logical_type)).toBe(expectedLogicalType.entries.length); | ||
for (let i = 0; i < expectedLogicalType.entries.length; i++) { | ||
expect(duckdb.struct_type_child_name(logical_type, i)).toBe(expectedLogicalType.entries[i].name); | ||
expectLogicalType(duckdb.struct_type_child_type(logical_type, i), expectedLogicalType.entries[i].type); | ||
} | ||
break; | ||
case duckdb.Type.UNION: | ||
expect(duckdb.union_type_member_count(logical_type)).toBe(expectedLogicalType.alternatives.length); | ||
for (let i = 0; i < expectedLogicalType.alternatives.length; i++) { | ||
expect(duckdb.union_type_member_name(logical_type, i)).toBe(expectedLogicalType.alternatives[i].tag); | ||
expectLogicalType(duckdb.union_type_member_type(logical_type, i), expectedLogicalType.alternatives[i].type); | ||
} | ||
break; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import duckdb from '@duckdb/node-bindings'; | ||
import { expect } from 'vitest'; | ||
import { isValid } from './isValid'; | ||
|
||
export function expectValidity(validity_bytes: Uint8Array, validity: BigUint64Array, bit: number, expected: boolean, vectorName: string) { | ||
expect(duckdb.validity_row_is_valid(validity_bytes, bit), `${vectorName} validity_bytes_bit[${bit}]`).toBe(expected); | ||
expect(isValid(validity, bit), `${vectorName} validity_bit[${bit}]`).toBe(expected); | ||
} |
Oops, something went wrong.