Skip to content

Commit d330be4

Browse files
committed
fix: Athena doesn't support _ in contains filter
1 parent 682904d commit d330be4

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

packages/cubejs-athena-driver/driver/AthenaDriver.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const AWS = require('aws-sdk');
22
const { promisify } = require('util');
33
const BaseDriver = require('@cubejs-backend/query-orchestrator/driver/BaseDriver');
44
const SqlString = require('sqlstring');
5-
const crypto = require('crypto');
65

76
const applyParams = (query, params) => {
87
return SqlString.format(query, params);
@@ -32,11 +31,17 @@ class AthenaDriver extends BaseDriver {
3231
sleep(ms) {
3332
return new Promise((resolve) => {
3433
setTimeout(() => resolve(), ms);
35-
})
34+
});
3635
}
3736

3837
async query(query, values) {
39-
const queryString = applyParams(query, values);
38+
const queryString = applyParams(
39+
query,
40+
values.map(s => (typeof s === 'string' ? {
41+
toSqlString: () => SqlString.escape(s).replace(/\\\\([_%])/g, '\\$1')
42+
} : s))
43+
);
44+
console.log(queryString);
4045
const { QueryExecutionId } = await this.athena.startQueryExecutionAsync({
4146
QueryString: queryString,
4247
ResultConfiguration: {
@@ -84,4 +89,4 @@ class AthenaDriver extends BaseDriver {
8489
}
8590
}
8691

87-
module.exports = AthenaDriver;
92+
module.exports = AthenaDriver;

packages/cubejs-schema-compiler/adapter/PrestodbQuery.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const GRANULARITY_TO_INTERVAL = {
1111

1212
class PrestodbFilter extends BaseFilter {
1313
likeIgnoreCase(column, not) {
14-
return `LOWER(${column})${not ? ' NOT' : ''} LIKE CONCAT('%', LOWER(?) ,'%')`;
14+
return `LOWER(${column})${not ? ' NOT' : ''} LIKE CONCAT('%', LOWER(?) ,'%') ESCAPE '\\'`;
1515
}
1616

1717
castParameter() {

0 commit comments

Comments
 (0)