Skip to content

Commit 577a09f

Browse files
authored
feat(cubesql): Support PERCENTILE_CONT SQL push down (#8697)
1 parent 1104bde commit 577a09f

File tree

28 files changed

+512
-116
lines changed

28 files changed

+512
-116
lines changed

packages/cubejs-backend-native/Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cubejs-schema-compiler/src/adapter/BaseQuery.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3831,6 +3831,8 @@ export class BaseQuery {
38313831
// DATEADD is being rewritten to DATE_ADD
38323832
// DATEADD: 'DATEADD({{ date_part }}, {{ interval }}, {{ args[2] }})',
38333833
DATE: 'DATE({{ args_concat }})',
3834+
3835+
PERCENTILECONT: 'PERCENTILE_CONT({{ args_concat }})',
38343836
},
38353837
statements: {
38363838
select: '{% if ctes %} WITH \n' +
@@ -3893,6 +3895,7 @@ export class BaseQuery {
38933895
like: '{{ expr }} {% if negated %}NOT {% endif %}LIKE {{ pattern }}',
38943896
ilike: '{{ expr }} {% if negated %}NOT {% endif %}ILIKE {{ pattern }}',
38953897
like_escape: '{{ like_expr }} ESCAPE {{ escape_char }}',
3898+
within_group: '{{ fun_sql }} WITHIN GROUP (ORDER BY {{ within_group_concat }})',
38963899
concat_strings: '{{ strings | join(\' || \' ) }}',
38973900
},
38983901
tesseract: {

packages/cubejs-schema-compiler/src/adapter/BigqueryQuery.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ export class BigqueryQuery extends BaseQuery {
259259
templates.functions.DATE_ADD = 'DATETIME_ADD(DATETIME({{ args[0] }}), INTERVAL {{ interval }} {{ date_part }})';
260260
templates.functions.CURRENTDATE = 'CURRENT_DATE';
261261
delete templates.functions.TO_CHAR;
262+
delete templates.functions.PERCENTILECONT;
262263
templates.expressions.binary = '{% if op == \'%\' %}MOD({{ left }}, {{ right }}){% else %}({{ left }} {{ op }} {{ right }}){% endif %}';
263264
templates.expressions.interval = 'INTERVAL {{ interval }}';
264265
templates.expressions.extract = 'EXTRACT({% if date_part == \'DOW\' %}DAYOFWEEK{% elif date_part == \'DOY\' %}DAYOFYEAR{% else %}{{ date_part }}{% endif %} FROM {{ expr }})';

packages/cubejs-schema-compiler/src/adapter/ClickHouseQuery.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ export class ClickHouseQuery extends BaseQuery {
272272
// TODO: Introduce additional filter in jinja? or parseDateTimeBestEffort?
273273
// https://github.com/ClickHouse/ClickHouse/issues/19351
274274
templates.expressions.timestamp_literal = 'parseDateTimeBestEffort(\'{{ value }}\')';
275+
delete templates.functions.PERCENTILECONT;
275276
delete templates.expressions.like_escape;
276277
templates.quotes.identifiers = '`';
277278
templates.quotes.escape = '\\`';

packages/cubejs-schema-compiler/src/adapter/MssqlQuery.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ export class MssqlQuery extends BaseQuery {
246246
const templates = super.sqlTemplates();
247247
templates.functions.LEAST = 'LEAST({{ args_concat }})';
248248
templates.functions.GREATEST = 'GREATEST({{ args_concat }})';
249+
// PERCENTILE_CONT works but requires PARTITION BY
250+
delete templates.functions.PERCENTILECONT;
249251
delete templates.expressions.ilike;
250252
// NOTE: this template contains a comma; two order expressions are being generated
251253
templates.expressions.sort = '{{ expr }} IS NULL {% if nulls_first %}DESC{% else %}ASC{% endif %}, {{ expr }} {% if asc %}ASC{% else %}DESC{% endif %}';

packages/cubejs-schema-compiler/src/adapter/MysqlQuery.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ export class MysqlQuery extends BaseQuery {
165165

166166
public sqlTemplates() {
167167
const templates = super.sqlTemplates();
168+
// PERCENTILE_CONT works but requires PARTITION BY
169+
delete templates.functions.PERCENTILECONT;
168170
templates.quotes.identifiers = '`';
169171
templates.quotes.escape = '\\`';
170172
// NOTE: this template contains a comma; two order expressions are being generated

packages/cubejs-schema-compiler/src/adapter/PrestodbQuery.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export class PrestodbQuery extends BaseQuery {
137137
const templates = super.sqlTemplates();
138138
templates.functions.DATETRUNC = 'DATE_TRUNC({{ args_concat }})';
139139
templates.functions.DATEPART = 'DATE_PART({{ args_concat }})';
140+
delete templates.functions.PERCENTILECONT;
140141
templates.statements.select = 'SELECT {{ select_concat | map(attribute=\'aliased\') | join(\', \') }} \n' +
141142
'FROM (\n {{ from }}\n) AS {{ from_alias }} \n' +
142143
'{% if group_by %} GROUP BY {{ group_by }}{% endif %}' +

rust/cubenativeutils/Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/cubesql/Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/cubesql/cubesql/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ homepage = "https://cube.dev"
1010

1111
[dependencies]
1212
arc-swap = "1"
13-
datafusion = { git = 'https://github.com/cube-js/arrow-datafusion.git', rev = "ecd17b3a6f3f902ac42814344bddc891c41686e6", default-features = false, features = [
13+
datafusion = { git = 'https://github.com/cube-js/arrow-datafusion.git', rev = "454020d6ad0eb5987aa0dbc3a3b4db8c24ccc1b5", default-features = false, features = [
1414
"regex_expressions",
1515
"unicode_expressions",
1616
] }
1717
thiserror = "2"
1818
cubeclient = { path = "../cubeclient" }
1919
pg-srv = { path = "../pg-srv" }
20-
sqlparser = { git = 'https://github.com/cube-js/sqlparser-rs.git', rev = "6a54d27d3b75a04b9f9cbe309a83078aa54b32fd" }
20+
sqlparser = { git = 'https://github.com/cube-js/sqlparser-rs.git', rev = "34f22de680caa5fe586def5b336d56efe43c8cc4" }
2121
base64 = "0.13.0"
2222
tokio = { version = "^1.35", features = ["full", "rt", "tracing"] }
2323
serde = { version = "^1.0", features = ["derive"] }

0 commit comments

Comments
 (0)