Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cast decimal literal to DOUBLE #1722

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions packages/malloy-db-duckdb/src/duckdb_wasm_connection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,11 @@ FROM read_parquet("inventory_items2.parquet")
{}
);
});

// Test to check that DecimalBigNums are broken.
// Remove/update when fixed
Copy link
Collaborator

Choose a reason for hiding this comment

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

If it were me, I would mention sqlLiteralNumber in this comment, in case neither of us are here on the day this happens.

it('DecimalBigNum is broken', async () => {
const result = await connection.runSQL('SELECT 1.234 AS n1');
expect(result).toEqual({'rows': [{'n1': 1234}], 'totalRows': 1});
});
});
8 changes: 8 additions & 0 deletions packages/malloy/src/dialect/duckdb/duckdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ export class DuckDBDialect extends Dialect {
return `FIRST(${fieldName}) FILTER (WHERE ${fieldName} IS NOT NULL)`;
}

// DuckDB WASM has an issue with returning invalid DecimalBigNum
// values unless we explicitly cast to DOUBLE
override sqlLiteralNumber(literal: string): string {
return literal.includes('.')
? `${literal}::${this.defaultNumberType}`
: literal;
}

mapFields(fieldList: DialectFieldList): string {
return fieldList.join(', ');
}
Expand Down
11 changes: 11 additions & 0 deletions test/src/databases/duckdb/duckdb.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ describe.each(allDucks.runtimeList)('duckdb:%s', (dbName, runtime) => {
);
});

it('handles decimal literals', async () => {
const query = `
run: duckdb.sql("select 1") -> {
select:
n1 is 1.234
n2 is 1234.0 / 1000
}
`;
await expect(query).malloyResultMatches(runtime, {n1: 1.234, n2: 1.234});
});

it('can open json files', async () => {
await expect(`
run: duckdb.table('test/data/duckdb/test.json') -> {
Expand Down
Loading