@@ -3,6 +3,7 @@ import { MysqlDBRunner, PostgresDBRunner } from '@cubejs-backend/testing-shared'
33import cubejs , { CubeApi } from '@cubejs-client/core' ;
44// eslint-disable-next-line import/no-extraneous-dependencies
55import { afterAll , beforeAll , expect , jest } from '@jest/globals' ;
6+ import { Client as PgClient } from 'pg' ;
67import { BirdBox , getBirdbox } from '../src' ;
78import {
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