Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class BigqueryFilter extends BaseFilter {
public castParameter() {
if (this.definition().type === 'boolean') {
return 'CAST(? AS BOOL)';
} else if (this.definition().type === 'time') {
return 'CAST(? AS TIMESTAMP)';
} else if (this.measure || this.definition().type === 'number') {
// TODO here can be measure type of string actually
return 'CAST(? AS FLOAT64)';
Expand Down Expand Up @@ -347,6 +349,7 @@ export class BigqueryQuery extends BaseQuery {
// DATEADD is being rewritten to DATE_ADD
templates.functions.DATE_ADD = 'DATETIME_ADD(DATETIME({{ args[0] }}), INTERVAL {{ interval }} {{ date_part }})';
templates.functions.CURRENTDATE = 'CURRENT_DATE';
templates.functions.DATE = 'TIMESTAMP({{ args_concat }})';
delete templates.functions.TO_CHAR;
delete templates.functions.PERCENTILECONT;
templates.expressions.binary = '{% if op == \'%\' %}MOD({{ left }}, {{ right }}){% else %}({{ left }} {{ op }} {{ right }}){% endif %}';
Expand Down
4 changes: 4 additions & 0 deletions packages/cubejs-testing-drivers/fixtures/mssql.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@
"SQL API: SQL push down push to cube quoted alias",
"SQL API: Date/time comparison with SQL push down",
"SQL API: Date/time comparison with date_trunc with SQL push down",
"SQL API: Date/time comparison with DATE() function in SQL push down",
"SQL API: Date/time comparison with DATE() function using COUNT push down",

"---------------------------------------",
"Error during rewrite: Can't detect Cube query and it may be not supported yet.",
Expand Down Expand Up @@ -228,6 +230,8 @@
"SQL API: SQL push down push to cube quoted alias",
"SQL API: Date/time comparison with SQL push down",
"SQL API: Date/time comparison with date_trunc with SQL push down",
"SQL API: Date/time comparison with DATE() function in SQL push down",
"SQL API: Date/time comparison with DATE() function using COUNT push down",

"---------------------------------------",
"Error during rewrite: Can't detect Cube query and it may be not supported yet.",
Expand Down
21 changes: 21 additions & 0 deletions packages/cubejs-testing-drivers/src/tests/testQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2610,5 +2610,26 @@ from
`);
expect(res.rows).toMatchSnapshot();
});

executePg('SQL API: Date/time comparison with DATE() function in SQL push down', async (connection) => {
const res = await connection.query(`
SELECT MEASURE(BigECommerce.totalQuantity) as qty
FROM BigECommerce
WHERE CAST(BigECommerce.orderDate AS DATE) = DATE('2020-01-01')
`);
expect(res.rows).toMatchSnapshot();
});

executePg('SQL API: Date/time comparison with DATE() function using COUNT push down', async (connection) => {
const res = await connection.query(`
SELECT
CAST(BigECommerce.orderDate AS DATE) as order_day,
COUNT(1) as cnt
FROM BigECommerce
WHERE CAST(BigECommerce.orderDate AS DATE) = DATE('2020-01-01')
GROUP BY 1
`);
expect(res.rows).toMatchSnapshot();
});
});
}
Loading