Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/cubejs-duckdb-driver/src/DuckDBQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ const GRANULARITY_TO_INTERVAL: Record<string, (date: string) => string> = {
};

class DuckDBFilter extends BaseFilter {
public castParameter() {
const numberTypes = ['number', 'count', 'count_distinct', 'count_distinct_approx', 'sum', 'avg', 'min', 'max'];
const definition = this.definition();

if (numberTypes.includes(definition.type)) {
return 'CAST(? AS DOUBLE)';
}

return '?';
}
}

export class DuckDBQuery extends BaseQuery {
Expand Down Expand Up @@ -55,4 +65,12 @@ export class DuckDBQuery extends BaseQuery {
templates.functions.GREATEST = 'GREATEST({{ args_concat }})';
return templates;
}

public timeStampParam(timeDimension: any) {
if (timeDimension.measure) {
// For time measures, we don't need to check dateFieldType
return super.timeStampCast('?');
}
return super.timeStampParam(timeDimension);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
cube(`Orders`, {
sql: `
select id, amount, status from (
select 1 as id, 100 as amount, 'new' status
select id, amount, status, created_at, is_paid from (
select 1 as id, 100 as amount, 'new' status, TIMESTAMPTZ '2020-01-01 00:00:00' created_at, TRUE as is_paid
UNION ALL
select 2 as id, 200 as amount, 'new' status
select 2 as id, 200 as amount, 'new' status, TIMESTAMPTZ '2020-01-02 00:00:00' created_at, TRUE as is_paid
UNION ALL
select 3 as id, 300 as amount, 'processed' status
select 3 as id, 300 as amount, 'processed' status, TIMESTAMPTZ '2020-01-03 00:00:00' created_at, TRUE as is_paid
UNION ALL
select 4 as id, 500 as amount, 'processed' status
select 4 as id, 500 as amount, 'processed' status, TIMESTAMPTZ '2020-01-04 00:00:00' created_at, FALSE as is_paid
UNION ALL
select 5 as id, 600 as amount, 'shipped' status
select 5 as id, 600 as amount, 'shipped' status, TIMESTAMPTZ '2020-01-05 00:00:00' created_at, FALSE as is_paid
)
`,
measures: {
Expand All @@ -20,6 +20,26 @@ cube(`Orders`, {
sql: `amount`,
type: `sum`,
},
avgAmount: {
sql: `amount`,
type: `avg`,
},
statusList: {
sql: `status`,
type: `string`,
},
lastStatus: {
sql: `MAX(status)`,
type: `string`,
},
hasUnpaidOrders: {
sql: `BOOL_OR(NOT is_paid)`,
type: `boolean`,
},
maxCreatedAt: {
sql: `MAX(created_at)`,
type: `time`,
},
toRemove: {
type: `count`,
},
Expand All @@ -29,5 +49,17 @@ cube(`Orders`, {
sql: `status`,
type: `string`,
},
amount: {
sql: `amount`,
type: `number`,
},
isPaid: {
sql: `is_paid`,
type: `boolean`,
},
createdAt: {
sql: `created_at`,
type: `time`,
},
},
});
Loading
Loading