Skip to content
2 changes: 2 additions & 0 deletions packages/cubejs-schema-compiler/src/adapter/BaseQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -1963,6 +1963,8 @@ export class BaseQuery {
}

/**
* BigQuery has strict date type and can not automatically convert between date
* and timestamp, so we override seriesSql() in BigQuery Dialect
* @param {import('./BaseTimeDimension').BaseTimeDimension} timeDimension
* @return {string}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class BigqueryQuery extends BaseQuery {
const values = timeDimension.timeSeries().map(
([from, to]) => `select '${from}' f, '${to}' t`
).join(' UNION ALL ');
return `SELECT ${this.dateTimeCast('dates.f')} date_from, ${this.dateTimeCast('dates.t')} date_to FROM (${values}) AS dates`;
return `SELECT ${this.timeStampCast('dates.f')} date_from, ${this.timeStampCast('dates.t')} date_to FROM (${values}) AS dates`;
}

public timestampFormat() {
Expand Down
8 changes: 8 additions & 0 deletions packages/cubejs-testing-drivers/fixtures/_schemas.json
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,14 @@
"sql": "profit",
"type": "sum"
},
{
"name": "customersCountPrev1Month",
"type": "count",
"rolling_window": {
"trailing": "1 month",
"offset": "start"
}
},
{
"name": "totalProfitYearAgo",
"type": "number",
Expand Down
1 change: 1 addition & 0 deletions packages/cubejs-testing-drivers/fixtures/clickhouse.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
"querying BigECommerce: rolling window YTD (month + week + no gran)",
"querying BigECommerce: rolling window YTD (month + week + day)",
"querying BigECommerce: rolling window YTD (month + week + day + no gran)",
"querying BigECommerce: time series in rolling window",

"---------------------------------------",
"Requires Tesseract. ",
Expand Down
17 changes: 17 additions & 0 deletions packages/cubejs-testing-drivers/src/tests/testQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,23 @@ export function testQueries(type: string, { includeIncrementalSchemaSuite, exten
expect(response.rawData()).toMatchSnapshot();
});

execute('querying BigECommerce: time series in rolling window', async () => {
const response = await client.load({
measures: [
'BigECommerce.customersCountPrev1Month',
],
timeDimensions: [{
dimension: 'BigECommerce.orderDate',
granularity: 'month',
dateRange: ['2020-01-01', '2020-12-31'],
}],
order: {
'BigECommerce.orderDate': 'asc',
}
});
expect(response.rawData()).toMatchSnapshot();
});

execute('querying BigECommerce: null sum', async () => {
const response = await client.load({
measures: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4411,14 +4411,6 @@ Array [
]
`;

exports[`Queries with the @cubejs-backend/athena-driver querying BigECommerce: rolling window YTD without granularity 1`] = `
Array [
Object {
"BigECommerce.rollingCountYTD": "44",
},
]
`;

exports[`Queries with the @cubejs-backend/athena-driver querying BigECommerce: rolling window YTD without date range 1`] = `
Array [
Object {
Expand Down Expand Up @@ -4484,6 +4476,14 @@ Array [
]
`;

exports[`Queries with the @cubejs-backend/athena-driver querying BigECommerce: rolling window YTD without granularity 1`] = `
Array [
Object {
"BigECommerce.rollingCountYTD": "44",
},
]
`;

exports[`Queries with the @cubejs-backend/athena-driver querying BigECommerce: rolling window by 2 day 1`] = `
Array [
Object {
Expand Down Expand Up @@ -4744,6 +4744,71 @@ Array [
]
`;

exports[`Queries with the @cubejs-backend/athena-driver querying BigECommerce: time series in rolling window 1`] = `
Array [
Object {
"BigECommerce.customersCountPrev1Month": null,
"BigECommerce.orderDate": "2020-01-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-01-01T00:00:00.000",
},
Object {
"BigECommerce.customersCountPrev1Month": "2",
"BigECommerce.orderDate": "2020-02-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-02-01T00:00:00.000",
},
Object {
"BigECommerce.customersCountPrev1Month": "1",
"BigECommerce.orderDate": "2020-03-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-03-01T00:00:00.000",
},
Object {
"BigECommerce.customersCountPrev1Month": "2",
"BigECommerce.orderDate": "2020-04-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-04-01T00:00:00.000",
},
Object {
"BigECommerce.customersCountPrev1Month": "1",
"BigECommerce.orderDate": "2020-05-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-05-01T00:00:00.000",
},
Object {
"BigECommerce.customersCountPrev1Month": "5",
"BigECommerce.orderDate": "2020-06-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-06-01T00:00:00.000",
},
Object {
"BigECommerce.customersCountPrev1Month": "7",
"BigECommerce.orderDate": "2020-07-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-07-01T00:00:00.000",
},
Object {
"BigECommerce.customersCountPrev1Month": null,
"BigECommerce.orderDate": "2020-08-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-08-01T00:00:00.000",
},
Object {
"BigECommerce.customersCountPrev1Month": null,
"BigECommerce.orderDate": "2020-09-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-09-01T00:00:00.000",
},
Object {
"BigECommerce.customersCountPrev1Month": "6",
"BigECommerce.orderDate": "2020-10-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-10-01T00:00:00.000",
},
Object {
"BigECommerce.customersCountPrev1Month": "4",
"BigECommerce.orderDate": "2020-11-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-11-01T00:00:00.000",
},
Object {
"BigECommerce.customersCountPrev1Month": "9",
"BigECommerce.orderDate": "2020-12-01T00:00:00.000",
"BigECommerce.orderDate.month": "2020-12-01T00:00:00.000",
},
]
`;

exports[`Queries with the @cubejs-backend/athena-driver querying BigECommerce: totalProfitYearAgo 1`] = `Array []`;

exports[`Queries with the @cubejs-backend/athena-driver querying Customers: dimensions + limit 1`] = `
Expand Down
Loading
Loading