Skip to content

Commit 63b935c

Browse files
committed
Remove unnecessary concat function, and use UTF8 compatible functions and COLLATE
1 parent 04ac787 commit 63b935c

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ClickHouseFilter extends BaseFilter {
1616
likeIgnoreCase(column, not, param, type) {
1717
const p = (!type || type === 'contains' || type === 'ends') ? '%' : '';
1818
const s = (!type || type === 'contains' || type === 'starts') ? '%' : '';
19-
return `lower(${column}) ${not ? 'NOT' : ''} LIKE CONCAT('${p}', lower(${this.allocateParam(param)}), '${s}')`;
19+
return `lowerUTF8(${column}) ${not ? 'NOT' : ''} LIKE lowerUTF8(${p}${this.allocateParam(param)}${s})`;
2020
}
2121

2222
castParameter() {
@@ -149,6 +149,28 @@ export class ClickHouseQuery extends BaseQuery {
149149
return `${fieldAlias} ${direction}`;
150150
}
151151

152+
orderBy() {
153+
//
154+
// ClickHouse orders string by bytes, so we need to use COLLATE 'en' to order by string
155+
//
156+
if (R.isEmpty(this.order)) {
157+
return '';
158+
}
159+
160+
const orderByString = R.pipe(
161+
R.map(this.orderHashToString),
162+
R.reject(R.isNil),
163+
R.join(' COLLATE \'en\''),
164+
R.join(', ')
165+
)(this.order);
166+
167+
if (!orderByString) {
168+
return '';
169+
}
170+
171+
return ` ORDER BY ${orderByString}`;
172+
}
173+
152174
groupByClause() {
153175
if (this.ungrouped) {
154176
return '';

0 commit comments

Comments
 (0)