Skip to content

Commit 9c6153d

Browse files
authored
fix(api-gateway): Fix CompareDateRange queries native transformations (#9232)
* fix(api-gateway): Fix CompareDateRange queries native transformations * fix versions / sync * trying to add smoke tests...
1 parent 2dd9a4a commit 9c6153d

File tree

6 files changed

+88
-9
lines changed

6 files changed

+88
-9
lines changed

packages/cubejs-testing/test/driver-postgres.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
import { mainTestSet, preAggsTestSet, productionTestSet } from './driverTests/testSets';
1+
import { mainTestSet, multiQueryTestSet, preAggsTestSet, productionTestSet } from './driverTests/testSets';
22
import { executeTestSuite } from './driver-test-suite';
33

44
executeTestSuite({
55
type: 'postgres',
66
tests: mainTestSet,
77
});
88

9+
executeTestSuite({
10+
type: 'postgres',
11+
tests: multiQueryTestSet,
12+
});
13+
914
executeTestSuite({
1015
type: 'postgres',
1116
tests: mainTestSet,

packages/cubejs-testing/test/driver-test-suite.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export function executeTestSuite({ type, tests, config = {} }: TestSuite) {
6868
for (const t of tests) {
6969
const jsonConfig = JSON.stringify(overridedConfig);
7070
const testNameWithHash = `${t.name}_${jsonConfig}`;
71-
71+
7272
if (t.type === 'basic') {
7373
// eslint-disable-next-line no-loop-func
7474
const cbFn = async () => {
@@ -83,6 +83,26 @@ export function executeTestSuite({ type, tests, config = {} }: TestSuite) {
8383
}
8484
};
8585

86+
if (t.skip) {
87+
test.skip(testNameWithHash, cbFn);
88+
} else {
89+
test(testNameWithHash, cbFn);
90+
}
91+
} else if (t.type === 'multi') {
92+
// eslint-disable-next-line no-loop-func
93+
const cbFn = async () => {
94+
const response = await client.load(t.query);
95+
96+
const resultSets = response.decompose();
97+
expect(resultSets).toMatchSnapshot('query');
98+
99+
if (t.expectArray) {
100+
for (const expectFn of t.expectArray) {
101+
expectFn(response);
102+
}
103+
}
104+
};
105+
86106
if (t.skip) {
87107
test.skip(testNameWithHash, cbFn);
88108
} else {

packages/cubejs-testing/test/driverTests/driverTest.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export type TestType = 'basic' | 'withError' | 'testFn';
77

88
type DriverTestArg = {
99
name: string;
10-
query: Query;
10+
query: Query | Query[];
1111
expectArray?: ((response: ResultSet<QueryRecordType<Query>>) => any)[];
1212
schemas: Schemas;
1313
skip?: boolean;
@@ -23,7 +23,7 @@ type DriverTestWithErrorArg = {
2323

2424
export type DriverTestBasic = {
2525
name: string,
26-
query: Query,
26+
query: Query | Query[],
2727
expectArray?: ((response: ResultSet<QueryRecordType<Query>>) => any)[]
2828
schemas: Schemas,
2929
skip?: boolean;
@@ -32,13 +32,22 @@ export type DriverTestBasic = {
3232

3333
export type DriverTestWithError = {
3434
name: string;
35-
query: Query;
35+
query: Query | Query[];
3636
expectArray?: ((e: Error) => any)[];
3737
schemas: Schemas;
3838
skip?: boolean;
3939
type: 'withError';
4040
};
4141

42+
export type DriverTestMulti = {
43+
name: string,
44+
query: Query | Query[],
45+
expectArray?: ((response: ResultSet<QueryRecordType<Query>>) => any)[]
46+
schemas: Schemas,
47+
skip?: boolean;
48+
type: 'multi';
49+
};
50+
4251
type DriverTestFnArg = {
4352
name: string;
4453
schemas: Schemas,
@@ -50,7 +59,7 @@ export type DriverTestFn = DriverTestFnArg & {
5059
type: 'testFn';
5160
};
5261

53-
export type DriverTest = DriverTestBasic | DriverTestWithError | DriverTestFn;
62+
export type DriverTest = DriverTestBasic | DriverTestWithError | DriverTestFn | DriverTestMulti;
5463

5564
export function driverTest(
5665
{ name, query, expectArray = [], skip, schemas }: DriverTestArg
@@ -70,6 +79,12 @@ export function driverTestFn(
7079
return { name, testFn, schemas, skip, type: 'testFn' };
7180
}
7281

82+
export function driverTestMulti(
83+
{ name, query, expectArray = [], skip, schemas }: DriverTestArg
84+
): DriverTestMulti {
85+
return { name, query, expectArray, schemas, skip, type: 'multi' };
86+
}
87+
7388
export function testSet(tests: DriverTest[]) {
7489
const uniqTests = uniqBy((t) => t.name, tests);
7590
return uniqTests;

packages/cubejs-testing/test/driverTests/testSets.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import {
6262
hiddenCube,
6363
viewMetaExposed,
6464
preAggsCustomersRunningTotal,
65+
queryingECommerceCompareDateRangesByCustomerOverProductNameByMonth,
6566
} from './tests';
6667
import { testSet } from './driverTest';
6768

@@ -156,3 +157,7 @@ export const productionTestSet = testSet([
156157
hiddenMember,
157158
hiddenCube,
158159
]);
160+
161+
export const multiQueryTestSet = testSet([
162+
queryingECommerceCompareDateRangesByCustomerOverProductNameByMonth,
163+
]);

packages/cubejs-testing/test/driverTests/tests.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// eslint-disable-next-line import/no-extraneous-dependencies
22
import { expect } from '@jest/globals';
3-
import { driverTest, driverTestFn, driverTestWithError } from './driverTest';
3+
import { driverTest, driverTestFn, driverTestMulti, driverTestWithError } from './driverTest';
44

55
const commonSchemas = [
66
'CAST.js',
@@ -189,7 +189,7 @@ export const filteringCustomersCubeThird = driverTest(
189189
},
190190
schemas: commonSchemas,
191191
}
192-
192+
193193
);
194194

195195
export const filteringCustomersEndsWithFilterFirst = driverTest({
@@ -1296,6 +1296,31 @@ export const preAggsCustomersRunningTotal = driverTest({
12961296
schemas: commonSchemas
12971297
});
12981298

1299+
export const queryingECommerceCompareDateRangesByCustomerOverProductNameByMonth = driverTestMulti({
1300+
name: 'querying ECommerce: compare DateRanges by customer over productName by month',
1301+
query: [{
1302+
timeDimensions: [{
1303+
dimension: 'ECommerce.orderDate',
1304+
granularity: 'month',
1305+
compareDateRange: [
1306+
['2023-01-01', '2024-01-01'],
1307+
['2024-01-01', '2025-01-01']
1308+
]
1309+
}],
1310+
dimensions: [
1311+
'ECommerce.productName'
1312+
],
1313+
measures: [
1314+
'ECommerce.count'
1315+
],
1316+
order: {
1317+
'ECommerce.orderDate': 'desc',
1318+
'ECommerce.productName': 'asc',
1319+
},
1320+
}],
1321+
schemas: commonSchemas
1322+
});
1323+
12991324
export const queryingEcommerceTotalQuantifyAvgDiscountTotal = driverTestWithError({
13001325
name: 'querying ECommerce: total quantity, avg discount, total ' +
13011326
'sales, total profit by product + order + total -- noisy ' +

rust/cubeorchestrator/src/transport.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ pub struct GroupingSet {
8282
pub sub_id: Option<u32>,
8383
}
8484

85+
#[derive(Debug, Clone, Serialize, Deserialize)]
86+
#[serde(untagged)]
87+
pub enum CompareDateRangeType {
88+
Single(Vec<String>),
89+
Multi(Vec<Vec<String>>),
90+
}
91+
8592
// We can do nothing with JS functions here,
8693
// but to keep DTOs in sync with reality, let's keep it.
8794
pub type JsFunction = String;
@@ -120,7 +127,7 @@ pub struct ParsedMemberExpression {
120127
pub struct QueryTimeDimension {
121128
pub dimension: String,
122129
pub date_range: Option<Vec<String>>,
123-
pub compare_date_range: Option<Vec<String>>,
130+
pub compare_date_range: Option<CompareDateRangeType>,
124131
pub granularity: Option<String>,
125132
}
126133

@@ -161,6 +168,8 @@ pub struct ConfigItem {
161168
pub drill_members_grouped: Option<DrillMembersGrouped>,
162169
#[serde(skip_serializing_if = "Option::is_none")]
163170
pub granularities: Option<Vec<GranularityMeta>>,
171+
#[serde(skip_serializing_if = "Option::is_none")]
172+
pub granularity: Option<GranularityMeta>,
164173
}
165174

166175
#[derive(Debug, Clone, Serialize, Deserialize)]

0 commit comments

Comments
 (0)