From 86da34d6049d3d762be405e043d9bb119da06293 Mon Sep 17 00:00:00 2001 From: Tyagiquamar Date: Fri, 18 Sep 2026 12:10:04 +0530 Subject: [PATCH] fix(cli): backtick-quote BigQuery rows alias in list-tables query (#3331) --- cli/cli/connection/index.test.ts | 18 ++++++++++++++++++ cli/cli/connection/index.ts | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cli/cli/connection/index.test.ts b/cli/cli/connection/index.test.ts index 50303fd3fe..7a975222ea 100644 --- a/cli/cli/connection/index.test.ts +++ b/cli/cli/connection/index.test.ts @@ -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 => ({ + 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', @@ -37,6 +47,14 @@ const databricks = (extra: Partial = {}): 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([])); diff --git a/cli/cli/connection/index.ts b/cli/cli/connection/index.ts index 4b32cf9734..01503a3386 100644 --- a/cli/cli/connection/index.ts +++ b/cli/cli/connection/index.ts @@ -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