-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tesseract): Support multiple join paths within single query
- Loading branch information
1 parent
a56462e
commit 278fef1
Showing
20 changed files
with
555 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
packages/cubejs-schema-compiler/test/integration/postgres/multi-fact-join.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import { PostgresQuery } from '../../../src/adapter/PostgresQuery'; | ||
import { prepareCompiler } from '../../unit/PrepareCompiler'; | ||
import { dbRunner } from './PostgresDBRunner'; | ||
import { | ||
getEnv, | ||
} from '@cubejs-backend/shared'; | ||
|
||
describe('Multi-fact join', () => { | ||
jest.setTimeout(200000); | ||
|
||
const { compiler, joinGraph, cubeEvaluator } = prepareCompiler(` | ||
cube(\`orders\`, { | ||
sql: \` | ||
SELECT 79 AS id, 1 AS amount, 1 AS city_id UNION ALL | ||
SELECT 80 AS id, 2 AS amount, 1 AS city_id UNION ALL | ||
SELECT 81 AS id, 3 AS amount, 1 AS city_id UNION ALL | ||
SELECT 82 AS id, 4 AS amount, 2 AS city_id UNION ALL | ||
SELECT 83 AS id, 5 AS amount, 2 AS city_id UNION ALL | ||
SELECT 84 AS id, 6 AS amount, 3 AS city_id | ||
\`, | ||
joins: { | ||
city: { | ||
relationship: \`many_to_one\`, | ||
sql: \`\${orders}.city_id = \${city}.id\`, | ||
}, | ||
}, | ||
measures: { | ||
amount: { | ||
sql: \`amount\`, | ||
type: 'sum' | ||
} | ||
}, | ||
dimensions: { | ||
id: { | ||
sql: \`id\`, | ||
type: \`number\`, | ||
primaryKey: true, | ||
}, | ||
}, | ||
}); | ||
cube(\`shipments\`, { | ||
sql: \` | ||
SELECT 100 AS id, 1 AS foo_id, 1 AS city_id UNION ALL | ||
SELECT 101 AS id, 2 AS foo_id, 2 AS city_id UNION ALL | ||
SELECT 102 AS id, 3 AS foo_id, 2 AS city_id UNION ALL | ||
SELECT 103 AS id, 4 AS foo_id, 2 AS city_id UNION ALL | ||
SELECT 104 AS id, 5 AS foo_id, 4 AS city_id | ||
\`, | ||
joins: { | ||
city: { | ||
relationship: \`many_to_one\`, | ||
sql: \`\${shipments}.city_id = \${city}.id\`, | ||
}, | ||
}, | ||
measures: { | ||
count: { | ||
type: \`count\` | ||
}, | ||
}, | ||
dimensions: { | ||
id: { | ||
sql: \`id\`, | ||
type: \`number\`, | ||
primaryKey: true, | ||
shown: true | ||
}, | ||
} | ||
}); | ||
cube(\`city\`, { | ||
sql: \` | ||
SELECT 1 AS id, 'San Francisco' AS name UNION ALL | ||
SELECT 2 AS id, 'New York City' AS name | ||
\`, | ||
dimensions: { | ||
id: { | ||
sql: \`id\`, | ||
type: \`number\`, | ||
primaryKey: true, | ||
}, | ||
name: { | ||
sql: \`\${CUBE}.name\`, | ||
type: \`string\`, | ||
}, | ||
}, | ||
}); | ||
`); | ||
|
||
async function runQueryTest(q, expectedResult) { | ||
if (!getEnv('nativeSqlPlanner')) { | ||
return; | ||
} | ||
await compiler.compile(); | ||
const query = new PostgresQuery({ joinGraph, cubeEvaluator, compiler }, q); | ||
|
||
console.log(query.buildSqlAndParams()); | ||
|
||
const res = await dbRunner.testQuery(query.buildSqlAndParams()); | ||
console.log(JSON.stringify(res)); | ||
|
||
expect(res).toEqual( | ||
expectedResult | ||
); | ||
} | ||
|
||
it('two regular sub-queries', async () => runQueryTest({ | ||
measures: ['orders.amount', 'shipments.count'], | ||
dimensions: [ | ||
'city.name' | ||
], | ||
order: [{ id: 'city.name' }] | ||
}, [{ | ||
city__name: 'New York City', | ||
orders__amount: '9', | ||
shipments__count: '3', | ||
}, { | ||
city__name: 'San Francisco', | ||
orders__amount: '6', | ||
shipments__count: '1', | ||
}, { | ||
city__name: null, | ||
orders__amount: '6', | ||
shipments__count: '1', | ||
}])); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.