Skip to content
Open
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
18 changes: 18 additions & 0 deletions cli/cli/connection/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import { describe, it, expect } from 'vitest';
import { listTablesSql, qualifyTableName } from './index';
import type {
BigQueryConnectionConfig,
ClickHouseConnectionConfig,
FabricConnectionConfig,
DatabricksConnectionConfig
} from './types';

const bq = (extra: Partial<BigQueryConnectionConfig> = {}): BigQueryConnectionConfig => ({
type: 'bigquery',
authType: 'service_account_json',
projectId: 'my-proj',
serviceAccountJson: { client_email: 'a@b.c', private_key: 'k' },
defaultDataset: 'my_dataset',
...extra
});

const ch = (databases: string[]): ClickHouseConnectionConfig => ({
type: 'clickhouse',
url: 'https://h:8443',
Expand Down Expand Up @@ -37,6 +47,14 @@ const databricks = (extra: Partial<DatabricksConnectionConfig> = {}): Databricks
// The `...extra` spread widens the token/oauth discriminant; cast back.
}) as DatabricksConnectionConfig;

describe('listTablesSql (bigquery)', () => {
it('backtick-quotes the `rows` alias (`rows` is a reserved keyword)', () => {
const sql = listTablesSql(bq());
expect(sql).toContain('AS `rows`');
expect(sql).not.toMatch(/AS rows\b/);
});
});

describe('listTablesSql (clickhouse)', () => {
it('scopes to the current database when the allowlist is empty', () => {
const sql = listTablesSql(ch([]));
Expand Down
2 changes: 1 addition & 1 deletion cli/cli/connection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function listTablesSql(config: ConnectionConfig | null): string {
// Backtick-quote project and dataset to tolerate hyphens (project IDs
// commonly contain them) and reserved words.
// __TABLES__ (not INFORMATION_SCHEMA.TABLES) carries row_count.
return `SELECT table_id AS name, dataset_id AS schema_name, row_count AS rows FROM \`${config.projectId}\`.\`${config.defaultDataset}\`.__TABLES__ ORDER BY table_id`;
return `SELECT table_id AS name, dataset_id AS schema_name, row_count AS \`rows\` FROM \`${config.projectId}\`.\`${config.defaultDataset}\`.__TABLES__ ORDER BY table_id`;
}
case 'clickhouse': {
// Hide Evidence-internal dot-tables. An empty allowlist scopes to the
Expand Down