Skip to content

Commit

Permalink
Use the Trino client instead of inheriting from Presto
Browse files Browse the repository at this point in the history
  • Loading branch information
ndrluis committed Nov 12, 2024
1 parent 5593a2a commit a12044a
Show file tree
Hide file tree
Showing 11 changed files with 345 additions and 56 deletions.
8 changes: 4 additions & 4 deletions .github/actions/smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ echo "::endgroup::"
#yarn lerna run --concurrency 1 --stream --no-prefix smoke:prestodb
#echo "::endgroup::"

echo "::group::Trino"
yarn lerna run --concurrency 1 --stream --no-prefix smoke:trino
echo "::endgroup::"
#echo "::group::Trino"
#yarn lerna run --concurrency 1 --stream --no-prefix smoke:trino
#echo "::endgroup::"

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

echo "::group::MongoBI"
yarn lerna run --concurrency 1 --stream --no-prefix smoke:mongobi
echo "::endgroup::"
echo "::endgroup::"
5 changes: 2 additions & 3 deletions docs/pages/product/configuration/data-sources/trino.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CUBEJS_DB_TYPE=trino
CUBEJS_DB_HOST=my.trino.host
CUBEJS_DB_USER=trino_user
CUBEJS_DB_PASS=**********
CUBEJS_DB_PRESTO_CATALOG=my_trino_catalog
CUBEJS_DB_TRINO_CATALOG=my_trino_catalog
CUBEJS_DB_SCHEMA=my_trino_schema
```

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

Expand Down
72 changes: 33 additions & 39 deletions packages/cubejs-backend-shared/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ export function assertDataSource(dataSource = 'default'): string {
return dataSource;
} else {
throw new Error(
`The ${
dataSource
`The ${dataSource
} data source is missing in the declared CUBEJS_DATASOURCES.`
);
}
Expand All @@ -90,10 +89,8 @@ export function keyByDataSource(origin: string, dataSource?: string): string {
return `CUBEJS_DS_${dataSource.toUpperCase()}_${s[1]}`;
} else {
throw new Error(
`The ${
origin
} environment variable can not be converted for the ${
dataSource
`The ${origin
} environment variable can not be converted for the ${dataSource
} data source.`
);
}
Expand Down Expand Up @@ -237,8 +234,7 @@ const variables: Record<string, (...args: any) => any> = {
return false;
} else {
throw new TypeError(
`The ${
keyByDataSource('CUBEJS_DB_SSL', dataSource)
`The ${keyByDataSource('CUBEJS_DB_SSL', dataSource)
} must be either 'true' or 'false'.`
);
}
Expand All @@ -261,8 +257,7 @@ const variables: Record<string, (...args: any) => any> = {
return false;
} else {
throw new TypeError(
`The ${
keyByDataSource('CUBEJS_DB_SSL_REJECT_UNAUTHORIZED', dataSource)
`The ${keyByDataSource('CUBEJS_DB_SSL_REJECT_UNAUTHORIZED', dataSource)
} must be either 'true' or 'false'.`
);
}
Expand Down Expand Up @@ -353,8 +348,7 @@ const variables: Record<string, (...args: any) => any> = {
}) => (
process.env[keyByDataSource('CUBEJS_DB_PORT', dataSource)]
? parseInt(
`${
process.env[keyByDataSource('CUBEJS_DB_PORT', dataSource)]
`${process.env[keyByDataSource('CUBEJS_DB_PORT', dataSource)]
}`,
10,
)
Expand Down Expand Up @@ -409,8 +403,7 @@ const variables: Record<string, (...args: any) => any> = {
];
if (required && !val) {
throw new Error(
`The ${
keyByDataSource('CUBEJS_DB_NAME', dataSource)
`The ${keyByDataSource('CUBEJS_DB_NAME', dataSource)
} is required and missing.`
);
}
Expand All @@ -429,19 +422,16 @@ const variables: Record<string, (...args: any) => any> = {
required?: boolean,
}) => {
console.warn(
`The ${
keyByDataSource('CUBEJS_DB_SCHEMA', dataSource)
} is deprecated. Please, use the ${
keyByDataSource('CUBEJS_DB_NAME', dataSource)
`The ${keyByDataSource('CUBEJS_DB_SCHEMA', dataSource)
} is deprecated. Please, use the ${keyByDataSource('CUBEJS_DB_NAME', dataSource)
} instead.`
);
const val = process.env[
keyByDataSource('CUBEJS_DB_SCHEMA', dataSource)
];
if (required && !val) {
throw new Error(
`The ${
keyByDataSource('CUBEJS_DB_SCHEMA', dataSource)
`The ${keyByDataSource('CUBEJS_DB_SCHEMA', dataSource)
} is required and missing.`
);
}
Expand All @@ -460,19 +450,16 @@ const variables: Record<string, (...args: any) => any> = {
required?: boolean,
}) => {
console.warn(
`The ${
keyByDataSource('CUBEJS_DATABASE', dataSource)
} is deprecated. Please, use the ${
keyByDataSource('CUBEJS_DB_NAME', dataSource)
`The ${keyByDataSource('CUBEJS_DATABASE', dataSource)
} is deprecated. Please, use the ${keyByDataSource('CUBEJS_DB_NAME', dataSource)
} instead.`
);
const val = process.env[
keyByDataSource('CUBEJS_DATABASE', dataSource)
];
if (required && !val) {
throw new Error(
`The ${
keyByDataSource('CUBEJS_DATABASE', dataSource)
`The ${keyByDataSource('CUBEJS_DATABASE', dataSource)
} is required and missing.`
);
}
Expand All @@ -489,10 +476,9 @@ const variables: Record<string, (...args: any) => any> = {
}) => (
process.env[keyByDataSource('CUBEJS_DB_MAX_POOL', dataSource)]
? parseInt(
`${
process.env[
keyByDataSource('CUBEJS_DB_MAX_POOL', dataSource)
]
`${process.env[
keyByDataSource('CUBEJS_DB_MAX_POOL', dataSource)
]
}`,
10,
)
Expand Down Expand Up @@ -684,8 +670,7 @@ const variables: Record<string, (...args: any) => any> = {
supported.indexOf(<'s3' | 'gcp' | 'azure'>val) === -1
) {
throw new TypeError(
`The ${
keyByDataSource('CUBEJS_DB_EXPORT_BUCKET_TYPE', dataSource)
`The ${keyByDataSource('CUBEJS_DB_EXPORT_BUCKET_TYPE', dataSource)
} must be one of the [${supported.join(', ')}].`
);
}
Expand Down Expand Up @@ -878,8 +863,7 @@ const variables: Record<string, (...args: any) => any> = {
];
if (!val) {
throw new Error(
`The ${
keyByDataSource('CUBEJS_DB_DATABRICKS_URL', dataSource)
`The ${keyByDataSource('CUBEJS_DB_DATABRICKS_URL', dataSource)
} is required and missing.`
);
}
Expand Down Expand Up @@ -1387,11 +1371,10 @@ const variables: Record<string, (...args: any) => any> = {
return false;
} else {
throw new TypeError(
`The ${
keyByDataSource(
'CUBEJS_DB_SNOWFLAKE_CLIENT_SESSION_KEEP_ALIVE',
dataSource,
)
`The ${keyByDataSource(
'CUBEJS_DB_SNOWFLAKE_CLIENT_SESSION_KEEP_ALIVE',
dataSource,
)
} must be either 'true' or 'false'.`
);
}
Expand Down Expand Up @@ -1626,6 +1609,17 @@ const variables: Record<string, (...args: any) => any> = {
]
),

/**
* Trino catalog.
*/
trinoCatalog: ({
dataSource,
}: { dataSource: string }) => (
process.env[
keyByDataSource('CUBEJS_DB_TRINO_CATALOG', dataSource)
]
),

/** ****************************************************************
* Cube Store Driver *
***************************************************************** */
Expand Down
29 changes: 29 additions & 0 deletions packages/cubejs-backend-shared/test/db_env_multi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2189,4 +2189,33 @@ describe('Multiple datasources', () => {
'The wrong data source is missing in the declared CUBEJS_DATASOURCES.'
);
});

test('getEnv("trinoCatalog")', () => {
process.env.CUBEJS_DB_TRINO_CATALOG = 'default1';
process.env.CUBEJS_DS_POSTGRES_DB_TRINO_CATALOG = 'postgres1';
process.env.CUBEJS_DS_WRONG_DB_TRINO_CATALOG = 'wrong1';
expect(getEnv('trinoCatalog', { dataSource: 'default' })).toEqual('default1');
expect(getEnv('trinoCatalog', { dataSource: 'postgres' })).toEqual('postgres1');
expect(() => getEnv('trinoCatalog', { dataSource: 'wrong' })).toThrow(
'The wrong data source is missing in the declared CUBEJS_DATASOURCES.'
);

process.env.CUBEJS_DB_TRINO_CATALOG = 'default2';
process.env.CUBEJS_DS_POSTGRES_DB_TRINO_CATALOG = 'postgres2';
process.env.CUBEJS_DS_WRONG_DB_TRINO_CATALOG = 'wrong2';
expect(getEnv('trinoCatalog', { dataSource: 'default' })).toEqual('default2');
expect(getEnv('trinoCatalog', { dataSource: 'postgres' })).toEqual('postgres2');
expect(() => getEnv('trinoCatalog', { dataSource: 'wrong' })).toThrow(
'The wrong data source is missing in the declared CUBEJS_DATASOURCES.'
);

delete process.env.CUBEJS_DB_TRINO_CATALOG;
delete process.env.CUBEJS_DS_POSTGRES_DB_TRINO_CATALOG;
delete process.env.CUBEJS_DS_WRONG_DB_TRINO_CATALOG;
expect(getEnv('trinoCatalog', { dataSource: 'default' })).toBeUndefined();
expect(getEnv('trinoCatalog', { dataSource: 'postgres' })).toBeUndefined();
expect(() => getEnv('trinoCatalog', { dataSource: 'wrong' })).toThrow(
'The wrong data source is missing in the declared CUBEJS_DATASOURCES.'
);
});
});
2 changes: 1 addition & 1 deletion packages/cubejs-testing/test/smoke-trino.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('trino', () => {

CUBEJS_DB_HOST: db.getHost(),
CUBEJS_DB_PORT: `${db.getMappedPort(8080)}`,
CUBEJS_DB_PRESTO_CATALOG: 'memory',
CUBEJS_DB_TRINO_CATALOG: 'memory',
CUBEJS_DB_USER: 'test',

...DEFAULT_CONFIG,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
connector.name=postgresql
connection-url=jdbc:postgresql://postgres:5432/trino
connection-user=trino
connection-password=9bee2c3975024292eff5829526722ac2
13 changes: 13 additions & 0 deletions packages/cubejs-trino-driver/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '2.2'

services:
coordinator:
image: trinodb/trino
ports:
- "8080:8080"
container_name: "coordinator"
healthcheck:
test: "trino --execute 'SELECT 1' || exit 1"
interval: 10s
timeout: 5s
retries: 5
14 changes: 12 additions & 2 deletions packages/cubejs-trino-driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"build": "rm -rf dist && npm run tsc",
"tsc": "tsc",
"watch": "tsc -w",
"integration": "npm run integration:trino",
"integration:trino": "jest --verbose --config=jest.config.js dist/test",
"lint": "eslint src/* --ext .ts",
"lint:fix": "eslint --fix src/* --ext .ts"
},
Expand All @@ -29,15 +31,23 @@
"@cubejs-backend/prestodb-driver": "1.1.4",
"@cubejs-backend/schema-compiler": "1.1.4",
"@cubejs-backend/shared": "1.1.4",
"presto-client": "^0.12.2",
"trino-client": "^0.2.3",
"sqlstring": "^2.3.1"
},
"license": "Apache-2.0",
"publishConfig": {
"access": "public"
},
"devDependencies": {
"@cubejs-backend/linter": "^1.0.0"
"@cubejs-backend/linter": "^1.0.0",
"@types/jest": "^27",
"jest": "^27",
"babel-jest": "^27",
"testcontainers": "^10.10.4",
"typescript": "~5.2.2"
},
"jest": {
"testEnvironment": "node"
},
"eslintConfig": {
"extends": "../cubejs-linter"
Expand Down
Loading

0 comments on commit a12044a

Please sign in to comment.