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
7 changes: 6 additions & 1 deletion packages/cubejs-testing/test/driver-postgres.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { mainTestSet, preAggsTestSet, productionTestSet } from './driverTests/testSets';
import { mainTestSet, multiQueryTestSet, preAggsTestSet, productionTestSet } from './driverTests/testSets';
import { executeTestSuite } from './driver-test-suite';

executeTestSuite({
type: 'postgres',
tests: mainTestSet,
});

executeTestSuite({
type: 'postgres',
tests: multiQueryTestSet,
});

executeTestSuite({
type: 'postgres',
tests: mainTestSet,
Expand Down
22 changes: 21 additions & 1 deletion packages/cubejs-testing/test/driver-test-suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function executeTestSuite({ type, tests, config = {} }: TestSuite) {
for (const t of tests) {
const jsonConfig = JSON.stringify(overridedConfig);
const testNameWithHash = `${t.name}_${jsonConfig}`;

if (t.type === 'basic') {
// eslint-disable-next-line no-loop-func
const cbFn = async () => {
Expand All @@ -83,6 +83,26 @@ export function executeTestSuite({ type, tests, config = {} }: TestSuite) {
}
};

if (t.skip) {
test.skip(testNameWithHash, cbFn);
} else {
test(testNameWithHash, cbFn);
}
} else if (t.type === 'multi') {
// eslint-disable-next-line no-loop-func
const cbFn = async () => {
const response = await client.load(t.query);

const resultSets = response.decompose();
expect(resultSets).toMatchSnapshot('query');

if (t.expectArray) {
for (const expectFn of t.expectArray) {
expectFn(response);
}
}
};

if (t.skip) {
test.skip(testNameWithHash, cbFn);
} else {
Expand Down
23 changes: 19 additions & 4 deletions packages/cubejs-testing/test/driverTests/driverTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type TestType = 'basic' | 'withError' | 'testFn';

type DriverTestArg = {
name: string;
query: Query;
query: Query | Query[];
expectArray?: ((response: ResultSet<QueryRecordType<Query>>) => any)[];
schemas: Schemas;
skip?: boolean;
Expand All @@ -23,7 +23,7 @@ type DriverTestWithErrorArg = {

export type DriverTestBasic = {
name: string,
query: Query,
query: Query | Query[],
expectArray?: ((response: ResultSet<QueryRecordType<Query>>) => any)[]
schemas: Schemas,
skip?: boolean;
Expand All @@ -32,13 +32,22 @@ export type DriverTestBasic = {

export type DriverTestWithError = {
name: string;
query: Query;
query: Query | Query[];
expectArray?: ((e: Error) => any)[];
schemas: Schemas;
skip?: boolean;
type: 'withError';
};

export type DriverTestMulti = {
name: string,
query: Query | Query[],
expectArray?: ((response: ResultSet<QueryRecordType<Query>>) => any)[]
schemas: Schemas,
skip?: boolean;
type: 'multi';
};

type DriverTestFnArg = {
name: string;
schemas: Schemas,
Expand All @@ -50,7 +59,7 @@ export type DriverTestFn = DriverTestFnArg & {
type: 'testFn';
};

export type DriverTest = DriverTestBasic | DriverTestWithError | DriverTestFn;
export type DriverTest = DriverTestBasic | DriverTestWithError | DriverTestFn | DriverTestMulti;

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

export function driverTestMulti(
{ name, query, expectArray = [], skip, schemas }: DriverTestArg
): DriverTestMulti {
return { name, query, expectArray, schemas, skip, type: 'multi' };
}

export function testSet(tests: DriverTest[]) {
const uniqTests = uniqBy((t) => t.name, tests);
return uniqTests;
Expand Down
5 changes: 5 additions & 0 deletions packages/cubejs-testing/test/driverTests/testSets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import {
hiddenCube,
viewMetaExposed,
preAggsCustomersRunningTotal,
queryingECommerceCompareDateRangesByCustomerOverProductNameByMonth,
} from './tests';
import { testSet } from './driverTest';

Expand Down Expand Up @@ -156,3 +157,7 @@ export const productionTestSet = testSet([
hiddenMember,
hiddenCube,
]);

export const multiQueryTestSet = testSet([
queryingECommerceCompareDateRangesByCustomerOverProductNameByMonth,
]);
29 changes: 27 additions & 2 deletions packages/cubejs-testing/test/driverTests/tests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { expect } from '@jest/globals';
import { driverTest, driverTestFn, driverTestWithError } from './driverTest';
import { driverTest, driverTestFn, driverTestMulti, driverTestWithError } from './driverTest';

const commonSchemas = [
'CAST.js',
Expand Down Expand Up @@ -189,7 +189,7 @@ export const filteringCustomersCubeThird = driverTest(
},
schemas: commonSchemas,
}

);

export const filteringCustomersEndsWithFilterFirst = driverTest({
Expand Down Expand Up @@ -1296,6 +1296,31 @@ export const preAggsCustomersRunningTotal = driverTest({
schemas: commonSchemas
});

export const queryingECommerceCompareDateRangesByCustomerOverProductNameByMonth = driverTestMulti({
name: 'querying ECommerce: compare DateRanges by customer over productName by month',
query: [{
timeDimensions: [{
dimension: 'ECommerce.orderDate',
granularity: 'month',
compareDateRange: [
['2023-01-01', '2024-01-01'],
['2024-01-01', '2025-01-01']
]
}],
dimensions: [
'ECommerce.productName'
],
measures: [
'ECommerce.count'
],
order: {
'ECommerce.orderDate': 'desc',
'ECommerce.productName': 'asc',
},
}],
schemas: commonSchemas
});

export const queryingEcommerceTotalQuantifyAvgDiscountTotal = driverTestWithError({
name: 'querying ECommerce: total quantity, avg discount, total ' +
'sales, total profit by product + order + total -- noisy ' +
Expand Down
11 changes: 10 additions & 1 deletion rust/cubeorchestrator/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ pub struct GroupingSet {
pub sub_id: Option<u32>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CompareDateRangeType {
Single(Vec<String>),
Multi(Vec<Vec<String>>),
}

// We can do nothing with JS functions here,
// but to keep DTOs in sync with reality, let's keep it.
pub type JsFunction = String;
Expand Down Expand Up @@ -120,7 +127,7 @@ pub struct ParsedMemberExpression {
pub struct QueryTimeDimension {
pub dimension: String,
pub date_range: Option<Vec<String>>,
pub compare_date_range: Option<Vec<String>>,
pub compare_date_range: Option<CompareDateRangeType>,
pub granularity: Option<String>,
}

Expand Down Expand Up @@ -161,6 +168,8 @@ pub struct ConfigItem {
pub drill_members_grouped: Option<DrillMembersGrouped>,
#[serde(skip_serializing_if = "Option::is_none")]
pub granularities: Option<Vec<GranularityMeta>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub granularity: Option<GranularityMeta>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
4 changes: 2 additions & 2 deletions rust/cubestore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"author": "Cube Dev, Inc.",
"license": "Apache-2.0",
"devDependencies": {
"@cubejs-backend/linter": "1.2.4",
"@cubejs-backend/linter": "1.2.5",
"@types/jest": "^27",
"@types/node": "^12",
"jest": "^27",
Expand All @@ -37,7 +37,7 @@
"access": "public"
},
"dependencies": {
"@cubejs-backend/shared": "1.2.4",
"@cubejs-backend/shared": "1.2.5",
"@octokit/core": "^3.2.5",
"source-map-support": "^0.5.19"
},
Expand Down
Loading