Skip to content

Commit 90136dc

Browse files
authored
fix(firebolt-driver): Automatically cast boolean parameters (#6531)
1 parent c8e451d commit 90136dc

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

packages/cubejs-firebolt-driver/src/FireboltQuery.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BaseQuery, ParamAllocator } from '@cubejs-backend/schema-compiler';
1+
import { BaseFilter, BaseQuery, ParamAllocator } from '@cubejs-backend/schema-compiler';
22

33
const GRANULARITY_TO_INTERVAL: Record<string, string> = {
44
day: 'DAY',
@@ -11,6 +11,16 @@ const GRANULARITY_TO_INTERVAL: Record<string, string> = {
1111
year: 'YEAR'
1212
};
1313

14+
class FireboltFilter extends BaseFilter {
15+
public castParameter() {
16+
if (this.definition().type === 'boolean') {
17+
return 'CAST(? AS BOOLEAN)';
18+
}
19+
20+
return '?';
21+
}
22+
}
23+
1424
export class FireboltQuery extends BaseQuery {
1525
public paramAllocator!: ParamAllocator;
1626

@@ -25,4 +35,8 @@ export class FireboltQuery extends BaseQuery {
2535
public timeGroupedColumn(granularity: string, dimension: string) {
2636
return `DATE_TRUNC('${GRANULARITY_TO_INTERVAL[granularity]}', ${dimension})`;
2737
}
38+
39+
public newFilter(filter: any) {
40+
return new FireboltFilter(this, filter);
41+
}
2842
}

packages/cubejs-firebolt-driver/test/FireboltQuery.test.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ cube(\`sales\`, {
2525
salesDatetime: {
2626
type: 'time',
2727
sql: 'sales_datetime'
28-
}
28+
},
29+
isShiped: {
30+
type: 'boolean',
31+
sql: 'is_shiped',
32+
},
2933
}
3034
});
3135
`,
@@ -58,4 +62,28 @@ cube(\`sales\`, {
5862
'DATE_TRUNC(\'DAY\', "sales".sales_datetime)'
5963
);
6064
}));
61-
});
65+
66+
it('should cast BOOLEAN', () => compiler.compile().then(() => {
67+
const query = new FireboltQuery(
68+
{ joinGraph, cubeEvaluator, compiler },
69+
{
70+
measures: ['sales.count'],
71+
filters: [
72+
{
73+
member: "sales.isShiped",
74+
operator: "equals",
75+
values: ["true"]
76+
}
77+
]
78+
}
79+
)
80+
81+
const queryAndParams = query.buildSqlAndParams();
82+
83+
expect(queryAndParams[0]).toContain(
84+
'("sales".is_shiped = CAST(? AS BOOL))'
85+
);
86+
87+
expect(queryAndParams[1]).toEqual(["true"]);
88+
}))
89+
})

0 commit comments

Comments
 (0)