Skip to content

Commit

Permalink
fix: Athena doesn't support _ in contains filter
Browse files Browse the repository at this point in the history
  • Loading branch information
paveltiunov committed Aug 22, 2019
1 parent 682904d commit d330be4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions packages/cubejs-athena-driver/driver/AthenaDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const AWS = require('aws-sdk');
const { promisify } = require('util');
const BaseDriver = require('@cubejs-backend/query-orchestrator/driver/BaseDriver');
const SqlString = require('sqlstring');
const crypto = require('crypto');

const applyParams = (query, params) => {
return SqlString.format(query, params);
Expand Down Expand Up @@ -32,11 +31,17 @@ class AthenaDriver extends BaseDriver {
sleep(ms) {
return new Promise((resolve) => {
setTimeout(() => resolve(), ms);
})
});
}

async query(query, values) {
const queryString = applyParams(query, values);
const queryString = applyParams(
query,
values.map(s => (typeof s === 'string' ? {
toSqlString: () => SqlString.escape(s).replace(/\\\\([_%])/g, '\\$1')
} : s))
);
console.log(queryString);
const { QueryExecutionId } = await this.athena.startQueryExecutionAsync({
QueryString: queryString,
ResultConfiguration: {
Expand Down Expand Up @@ -84,4 +89,4 @@ class AthenaDriver extends BaseDriver {
}
}

module.exports = AthenaDriver;
module.exports = AthenaDriver;
2 changes: 1 addition & 1 deletion packages/cubejs-schema-compiler/adapter/PrestodbQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const GRANULARITY_TO_INTERVAL = {

class PrestodbFilter extends BaseFilter {
likeIgnoreCase(column, not) {
return `LOWER(${column})${not ? ' NOT' : ''} LIKE CONCAT('%', LOWER(?) ,'%')`;
return `LOWER(${column})${not ? ' NOT' : ''} LIKE CONCAT('%', LOWER(?) ,'%') ESCAPE '\\'`;
}

castParameter() {
Expand Down

0 comments on commit d330be4

Please sign in to comment.