Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/cubejs-mysql-driver/src/MySqlDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
IndexesSQL,
DownloadTableMemoryData,
DriverCapabilities,
TableColumn,
} from '@cubejs-backend/base-driver';

const GenericTypeToMySql: Record<GenericDataBaseType, string> = {
Expand Down Expand Up @@ -180,7 +181,7 @@ export class MySqlDriver extends BaseDriver implements DriverInterface {

protected primaryKeysQuery(conditionString?: string): string | null {
return `SELECT
TABLE_SCHEMA as ${this.quoteIdentifier('table_schema')},
TABLE_SCHEMA as ${this.quoteIdentifier('table_schema')},
TABLE_NAME as ${this.quoteIdentifier('table_name')},
COLUMN_NAME as ${this.quoteIdentifier('column_name')}
FROM
Expand Down Expand Up @@ -262,6 +263,14 @@ export class MySqlDriver extends BaseDriver implements DriverInterface {
}
}

public async createTable(quotedTableName: string, columns: TableColumn[]): Promise<void> {
if (quotedTableName.length > 64) {
throw new Error('MySQL can not work with table names longer than 64 symbols. ' +
`Consider using the 'sqlAlias' attribute in your cube definition for ${quotedTableName}.`);
}
return super.createTable(quotedTableName, columns);
}

public async query(query: string, values: unknown[]) {
return this.withConnection(async (conn) => {
await this.setTimeZone(conn);
Expand Down
14 changes: 14 additions & 0 deletions packages/cubejs-mysql-driver/test/MySqlDriver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,18 @@ describe('MySqlDriver', () => {
await tableData.release();
}
});

test('table name check', async () => {
const tblName = 'really-really-really-looooooooooooooooooooooooooooooooooooooooooooooooooooong-table-name';
try {
await mySqlDriver.createTable(tblName, [{ name: 'id', type: 'bigint' }]);

throw new Error('createTable must throw an exception');
} catch (e: any) {
expect(e.message).toEqual(
'MySQL can not work with table names longer than 64 symbols. ' +
`Consider using the 'sqlAlias' attribute in your cube definition for ${tblName}.`
);
}
});
});
22 changes: 15 additions & 7 deletions packages/cubejs-oracle-driver/driver/OracleDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
getEnv,
assertDataSource,
} = require('@cubejs-backend/shared');
const { BaseDriver } = require('@cubejs-backend/base-driver');
const { BaseDriver, TableColumn } = require('@cubejs-backend/base-driver');
const oracledb = require('oracledb');
const { reduce } = require('ramda');

Expand Down Expand Up @@ -95,13 +95,13 @@ class OracleDriver extends BaseDriver {
, tc.data_type "data_type"
, c.constraint_type "key_type"
from all_tab_columns tc
left join all_cons_columns cc
on (tc.owner, tc.table_name, tc.column_name)
left join all_cons_columns cc
on (tc.owner, tc.table_name, tc.column_name)
in ((cc.owner, cc.table_name, cc.column_name))
left join all_constraints c
on (tc.owner, tc.table_name, cc.constraint_name)
in ((c.owner, c.table_name, c.constraint_name))
and c.constraint_type
left join all_constraints c
on (tc.owner, tc.table_name, cc.constraint_name)
in ((c.owner, c.table_name, c.constraint_name))
and c.constraint_type
in ('P','U')
where tc.owner = user
`);
Expand All @@ -121,6 +121,14 @@ class OracleDriver extends BaseDriver {
await this.query('SELECT 1 FROM DUAL', {});
}

async createTable(quotedTableName, columns) {
if (quotedTableName.length > 128) {
throw new Error('Oracle can not work with table names longer than 128 symbols. ' +
`Consider using the 'sqlAlias' attribute in your cube definition for ${quotedTableName}.`);
}
return super.createTable(quotedTableName, columns);
}

async query(query, values) {
const conn = await this.getConnectionFromPool();

Expand Down
16 changes: 12 additions & 4 deletions packages/cubejs-postgres-driver/src/PostgresDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
BaseDriver,
DownloadQueryResultsOptions, DownloadTableMemoryData, DriverInterface,
GenericDataBaseType, IndexesSQL, TableStructure, StreamOptions,
StreamTableDataWithTypes, QueryOptions, DownloadQueryResultsResult, DriverCapabilities,
StreamTableDataWithTypes, QueryOptions, DownloadQueryResultsResult, DriverCapabilities, TableColumn,
} from '@cubejs-backend/base-driver';
import { QueryStream } from './QueryStream';

Expand Down Expand Up @@ -118,7 +118,7 @@ export class PostgresDriver<Config extends PostgresDriverConfiguration = Postgre
const dataSource =
config.dataSource ||
assertDataSource('default');

this.pool = new Pool({
idleTimeoutMillis: 30000,
max:
Expand Down Expand Up @@ -146,9 +146,9 @@ export class PostgresDriver<Config extends PostgresDriverConfiguration = Postgre
}

protected primaryKeysQuery(conditionString?: string): string | null {
return `SELECT
return `SELECT
columns.table_schema as ${this.quoteIdentifier('table_schema')},
columns.table_name as ${this.quoteIdentifier('table_name')},
columns.table_name as ${this.quoteIdentifier('table_name')},
columns.column_name as ${this.quoteIdentifier('column_name')}
FROM information_schema.table_constraints tc
JOIN information_schema.constraint_column_usage AS ccu USING (constraint_schema, constraint_name)
Expand Down Expand Up @@ -360,6 +360,14 @@ export class PostgresDriver<Config extends PostgresDriverConfiguration = Postgre
}
}

public async createTable(quotedTableName: string, columns: TableColumn[]): Promise<void> {
if (quotedTableName.length > 63) {
throw new Error('PostgreSQL can not work with table names longer than 63 symbols. ' +
`Consider using the 'sqlAlias' attribute in your cube definition for ${quotedTableName}.`);
}
return super.createTable(quotedTableName, columns);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
public async query<R = unknown>(query: string, values: unknown[], options?: QueryOptions): Promise<R[]> {
const result = await this.queryResponse(query, values);
Expand Down
14 changes: 14 additions & 0 deletions packages/cubejs-postgres-driver/test/PostgresDriver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,20 @@ describe('PostgresDriver', () => {
}
});

test('table name check', async () => {
const tblName = 'really-really-really-looooooooooooooooooooooooooooooooooooooooooooooooooooong-table-name';
try {
await driver.createTable(tblName, [{ name: 'id', type: 'bigint' }]);

throw new Error('createTable must throw an exception');
} catch (e: any) {
expect(e.message).toEqual(
'PostgreSQL can not work with table names longer than 63 symbols. ' +
`Consider using the 'sqlAlias' attribute in your cube definition for ${tblName}.`
);
}
});

// Note: This test MUST be the last in the list.
test('release', async () => {
expect(async () => {
Expand Down
16 changes: 16 additions & 0 deletions packages/cubejs-redshift-driver/src/RedshiftDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
QueryTablesResult,
StreamOptions,
StreamTableDataWithTypes,
TableColumn,
UnloadOptions
} from '@cubejs-backend/base-driver';
import crypto from 'crypto';
Expand Down Expand Up @@ -240,6 +241,21 @@ export class RedshiftDriver extends PostgresDriver<RedshiftDriverConfiguration>
}
}

public override async createTable(quotedTableName: string, columns: TableColumn[]): Promise<void> {
if (quotedTableName.length > 127) {
throw new Error('Redshift can not work with table names longer than 127 symbols. ' +
`Consider using the 'sqlAlias' attribute in your cube definition for ${quotedTableName}.`);
}

// we can not call super.createTable(quotedTableName, columns)
// because Postgres has 63 length check. So pasting the code from the base driver
const createTableSql = this.createTableSql(quotedTableName, columns);
await this.query(createTableSql, []).catch(e => {
e.message = `Error during create table: ${createTableSql}: ${e.message}`;
throw e;
});
}

/**
* AWS Redshift doesn't have any special connection check.
* And querying even system tables is billed.
Expand Down
Loading