Skip to content

Commit

Permalink
Remove unnecessary concat function, and use UTF8 compatible functions…
Browse files Browse the repository at this point in the history
… and COLLATE
  • Loading branch information
casab committed Feb 9, 2023
1 parent 04ac787 commit 63b935c
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion packages/cubejs-schema-compiler/src/adapter/ClickHouseQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ClickHouseFilter extends BaseFilter {
likeIgnoreCase(column, not, param, type) {
const p = (!type || type === 'contains' || type === 'ends') ? '%' : '';
const s = (!type || type === 'contains' || type === 'starts') ? '%' : '';
return `lower(${column}) ${not ? 'NOT' : ''} LIKE CONCAT('${p}', lower(${this.allocateParam(param)}), '${s}')`;
return `lowerUTF8(${column}) ${not ? 'NOT' : ''} LIKE lowerUTF8(${p}${this.allocateParam(param)}${s})`;
}

castParameter() {
Expand Down Expand Up @@ -149,6 +149,28 @@ export class ClickHouseQuery extends BaseQuery {
return `${fieldAlias} ${direction}`;
}

orderBy() {
//
// ClickHouse orders string by bytes, so we need to use COLLATE 'en' to order by string
//
if (R.isEmpty(this.order)) {
return '';
}

const orderByString = R.pipe(
R.map(this.orderHashToString),
R.reject(R.isNil),
R.join(' COLLATE \'en\''),
R.join(', ')
)(this.order);

if (!orderByString) {
return '';
}

return ` ORDER BY ${orderByString}`;
}

groupByClause() {
if (this.ungrouped) {
return '';
Expand Down

0 comments on commit 63b935c

Please sign in to comment.