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
5 changes: 0 additions & 5 deletions packages/cubejs-schema-compiler/src/adapter/AthenaQuery.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import { PrestodbQuery } from './PrestodbQuery';

export class AthenaQuery extends PrestodbQuery {
// Athena doesn't require odd prestodb manual datetime offset calculations
// as it uses mature timestamps models
public override convertTz(field) {
return this.timezone ? `CAST((${field} AT TIME ZONE '${this.timezone}') AS TIMESTAMP)` : field;
}
}
53 changes: 53 additions & 0 deletions packages/cubejs-schema-compiler/test/unit/athena-query.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* eslint-disable no-restricted-syntax */
import { AthenaQuery } from '../../src/adapter/AthenaQuery';
import { prepareJsCompiler } from './PrepareCompiler';

describe('AthenaQuery', () => {
const { compiler, joinGraph, cubeEvaluator } = prepareJsCompiler(`
cube('orders', {
sql: \`
SELECT *
FROM public.orders
\`,
dimensions: {
id: {
sql: \`id\`,
type: 'number',
primaryKey: true
},
created_at: {
sql: \`created_at\`,
type: 'time'
}
},
measures: {
count: {
type: 'count',
}
}
});
`);

it('convertTz uses manual offset calculation (inherits from PrestodbQuery)', async () => {
await compiler.compile();

const query = new AthenaQuery({ joinGraph, cubeEvaluator, compiler }, {
measures: ['orders.count'],
timeDimensions: [{
dimension: 'orders.created_at',
granularity: 'month',
dateRange: ['2026-01-01', '2026-12-31'],
}],
timezone: 'Asia/Kolkata',
});

const queryAndParams = query.buildSqlAndParams();
const sql = queryAndParams[0];

expect(sql).toContain('timezone_hour');
expect(sql).toContain('timezone_minute');
expect(sql).not.toMatch(
/CAST\(\(.*AT TIME ZONE.*\) AS TIMESTAMP\)/
);
});
});
18 changes: 18 additions & 0 deletions packages/cubejs-testing-drivers/src/tests/testQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,24 @@ export function testQueries(type: string, { includeIncrementalSchemaSuite, exten
expect(response.rawData()).toMatchSnapshot();
});

execute('querying ECommerce: count by month + order with non-UTC timezone (Asia/Kolkata)', async () => {
const response = await client.load({
measures: [
'ECommerce.count',
],
timeDimensions: [{
dimension: 'ECommerce.customOrderDateNoPreAgg',
granularity: 'month',
dateRange: ['2020-01-01', '2020-12-31'],
}],
order: {
'ECommerce.customOrderDateNoPreAgg': 'asc'
},
timezone: 'Asia/Kolkata',
});
expect(response.rawData()).toMatchSnapshot();
});

execute('filtering ECommerce: contains dimensions, first', async () => {
const response = await client.load({
dimensions: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14383,3 +14383,58 @@ Array [
},
]
`;

exports[`Queries with the @cubejs-backend/athena-driver querying ECommerce: count by month + order with non-UTC timezone (Asia/Kolkata) 1`] = `
Array [
Object {
"ECommerce.count": "2",
"ECommerce.customOrderDateNoPreAgg": "2020-01-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-01-01T00:00:00.000",
},
Object {
"ECommerce.count": "1",
"ECommerce.customOrderDateNoPreAgg": "2020-02-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-02-01T00:00:00.000",
},
Object {
"ECommerce.count": "2",
"ECommerce.customOrderDateNoPreAgg": "2020-03-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-03-01T00:00:00.000",
},
Object {
"ECommerce.count": "1",
"ECommerce.customOrderDateNoPreAgg": "2020-04-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-04-01T00:00:00.000",
},
Object {
"ECommerce.count": "5",
"ECommerce.customOrderDateNoPreAgg": "2020-05-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-05-01T00:00:00.000",
},
Object {
"ECommerce.count": "7",
"ECommerce.customOrderDateNoPreAgg": "2020-06-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-06-01T00:00:00.000",
},
Object {
"ECommerce.count": "6",
"ECommerce.customOrderDateNoPreAgg": "2020-09-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-09-01T00:00:00.000",
},
Object {
"ECommerce.count": "4",
"ECommerce.customOrderDateNoPreAgg": "2020-10-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-10-01T00:00:00.000",
},
Object {
"ECommerce.count": "9",
"ECommerce.customOrderDateNoPreAgg": "2020-11-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-11-01T00:00:00.000",
},
Object {
"ECommerce.count": "7",
"ECommerce.customOrderDateNoPreAgg": "2020-12-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-12-01T00:00:00.000",
},
]
`;
Original file line number Diff line number Diff line change
Expand Up @@ -18182,3 +18182,58 @@ Array [
},
]
`;

exports[`Queries with the @cubejs-backend/bigquery-driver querying ECommerce: count by month + order with non-UTC timezone (Asia/Kolkata) 1`] = `
Array [
Object {
"ECommerce.count": "2",
"ECommerce.customOrderDateNoPreAgg": "2020-01-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-01-01T00:00:00.000",
},
Object {
"ECommerce.count": "1",
"ECommerce.customOrderDateNoPreAgg": "2020-02-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-02-01T00:00:00.000",
},
Object {
"ECommerce.count": "2",
"ECommerce.customOrderDateNoPreAgg": "2020-03-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-03-01T00:00:00.000",
},
Object {
"ECommerce.count": "1",
"ECommerce.customOrderDateNoPreAgg": "2020-04-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-04-01T00:00:00.000",
},
Object {
"ECommerce.count": "5",
"ECommerce.customOrderDateNoPreAgg": "2020-05-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-05-01T00:00:00.000",
},
Object {
"ECommerce.count": "7",
"ECommerce.customOrderDateNoPreAgg": "2020-06-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-06-01T00:00:00.000",
},
Object {
"ECommerce.count": "6",
"ECommerce.customOrderDateNoPreAgg": "2020-09-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-09-01T00:00:00.000",
},
Object {
"ECommerce.count": "4",
"ECommerce.customOrderDateNoPreAgg": "2020-10-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-10-01T00:00:00.000",
},
Object {
"ECommerce.count": "9",
"ECommerce.customOrderDateNoPreAgg": "2020-11-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-11-01T00:00:00.000",
},
Object {
"ECommerce.count": "7",
"ECommerce.customOrderDateNoPreAgg": "2020-12-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-12-01T00:00:00.000",
},
]
`;
Original file line number Diff line number Diff line change
Expand Up @@ -9209,3 +9209,58 @@ Array [
},
]
`;

exports[`Queries with the @cubejs-backend/clickhouse-driver export-bucket-s3 querying ECommerce: count by month + order with non-UTC timezone (Asia/Kolkata) 1`] = `
Array [
Object {
"ECommerce.count": "2",
"ECommerce.customOrderDateNoPreAgg": "2020-01-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-01-01T00:00:00.000",
},
Object {
"ECommerce.count": "1",
"ECommerce.customOrderDateNoPreAgg": "2020-02-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-02-01T00:00:00.000",
},
Object {
"ECommerce.count": "2",
"ECommerce.customOrderDateNoPreAgg": "2020-03-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-03-01T00:00:00.000",
},
Object {
"ECommerce.count": "1",
"ECommerce.customOrderDateNoPreAgg": "2020-04-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-04-01T00:00:00.000",
},
Object {
"ECommerce.count": "5",
"ECommerce.customOrderDateNoPreAgg": "2020-05-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-05-01T00:00:00.000",
},
Object {
"ECommerce.count": "7",
"ECommerce.customOrderDateNoPreAgg": "2020-06-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-06-01T00:00:00.000",
},
Object {
"ECommerce.count": "6",
"ECommerce.customOrderDateNoPreAgg": "2020-09-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-09-01T00:00:00.000",
},
Object {
"ECommerce.count": "4",
"ECommerce.customOrderDateNoPreAgg": "2020-10-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-10-01T00:00:00.000",
},
Object {
"ECommerce.count": "9",
"ECommerce.customOrderDateNoPreAgg": "2020-11-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-11-01T00:00:00.000",
},
Object {
"ECommerce.count": "7",
"ECommerce.customOrderDateNoPreAgg": "2020-12-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-12-01T00:00:00.000",
},
]
`;
Original file line number Diff line number Diff line change
Expand Up @@ -9209,3 +9209,58 @@ Array [
},
]
`;

exports[`Queries with the @cubejs-backend/clickhouse-driver export-bucket-s3-prefix querying ECommerce: count by month + order with non-UTC timezone (Asia/Kolkata) 1`] = `
Array [
Object {
"ECommerce.count": "2",
"ECommerce.customOrderDateNoPreAgg": "2020-01-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-01-01T00:00:00.000",
},
Object {
"ECommerce.count": "1",
"ECommerce.customOrderDateNoPreAgg": "2020-02-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-02-01T00:00:00.000",
},
Object {
"ECommerce.count": "2",
"ECommerce.customOrderDateNoPreAgg": "2020-03-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-03-01T00:00:00.000",
},
Object {
"ECommerce.count": "1",
"ECommerce.customOrderDateNoPreAgg": "2020-04-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-04-01T00:00:00.000",
},
Object {
"ECommerce.count": "5",
"ECommerce.customOrderDateNoPreAgg": "2020-05-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-05-01T00:00:00.000",
},
Object {
"ECommerce.count": "7",
"ECommerce.customOrderDateNoPreAgg": "2020-06-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-06-01T00:00:00.000",
},
Object {
"ECommerce.count": "6",
"ECommerce.customOrderDateNoPreAgg": "2020-09-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-09-01T00:00:00.000",
},
Object {
"ECommerce.count": "4",
"ECommerce.customOrderDateNoPreAgg": "2020-10-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-10-01T00:00:00.000",
},
Object {
"ECommerce.count": "9",
"ECommerce.customOrderDateNoPreAgg": "2020-11-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-11-01T00:00:00.000",
},
Object {
"ECommerce.count": "7",
"ECommerce.customOrderDateNoPreAgg": "2020-12-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-12-01T00:00:00.000",
},
]
`;
Original file line number Diff line number Diff line change
Expand Up @@ -10019,3 +10019,58 @@ Array [
},
]
`;

exports[`Queries with the @cubejs-backend/clickhouse-driver querying ECommerce: count by month + order with non-UTC timezone (Asia/Kolkata) 1`] = `
Array [
Object {
"ECommerce.count": "2",
"ECommerce.customOrderDateNoPreAgg": "2020-01-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-01-01T00:00:00.000",
},
Object {
"ECommerce.count": "1",
"ECommerce.customOrderDateNoPreAgg": "2020-02-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-02-01T00:00:00.000",
},
Object {
"ECommerce.count": "2",
"ECommerce.customOrderDateNoPreAgg": "2020-03-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-03-01T00:00:00.000",
},
Object {
"ECommerce.count": "1",
"ECommerce.customOrderDateNoPreAgg": "2020-04-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-04-01T00:00:00.000",
},
Object {
"ECommerce.count": "5",
"ECommerce.customOrderDateNoPreAgg": "2020-05-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-05-01T00:00:00.000",
},
Object {
"ECommerce.count": "7",
"ECommerce.customOrderDateNoPreAgg": "2020-06-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-06-01T00:00:00.000",
},
Object {
"ECommerce.count": "6",
"ECommerce.customOrderDateNoPreAgg": "2020-09-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-09-01T00:00:00.000",
},
Object {
"ECommerce.count": "4",
"ECommerce.customOrderDateNoPreAgg": "2020-10-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-10-01T00:00:00.000",
},
Object {
"ECommerce.count": "9",
"ECommerce.customOrderDateNoPreAgg": "2020-11-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-11-01T00:00:00.000",
},
Object {
"ECommerce.count": "7",
"ECommerce.customOrderDateNoPreAgg": "2020-12-01T00:00:00.000",
"ECommerce.customOrderDateNoPreAgg.month": "2020-12-01T00:00:00.000",
},
]
`;
Loading
Loading