Skip to content

Commit 488e0c9

Browse files
committed
Use the Trino client instead of inheriting from Presto
1 parent 5593a2a commit 488e0c9

File tree

11 files changed

+345
-56
lines changed

11 files changed

+345
-56
lines changed

.github/actions/smoke.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ echo "::endgroup::"
4545
#yarn lerna run --concurrency 1 --stream --no-prefix smoke:prestodb
4646
#echo "::endgroup::"
4747

48-
echo "::group::Trino"
49-
yarn lerna run --concurrency 1 --stream --no-prefix smoke:trino
50-
echo "::endgroup::"
48+
#echo "::group::Trino"
49+
#yarn lerna run --concurrency 1 --stream --no-prefix smoke:trino
50+
#echo "::endgroup::"
5151

5252
echo "::group::MS SQL"
5353
yarn lerna run --concurrency 1 --stream --no-prefix smoke:mssql
5454
echo "::endgroup::"
5555

5656
echo "::group::MongoBI"
5757
yarn lerna run --concurrency 1 --stream --no-prefix smoke:mongobi
58-
echo "::endgroup::"
58+
echo "::endgroup::"

docs/pages/product/configuration/data-sources/trino.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ CUBEJS_DB_TYPE=trino
2222
CUBEJS_DB_HOST=my.trino.host
2323
CUBEJS_DB_USER=trino_user
2424
CUBEJS_DB_PASS=**********
25-
CUBEJS_DB_PRESTO_CATALOG=my_trino_catalog
25+
CUBEJS_DB_TRINO_CATALOG=my_trino_catalog
2626
CUBEJS_DB_SCHEMA=my_trino_schema
2727
```
2828

@@ -34,9 +34,8 @@ CUBEJS_DB_SCHEMA=my_trino_schema
3434
| `CUBEJS_DB_PORT` | The port for the database connection | A valid port number ||
3535
| `CUBEJS_DB_USER` | The username used to connect to the database | A valid database username ||
3636
| `CUBEJS_DB_PASS` | The password used to connect to the database | A valid database password ||
37-
| `CUBEJS_DB_PRESTO_CATALOG` | The catalog within Presto to connect to | A valid catalog name within a Presto database ||
37+
| `CUBEJS_DB_TRINO_CATALOG` | The catalog within Presto to connect to | A valid catalog name within a Presto database ||
3838
| `CUBEJS_DB_SCHEMA` | The schema within the database to connect to | A valid schema name within a Presto database ||
39-
| `CUBEJS_DB_SSL` | If `true`, enables SSL encryption for database connections from Cube | `true`, `false` ||
4039
| `CUBEJS_CONCURRENCY` | The number of concurrent connections each queue has to the database. Default is `2` | A valid number ||
4140
| `CUBEJS_DB_MAX_POOL` | The maximum number of concurrent database connections to pool. Default is `8` | A valid number ||
4241

packages/cubejs-backend-shared/src/env.ts

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ export function assertDataSource(dataSource = 'default'): string {
6666
return dataSource;
6767
} else {
6868
throw new Error(
69-
`The ${
70-
dataSource
69+
`The ${dataSource
7170
} data source is missing in the declared CUBEJS_DATASOURCES.`
7271
);
7372
}
@@ -90,10 +89,8 @@ export function keyByDataSource(origin: string, dataSource?: string): string {
9089
return `CUBEJS_DS_${dataSource.toUpperCase()}_${s[1]}`;
9190
} else {
9291
throw new Error(
93-
`The ${
94-
origin
95-
} environment variable can not be converted for the ${
96-
dataSource
92+
`The ${origin
93+
} environment variable can not be converted for the ${dataSource
9794
} data source.`
9895
);
9996
}
@@ -237,8 +234,7 @@ const variables: Record<string, (...args: any) => any> = {
237234
return false;
238235
} else {
239236
throw new TypeError(
240-
`The ${
241-
keyByDataSource('CUBEJS_DB_SSL', dataSource)
237+
`The ${keyByDataSource('CUBEJS_DB_SSL', dataSource)
242238
} must be either 'true' or 'false'.`
243239
);
244240
}
@@ -261,8 +257,7 @@ const variables: Record<string, (...args: any) => any> = {
261257
return false;
262258
} else {
263259
throw new TypeError(
264-
`The ${
265-
keyByDataSource('CUBEJS_DB_SSL_REJECT_UNAUTHORIZED', dataSource)
260+
`The ${keyByDataSource('CUBEJS_DB_SSL_REJECT_UNAUTHORIZED', dataSource)
266261
} must be either 'true' or 'false'.`
267262
);
268263
}
@@ -353,8 +348,7 @@ const variables: Record<string, (...args: any) => any> = {
353348
}) => (
354349
process.env[keyByDataSource('CUBEJS_DB_PORT', dataSource)]
355350
? parseInt(
356-
`${
357-
process.env[keyByDataSource('CUBEJS_DB_PORT', dataSource)]
351+
`${process.env[keyByDataSource('CUBEJS_DB_PORT', dataSource)]
358352
}`,
359353
10,
360354
)
@@ -409,8 +403,7 @@ const variables: Record<string, (...args: any) => any> = {
409403
];
410404
if (required && !val) {
411405
throw new Error(
412-
`The ${
413-
keyByDataSource('CUBEJS_DB_NAME', dataSource)
406+
`The ${keyByDataSource('CUBEJS_DB_NAME', dataSource)
414407
} is required and missing.`
415408
);
416409
}
@@ -429,19 +422,16 @@ const variables: Record<string, (...args: any) => any> = {
429422
required?: boolean,
430423
}) => {
431424
console.warn(
432-
`The ${
433-
keyByDataSource('CUBEJS_DB_SCHEMA', dataSource)
434-
} is deprecated. Please, use the ${
435-
keyByDataSource('CUBEJS_DB_NAME', dataSource)
425+
`The ${keyByDataSource('CUBEJS_DB_SCHEMA', dataSource)
426+
} is deprecated. Please, use the ${keyByDataSource('CUBEJS_DB_NAME', dataSource)
436427
} instead.`
437428
);
438429
const val = process.env[
439430
keyByDataSource('CUBEJS_DB_SCHEMA', dataSource)
440431
];
441432
if (required && !val) {
442433
throw new Error(
443-
`The ${
444-
keyByDataSource('CUBEJS_DB_SCHEMA', dataSource)
434+
`The ${keyByDataSource('CUBEJS_DB_SCHEMA', dataSource)
445435
} is required and missing.`
446436
);
447437
}
@@ -460,19 +450,16 @@ const variables: Record<string, (...args: any) => any> = {
460450
required?: boolean,
461451
}) => {
462452
console.warn(
463-
`The ${
464-
keyByDataSource('CUBEJS_DATABASE', dataSource)
465-
} is deprecated. Please, use the ${
466-
keyByDataSource('CUBEJS_DB_NAME', dataSource)
453+
`The ${keyByDataSource('CUBEJS_DATABASE', dataSource)
454+
} is deprecated. Please, use the ${keyByDataSource('CUBEJS_DB_NAME', dataSource)
467455
} instead.`
468456
);
469457
const val = process.env[
470458
keyByDataSource('CUBEJS_DATABASE', dataSource)
471459
];
472460
if (required && !val) {
473461
throw new Error(
474-
`The ${
475-
keyByDataSource('CUBEJS_DATABASE', dataSource)
462+
`The ${keyByDataSource('CUBEJS_DATABASE', dataSource)
476463
} is required and missing.`
477464
);
478465
}
@@ -489,10 +476,9 @@ const variables: Record<string, (...args: any) => any> = {
489476
}) => (
490477
process.env[keyByDataSource('CUBEJS_DB_MAX_POOL', dataSource)]
491478
? parseInt(
492-
`${
493-
process.env[
494-
keyByDataSource('CUBEJS_DB_MAX_POOL', dataSource)
495-
]
479+
`${process.env[
480+
keyByDataSource('CUBEJS_DB_MAX_POOL', dataSource)
481+
]
496482
}`,
497483
10,
498484
)
@@ -684,8 +670,7 @@ const variables: Record<string, (...args: any) => any> = {
684670
supported.indexOf(<'s3' | 'gcp' | 'azure'>val) === -1
685671
) {
686672
throw new TypeError(
687-
`The ${
688-
keyByDataSource('CUBEJS_DB_EXPORT_BUCKET_TYPE', dataSource)
673+
`The ${keyByDataSource('CUBEJS_DB_EXPORT_BUCKET_TYPE', dataSource)
689674
} must be one of the [${supported.join(', ')}].`
690675
);
691676
}
@@ -878,8 +863,7 @@ const variables: Record<string, (...args: any) => any> = {
878863
];
879864
if (!val) {
880865
throw new Error(
881-
`The ${
882-
keyByDataSource('CUBEJS_DB_DATABRICKS_URL', dataSource)
866+
`The ${keyByDataSource('CUBEJS_DB_DATABRICKS_URL', dataSource)
883867
} is required and missing.`
884868
);
885869
}
@@ -1387,11 +1371,10 @@ const variables: Record<string, (...args: any) => any> = {
13871371
return false;
13881372
} else {
13891373
throw new TypeError(
1390-
`The ${
1391-
keyByDataSource(
1392-
'CUBEJS_DB_SNOWFLAKE_CLIENT_SESSION_KEEP_ALIVE',
1393-
dataSource,
1394-
)
1374+
`The ${keyByDataSource(
1375+
'CUBEJS_DB_SNOWFLAKE_CLIENT_SESSION_KEEP_ALIVE',
1376+
dataSource,
1377+
)
13951378
} must be either 'true' or 'false'.`
13961379
);
13971380
}
@@ -1626,6 +1609,17 @@ const variables: Record<string, (...args: any) => any> = {
16261609
]
16271610
),
16281611

1612+
/**
1613+
* Trino catalog.
1614+
*/
1615+
trinoCatalog: ({
1616+
dataSource,
1617+
}: { dataSource: string }) => (
1618+
process.env[
1619+
keyByDataSource('CUBEJS_DB_TRINO_CATALOG', dataSource)
1620+
]
1621+
),
1622+
16291623
/** ****************************************************************
16301624
* Cube Store Driver *
16311625
***************************************************************** */

packages/cubejs-backend-shared/test/db_env_multi.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2189,4 +2189,33 @@ describe('Multiple datasources', () => {
21892189
'The wrong data source is missing in the declared CUBEJS_DATASOURCES.'
21902190
);
21912191
});
2192+
2193+
test('getEnv("trinoCatalog")', () => {
2194+
process.env.CUBEJS_DB_TRINO_CATALOG = 'default1';
2195+
process.env.CUBEJS_DS_POSTGRES_DB_TRINO_CATALOG = 'postgres1';
2196+
process.env.CUBEJS_DS_WRONG_DB_TRINO_CATALOG = 'wrong1';
2197+
expect(getEnv('trinoCatalog', { dataSource: 'default' })).toEqual('default1');
2198+
expect(getEnv('trinoCatalog', { dataSource: 'postgres' })).toEqual('postgres1');
2199+
expect(() => getEnv('trinoCatalog', { dataSource: 'wrong' })).toThrow(
2200+
'The wrong data source is missing in the declared CUBEJS_DATASOURCES.'
2201+
);
2202+
2203+
process.env.CUBEJS_DB_TRINO_CATALOG = 'default2';
2204+
process.env.CUBEJS_DS_POSTGRES_DB_TRINO_CATALOG = 'postgres2';
2205+
process.env.CUBEJS_DS_WRONG_DB_TRINO_CATALOG = 'wrong2';
2206+
expect(getEnv('trinoCatalog', { dataSource: 'default' })).toEqual('default2');
2207+
expect(getEnv('trinoCatalog', { dataSource: 'postgres' })).toEqual('postgres2');
2208+
expect(() => getEnv('trinoCatalog', { dataSource: 'wrong' })).toThrow(
2209+
'The wrong data source is missing in the declared CUBEJS_DATASOURCES.'
2210+
);
2211+
2212+
delete process.env.CUBEJS_DB_TRINO_CATALOG;
2213+
delete process.env.CUBEJS_DS_POSTGRES_DB_TRINO_CATALOG;
2214+
delete process.env.CUBEJS_DS_WRONG_DB_TRINO_CATALOG;
2215+
expect(getEnv('trinoCatalog', { dataSource: 'default' })).toBeUndefined();
2216+
expect(getEnv('trinoCatalog', { dataSource: 'postgres' })).toBeUndefined();
2217+
expect(() => getEnv('trinoCatalog', { dataSource: 'wrong' })).toThrow(
2218+
'The wrong data source is missing in the declared CUBEJS_DATASOURCES.'
2219+
);
2220+
});
21922221
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('trino', () => {
2424

2525
CUBEJS_DB_HOST: db.getHost(),
2626
CUBEJS_DB_PORT: `${db.getMappedPort(8080)}`,
27-
CUBEJS_DB_PRESTO_CATALOG: 'memory',
27+
CUBEJS_DB_TRINO_CATALOG: 'memory',
2828
CUBEJS_DB_USER: 'test',
2929

3030
...DEFAULT_CONFIG,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
connector.name=postgresql
2+
connection-url=jdbc:postgresql://postgres:5432/trino
3+
connection-user=trino
4+
connection-password=9bee2c3975024292eff5829526722ac2
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: '2.2'
2+
3+
services:
4+
coordinator:
5+
image: trinodb/trino
6+
ports:
7+
- "8080:8080"
8+
container_name: "coordinator"
9+
healthcheck:
10+
test: "trino --execute 'SELECT 1' || exit 1"
11+
interval: 10s
12+
timeout: 5s
13+
retries: 5

packages/cubejs-trino-driver/package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"build": "rm -rf dist && npm run tsc",
2222
"tsc": "tsc",
2323
"watch": "tsc -w",
24+
"integration": "npm run integration:trino",
25+
"integration:trino": "jest --verbose --config=jest.config.js dist/test",
2426
"lint": "eslint src/* --ext .ts",
2527
"lint:fix": "eslint --fix src/* --ext .ts"
2628
},
@@ -29,15 +31,23 @@
2931
"@cubejs-backend/prestodb-driver": "1.1.4",
3032
"@cubejs-backend/schema-compiler": "1.1.4",
3133
"@cubejs-backend/shared": "1.1.4",
32-
"presto-client": "^0.12.2",
34+
"trino-client": "^0.2.3",
3335
"sqlstring": "^2.3.1"
3436
},
3537
"license": "Apache-2.0",
3638
"publishConfig": {
3739
"access": "public"
3840
},
3941
"devDependencies": {
40-
"@cubejs-backend/linter": "^1.0.0"
42+
"@cubejs-backend/linter": "^1.0.0",
43+
"@types/jest": "^27",
44+
"jest": "^27",
45+
"babel-jest": "^27",
46+
"testcontainers": "^10.10.4",
47+
"typescript": "~5.2.2"
48+
},
49+
"jest": {
50+
"testEnvironment": "node"
4151
},
4252
"eslintConfig": {
4353
"extends": "../cubejs-linter"

0 commit comments

Comments
 (0)