Skip to content

Commit 346d300

Browse files
fix(tesseract): Param casting in Presto (#9908)
* fix param casting in presto * move test case
1 parent 6dd3224 commit 346d300

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

packages/cubejs-schema-compiler/src/adapter/PrestodbQuery.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ export class PrestodbQuery extends BaseQuery {
166166
delete templates.types.interval;
167167
templates.types.binary = 'VARBINARY';
168168
templates.tesseract.ilike = 'LOWER({{ expr }}) {% if negated %}NOT {% endif %} LIKE {{ pattern }}';
169+
templates.tesseract.bool_param_cast = 'CAST({{ expr }} AS BOOLEAN)';
170+
templates.tesseract.number_param_cast = 'CAST({{ expr }} AS DOUBLE)';
169171
templates.filters.like_pattern = 'CONCAT({% if start_wild %}\'%\'{% else %}\'\'{% endif %}, LOWER({{ value }}), {% if end_wild %}\'%\'{% else %}\'\'{% endif %}) ESCAPE \'\\\'';
170172
templates.statements.time_series_select = 'SELECT from_iso8601_timestamp(dates.f) date_from, from_iso8601_timestamp(dates.t) date_to \n' +
171173
'FROM (\n' +
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* eslint-disable no-restricted-syntax */
2+
import { PrestodbQuery } from '../../src/adapter/PrestodbQuery';
3+
import { prepareJsCompiler } from './PrepareCompiler';
4+
5+
describe('PrestodbQuery', () => {
6+
const { compiler, joinGraph, cubeEvaluator } = prepareJsCompiler(`
7+
cube('boolean_dimension', {
8+
sql: \`
9+
SELECT
10+
'true' AS dim
11+
\`,
12+
dimensions: {
13+
dim: {
14+
sql: \`dim\`,
15+
type: 'boolean',
16+
primaryKey: true
17+
}
18+
},
19+
measures: {
20+
count: {
21+
type: 'count',
22+
}
23+
}
24+
});
25+
`);
26+
27+
it('bool param cast (PrestoQuery)', async () => {
28+
await compiler.compile();
29+
30+
const query = new PrestodbQuery({ joinGraph, cubeEvaluator, compiler }, {
31+
measures: [
32+
'boolean_dimension.count',
33+
],
34+
timeDimensions: [{
35+
dimension: 'boolean_dimension.dim',
36+
}],
37+
filters: [
38+
{
39+
member: 'boolean_dimension.dim',
40+
operator: 'equals',
41+
values: ['true'],
42+
},
43+
],
44+
});
45+
46+
const queryAndParams = query.buildSqlAndParams();
47+
console.log(queryAndParams);
48+
49+
expect(queryAndParams[0]).toContain('"boolean_dimension".dim = CAST(? AS BOOLEAN)');
50+
});
51+
});

0 commit comments

Comments
 (0)