Skip to content

Commit e63a2fe

Browse files
fix param casting in presto
1 parent eace9db commit e63a2fe

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-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' +

packages/cubejs-schema-compiler/test/integration/postgres/sql-generation.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,25 @@ SELECT 1 AS revenue, cast('2024-01-01' AS timestamp) as time UNION ALL
860860
includes: ['count']
861861
}]
862862
})
863+
864+
cube('boolean_dimension', {
865+
sql: \`
866+
SELECT
867+
'true' AS dim
868+
\`,
869+
dimensions: {
870+
dim: {
871+
sql: \`dim\`,
872+
type: 'boolean',
873+
primaryKey: true
874+
}
875+
},
876+
measures: {
877+
count: {
878+
type: 'count',
879+
}
880+
}
881+
});
863882
`);
864883

865884
it('simple join', async () => {
@@ -1995,6 +2014,31 @@ SELECT 1 AS revenue, cast('2024-01-01' AS timestamp) as time UNION ALL
19952014
expect(query.buildSqlAndParams()[0]).toMatch(/OFFSET (\d)\s+LIMIT (\d)/);
19962015
});
19972016

2017+
it('bool param cast (PrestoQuery)', async () => {
2018+
await compiler.compile();
2019+
2020+
const query = new PrestodbQuery({ joinGraph, cubeEvaluator, compiler }, {
2021+
measures: [
2022+
'boolean_dimension.count',
2023+
],
2024+
timeDimensions: [{
2025+
dimension: 'boolean_dimension.dim',
2026+
}],
2027+
filters: [
2028+
{
2029+
member: 'boolean_dimension.dim',
2030+
operator: 'equals',
2031+
values: ['true'],
2032+
},
2033+
],
2034+
});
2035+
2036+
const queryAndParams = query.buildSqlAndParams();
2037+
console.log(queryAndParams);
2038+
2039+
expect(queryAndParams[0]).toContain('"boolean_dimension".dim = CAST(? AS BOOLEAN)');
2040+
});
2041+
19982042
it('calculated join', async () => {
19992043
await compiler.compile();
20002044

0 commit comments

Comments
 (0)