Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 134
fix: replace escapeSqlString with parameterized query binds in finops/schema#277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -37,19 +37,18 @@ export async function connect(config: ConnectionConfig): Promise<Connector> { | ||
| client = new BigQuery(options) | ||
| }, | ||
| async execute(sql: string, limit?: number): Promise<ConnectorResult> { | ||
| async execute(sql: string, limit?: number, binds?: any[]): Promise<ConnectorResult> { | ||
| const effectiveLimit = limit ?? 1000 | ||
| let query = sql | ||
| const query = sql.replace(/;\s*$/, "") | ||
| const isSelectLike = /^\s*(SELECT|WITH|VALUES)\b/i.test(sql) | ||
| if ( | ||
| isSelectLike && | ||
| effectiveLimit && | ||
| !/\bLIMIT\b/i.test(sql) | ||
| ) { | ||
| query = `${sql.replace(/;\s*$/, "")} LIMIT ${effectiveLimit + 1}` | ||
| } | ||
| // BigQuery does not allow appending LIMIT to parameterized queries. | ||
| // Use maxResults instead — it limits rows returned at the API level. | ||
| const options: Record<string, unknown> = { query } | ||
| if (isSelectLike && effectiveLimit && !/\bLIMIT\b/i.test(sql)) { | ||
| options.maxResults = effectiveLimit + 1 | ||
| } | ||
| if (binds?.length) options.params = binds | ||
| if (config.dataset) { | ||
Comment on lines
47
to
52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: BigQuery queries will fail because Suggested FixRemove the Prompt for AI Agent | ||
| options.defaultDataset = { | ||
| datasetId: config.dataset, | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -18,6 +18,10 @@ export async function connect(config: ConnectionConfig): Promise<Connector> { | ||
| let client: any | ||
| let session: any | ||
| function escapeIdentifier(value: string): string { | ||
| return value.replace(/`/g, "``") | ||
| } | ||
| return { | ||
| async connect() { | ||
| const DBSQLClient = databricksModule.DBSQLClient ?? databricksModule | ||
| @@ -40,7 +44,7 @@ export async function connect(config: ConnectionConfig): Promise<Connector> { | ||
| }) | ||
| }, | ||
| async execute(sql: string, limit?: number): Promise<ConnectorResult> { | ||
| async execute(sql: string, limit?: number, binds?: any[]): Promise<ConnectorResult> { | ||
| const effectiveLimit = limit ?? 1000 | ||
| let query = sql | ||
| const isSelectLike = /^\s*(SELECT|WITH|VALUES)\b/i.test(sql) | ||
| @@ -52,7 +56,11 @@ export async function connect(config: ConnectionConfig): Promise<Connector> { | ||
| query = `${sql.replace(/;\s*$/, "")} LIMIT ${effectiveLimit + 1}` | ||
| } | ||
| const operation = await session.executeStatement(query) | ||
| const stmtOptions: Record<string, any> = {} | ||
| if (binds?.length) { | ||
| stmtOptions.ordinalParameters = binds | ||
| } | ||
| const operation = await session.executeStatement(query, stmtOptions) | ||
Comment on lines
+59
to
+63
This comment was marked as outdated.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page. | ||
| const rows = await operation.fetchAll() | ||
| await operation.close() | ||
| @@ -84,7 +92,7 @@ export async function connect(config: ConnectionConfig): Promise<Connector> { | ||
| schema: string, | ||
| ): Promise<Array<{ name: string; type: string }>> { | ||
| const operation = await session.executeStatement( | ||
| `SHOW TABLES IN \`${schema}\``, | ||
| `SHOW TABLES IN \`${escapeIdentifier(schema)}\``, | ||
| ) | ||
| const rows = await operation.fetchAll() | ||
| await operation.close() | ||
| @@ -102,7 +110,7 @@ export async function connect(config: ConnectionConfig): Promise<Connector> { | ||
| table: string, | ||
| ): Promise<SchemaColumn[]> { | ||
| const operation = await session.executeStatement( | ||
| `DESCRIBE TABLE \`${schema}\`.\`${table}\``, | ||
| `DESCRIBE TABLE \`${escapeIdentifier(schema)}\`.\`${escapeIdentifier(table)}\``, | ||
| ) | ||
| const rows = await operation.fetchAll() | ||
| await operation.close() | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.