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
2 changes: 2 additions & 0 deletions packages/cubejs-pinot-driver/src/PinotQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ export class PinotQuery extends BaseQuery {
'{% if limit %}\nLIMIT {{ limit }}{% endif %}';
templates.expressions.extract = 'EXTRACT({{ date_part }} FROM {{ expr }})';
templates.expressions.timestamp_literal = `fromDateTime('{{ value }}', ${DATE_TIME_FORMAT})`;
// NOTE: this template contains a comma; two order expressions are being generated
templates.expressions.sort = '{{ expr }} IS NULL {% if nulls_first %}DESC{% else %}ASC{% endif %}, {{ expr }} {% if asc %}ASC{% else %}DESC{% endif %}';
templates.quotes.identifiers = '"';
delete templates.types.time;
delete templates.types.interval;
Expand Down
2 changes: 1 addition & 1 deletion packages/cubejs-schema-compiler/src/adapter/BaseQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -3230,7 +3230,7 @@ export class BaseQuery {
case: 'CASE{% if expr %} {{ expr }}{% endif %}{% for when, then in when_then %} WHEN {{ when }} THEN {{ then }}{% endfor %}{% if else_expr %} ELSE {{ else_expr }}{% endif %} END',
is_null: '{{ expr }} IS {% if negate %}NOT {% endif %}NULL',
binary: '({{ left }} {{ op }} {{ right }})',
sort: '{{ expr }} {% if asc %}ASC{% else %}DESC{% endif %}{% if nulls_first %} NULLS FIRST{% endif %}',
sort: '{{ expr }} {% if asc %}ASC{% else %}DESC{% endif %} NULLS {% if nulls_first %}FIRST{% else %}LAST{% endif %}',
cast: 'CAST({{ expr }} AS {{ data_type }})',
window_function: '{{ fun_call }} OVER ({% if partition_by_concat %}PARTITION BY {{ partition_by_concat }}{% if order_by_concat or window_frame %} {% endif %}{% endif %}{% if order_by_concat %}ORDER BY {{ order_by_concat }}{% if window_frame %} {% endif %}{% endif %}{% if window_frame %}{{ window_frame }}{% endif %})',
window_frame_bounds: '{{ frame_type }} BETWEEN {{ frame_start }} AND {{ frame_end }}',
Expand Down
2 changes: 2 additions & 0 deletions packages/cubejs-schema-compiler/src/adapter/MssqlQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ export class MssqlQuery extends BaseQuery {
templates.functions.LEAST = 'LEAST({{ args_concat }})';
templates.functions.GREATEST = 'GREATEST({{ args_concat }})';
delete templates.expressions.ilike;
// NOTE: this template contains a comma; two order expressions are being generated
templates.expressions.sort = '{{ expr }} IS NULL {% if nulls_first %}DESC{% else %}ASC{% endif %}, {{ expr }} {% if asc %}ASC{% else %}DESC{% endif %}';
templates.types.string = 'VARCHAR';
templates.types.boolean = 'BIT';
templates.types.integer = 'INT';
Expand Down
2 changes: 2 additions & 0 deletions packages/cubejs-schema-compiler/src/adapter/MysqlQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ export class MysqlQuery extends BaseQuery {
const templates = super.sqlTemplates();
templates.quotes.identifiers = '`';
templates.quotes.escape = '\\`';
// NOTE: this template contains a comma; two order expressions are being generated
templates.expressions.sort = '{{ expr }} IS NULL {% if nulls_first %}DESC{% else %}ASC{% endif %}, {{ expr }} {% if asc %}ASC{% else %}DESC{% endif %}';
delete templates.expressions.ilike;
templates.types.string = 'VARCHAR';
templates.types.boolean = 'TINYINT';
Expand Down
3 changes: 2 additions & 1 deletion packages/cubejs-testing-drivers/fixtures/mssql.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
"SQL API: Nested Rollup with aliases",
"SQL API: Nested Rollup over asterisk",
"SQL API: Extended nested Rollup over asterisk",
"SQL API: ungrouped pre-agg"
"SQL API: ungrouped pre-agg",
"SQL API: NULLS FIRST/LAST SQL push down"
]
}
12 changes: 12 additions & 0 deletions packages/cubejs-testing-drivers/src/tests/testQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2013,5 +2013,17 @@ from

expect(res.rows).toMatchSnapshot('metabase_count_cast_to_float32_from_push_down');
});

executePg('SQL API: NULLS FIRST/LAST SQL push down', async (connection) => {
const res = await connection.query(`
SELECT CASE WHEN "category" > 'G' THEN "category" ELSE NULL END AS "category"
FROM "Products"
WHERE LOWER("category") != 'invalid'
GROUP BY 1
ORDER BY 1 ASC NULLS FIRST
LIMIT 100
`);
expect(res.rows).toMatchSnapshot('nulls_first_last_sql_push_down');
});
});
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Queries with the @cubejs-backend/athena-driver SQL API: NULLS FIRST/LAST SQL push down: nulls_first_last_sql_push_down 1`] = `
Array [
Object {
"category": null,
},
Object {
"category": "Office Supplies",
},
Object {
"category": "Technology",
},
]
`;

exports[`Queries with the @cubejs-backend/athena-driver SQL API: metabase count cast to float32 from push down: metabase_count_cast_to_float32_from_push_down 1`] = `
Array [
Object {
Expand Down
Loading
Loading