Skip to content

Commit cc33b0c

Browse files
authored
feat: add support to DECIMAL column type (#3341)
1 parent 40ce323 commit cc33b0c

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

src/duckdb/src/table/duckdb-table-utils.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,13 @@ export function castDuckDBTypesForKepler(
140140
return `ST_AsWKB(${quotedColumnName}) as ${quotedColumnName}`;
141141
} else if (
142142
options.bigIntToDouble &&
143-
(type === 'BIGINT' || type === 'UBIGINT' || type === 'HUGEINT' || type === 'UHUGEINT')
143+
(type === 'BIGINT' ||
144+
type === 'UBIGINT' ||
145+
type === 'HUGEINT' ||
146+
type === 'UHUGEINT' ||
147+
type.startsWith('DECIMAL'))
144148
) {
145-
// Cast 64-bit and larger integer types to DOUBLE to avoid BigInt in JS
149+
// Cast 64-bit and larger integer types and DECIMAL to DOUBLE to avoid BigInt in JS
146150
return `CAST(${quotedColumnName} AS DOUBLE) as ${quotedColumnName}`;
147151
}
148152
return quotedColumnName;

test/node/utils/duckdb-utils-test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,24 @@ test('duckdb-utils -> castDuckDBTypesForKepler options', t => {
9595
t.end();
9696
});
9797

98+
// Test castDuckDBTypesForKepler with DECIMAL types
99+
test('duckdb-utils -> castDuckDBTypesForKepler with DECIMAL', t => {
100+
const tableName = 'test_table';
101+
const columns = [
102+
{name: 'id', type: 'INTEGER'},
103+
{name: 'price', type: 'DECIMAL(18,2)'},
104+
{name: 'amount', type: 'DECIMAL'},
105+
{name: 'rate', type: 'DECIMAL(10,5)'}
106+
];
107+
108+
const result = castDuckDBTypesForKepler(tableName, columns);
109+
110+
const resultMock = `SELECT "id", CAST("price" AS DOUBLE) as "price", CAST("amount" AS DOUBLE) as "amount", CAST("rate" AS DOUBLE) as "rate" FROM "test_table"`;
111+
t.equal(result, resultMock, 'should cast DECIMAL types to DOUBLE');
112+
113+
t.end();
114+
});
115+
98116
// Test castDuckDBTypesForKepler
99117
test('duckdb-utils -> castDuckDBTypesForKepler with complex table name', t => {
100118
const tableName = '"memory"."main"."earthquakes"';

0 commit comments

Comments
 (0)