Skip to content

Commit cf0379e

Browse files
committed
[WIP] test: Add multidb SQL pushdown smoke test
1 parent 87a7e5f commit cf0379e

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

packages/cubejs-testing/test/__snapshots__/smoke-multidb.test.ts.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`multidb SQL pushdown queries to different data sources: Products 1`] = `
4+
Array [
5+
Object {
6+
"name": "apples",
7+
},
8+
]
9+
`;
10+
11+
exports[`multidb SQL pushdown queries to different data sources: Suppliers 1`] = `
12+
Array [
13+
Object {
14+
"company": "Fruits Inc",
15+
},
16+
]
17+
`;
18+
319
exports[`multidb query: query 1`] = `
420
Array [
521
Object {

packages/cubejs-testing/test/smoke-cubesql.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ describe('SQL API', () => {
2424
const pgPort = 5656;
2525
let connectionId = 0;
2626

27+
// TODO extract this
2728
async function createPostgresClient(user: string, password: string) {
2829
connectionId++;
2930
const currentConnId = connectionId;

packages/cubejs-testing/test/smoke-multidb.test.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { MysqlDBRunner, PostgresDBRunner } from '@cubejs-backend/testing-shared'
33
import cubejs, { CubeApi } from '@cubejs-client/core';
44
// eslint-disable-next-line import/no-extraneous-dependencies
55
import { afterAll, beforeAll, expect, jest } from '@jest/globals';
6+
import { Client as PgClient } from 'pg';
67
import { BirdBox, getBirdbox } from '../src';
78
import {
89
DEFAULT_API_TOKEN,
@@ -18,6 +19,37 @@ describe('multidb', () => {
1819
let birdbox: BirdBox;
1920
let client: CubeApi;
2021

22+
// TODO bunch of this is a copy-paste
23+
let connection: PgClient;
24+
// TODO: Random port?
25+
const pgPort = 5656;
26+
let connectionId = 0;
27+
async function createPostgresClient(user: string, password: string) {
28+
connectionId++;
29+
const currentConnId = connectionId;
30+
31+
console.debug(`[pg] new connection ${currentConnId}`);
32+
33+
const conn = new PgClient({
34+
database: 'db',
35+
port: pgPort,
36+
host: '127.0.0.1',
37+
user,
38+
password,
39+
ssl: false,
40+
});
41+
conn.on('error', (err) => {
42+
console.log(err);
43+
});
44+
conn.on('end', () => {
45+
console.debug(`[pg] end ${currentConnId}`);
46+
});
47+
48+
await conn.connect();
49+
50+
return conn;
51+
}
52+
2153
beforeAll(async () => {
2254
db = await PostgresDBRunner.startContainer({});
2355
db2 = await MysqlDBRunner.startContainer({});
@@ -39,6 +71,9 @@ describe('multidb', () => {
3971
CUBEJS_DB_USER2: 'root',
4072
CUBEJS_DB_PASS2: 'Test1test',
4173

74+
CUBEJS_PG_SQL_PORT: `${pgPort}`,
75+
CUBESQL_SQL_PUSH_DOWN: 'true',
76+
4277
...DEFAULT_CONFIG,
4378
},
4479
{
@@ -49,6 +84,7 @@ describe('multidb', () => {
4984
client = cubejs(async () => DEFAULT_API_TOKEN, {
5085
apiUrl: birdbox.configuration.apiUrl,
5186
});
87+
connection = await createPostgresClient('admin', 'admin_password');
5288
}, JEST_BEFORE_ALL_DEFAULT_TIMEOUT);
5389

5490
afterAll(async () => {
@@ -69,4 +105,32 @@ describe('multidb', () => {
69105
});
70106
expect(response.rawData()).toMatchSnapshot('query');
71107
});
108+
109+
test('SQL pushdown queries to different data sources: Products', async () => {
110+
const res = await connection.query(`
111+
SELECT
112+
name
113+
FROM
114+
Products
115+
WHERE
116+
LOWER(name) = 'apples'
117+
GROUP BY
118+
1
119+
`);
120+
expect(res.rows).toMatchSnapshot();
121+
});
122+
123+
test('SQL pushdown queries to different data sources: Suppliers', async () => {
124+
const res = await connection.query(`
125+
SELECT
126+
company
127+
FROM
128+
Suppliers
129+
WHERE
130+
LOWER(company) = 'fruits inc'
131+
GROUP BY
132+
1
133+
`);
134+
expect(res.rows).toMatchSnapshot();
135+
});
72136
});

0 commit comments

Comments
 (0)