diff --git a/packages/cubejs-schema-compiler/src/adapter/ClickHouseQuery.js b/packages/cubejs-schema-compiler/src/adapter/ClickHouseQuery.js index f6d94af5ab301..261daaa5bf5c3 100644 --- a/packages/cubejs-schema-compiler/src/adapter/ClickHouseQuery.js +++ b/packages/cubejs-schema-compiler/src/adapter/ClickHouseQuery.js @@ -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() { @@ -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 '';