Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/duckdb/src/table/duckdb-table-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,13 @@ export function castDuckDBTypesForKepler(
return `ST_AsWKB(${quotedColumnName}) as ${quotedColumnName}`;
} else if (
options.bigIntToDouble &&
(type === 'BIGINT' || type === 'UBIGINT' || type === 'HUGEINT' || type === 'UHUGEINT')
(type === 'BIGINT' ||
type === 'UBIGINT' ||
type === 'HUGEINT' ||
type === 'UHUGEINT' ||
type.startsWith('DECIMAL'))

Copilot AI Feb 13, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type.startsWith('DECIMAL') can throw at runtime if type is undefined/non-string (e.g., getDuckDBColumnTypes assigns columnTypes?.get(i) with optional chaining). Consider normalizing/guarding first (e.g., const t = typeof type === 'string' ? type : '') before calling startsWith.

Suggested change
type.startsWith('DECIMAL'))
(typeof type === 'string' && type.startsWith('DECIMAL')))

Copilot uses AI. Check for mistakes.
) {
// Cast 64-bit and larger integer types to DOUBLE to avoid BigInt in JS
// Cast 64-bit and larger integer types and DECIMAL to DOUBLE to avoid BigInt in JS
return `CAST(${quotedColumnName} AS DOUBLE) as ${quotedColumnName}`;
Comment on lines 141 to 150

Copilot AI Feb 13, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bigIntToDouble now also controls DECIMAL casting, which is a behavioral/API mismatch with the option name (and could surprise callers who disable BigInt casting but still want DECIMAL coerced for Kepler compatibility). Consider introducing a separate option (e.g., decimalToDouble) or renaming/generalizing the option while keeping backward compatibility.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. But I just want to make a simple change

}
return quotedColumnName;
Expand Down
18 changes: 18 additions & 0 deletions test/node/utils/duckdb-utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,24 @@ test('duckdb-utils -> castDuckDBTypesForKepler options', t => {
t.end();
});

// Test castDuckDBTypesForKepler with DECIMAL types
test('duckdb-utils -> castDuckDBTypesForKepler with DECIMAL', t => {
const tableName = 'test_table';
const columns = [
{name: 'id', type: 'INTEGER'},
{name: 'price', type: 'DECIMAL(18,2)'},
{name: 'amount', type: 'DECIMAL'},
{name: 'rate', type: 'DECIMAL(10,5)'}
];

const result = castDuckDBTypesForKepler(tableName, columns);

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"`;
t.equal(result, resultMock, 'should cast DECIMAL types to DOUBLE');

t.end();
});

// Test castDuckDBTypesForKepler
test('duckdb-utils -> castDuckDBTypesForKepler with complex table name', t => {
const tableName = '"memory"."main"."earthquakes"';
Expand Down
Loading