You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "sha174n (via GitHub)" <gi...@apache.org> on 2026/05/03 19:03:12 UTC
[PR] fix: escape SQL identifiers in db engine spec prequeries and metadata queries [superset]
sha174n opened a new pull request, #39840:
URL: https://github.com/apache/superset/pull/39840
### SUMMARY
Several `get_prequeries()` and metadata query methods in db engine specs constructed SQL strings by directly interpolating user-supplied schema names, catalog names, table names, and usernames without escaping the relevant delimiter characters. This PR adds the appropriate escaping for each dialect:
| Engine spec | Method(s) | Delimiter | Escaping |
|---|---|---|---|
| `postgres.py` | `get_prequeries` | `"` | double → `""` |
| `db2.py` | `get_prequeries` | `"` | double → `""` |
| `databricks.py` | `get_prequeries` | `` ` `` | backtick → ` `` ` |
| `starrocks.py` | `get_prequeries` | `"` | double → `""` |
| `hive.py` | `get_view_names`, `df_to_sql`, `_partition_query` | `` ` `` / `'` | backtick doubling; backslash for LIKE literals |
| `bigquery.py` | `get_materialized_view_names`, `get_view_names` | `` ` `` | backslash-escape (`\`` `, `\\`) |
| `gsheets.py` | `get_extra_table_metadata` | `"` | double → `""` |
Also extracts a `_information_schema_ref` helper in `bigquery.py` to consolidate the duplicated 7-line escape block that previously appeared in both `get_materialized_view_names` and `get_view_names`.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — backend-only change.
### TESTING INSTRUCTIONS
Unit tests added for each changed spec:
```bash
pytest tests/unit_tests/db_engine_specs/test_postgres.py \
tests/unit_tests/db_engine_specs/test_db2.py \
tests/unit_tests/db_engine_specs/test_databricks.py \
tests/unit_tests/db_engine_specs/test_starrocks.py \
tests/unit_tests/db_engine_specs/test_hive.py \
tests/unit_tests/db_engine_specs/test_bigquery.py
```
Manual live test (PostgreSQL):
1. Create a schema whose name contains a double-quote: `CREATE SCHEMA "test""quoted"`
2. Configure a Superset PostgreSQL database connection and set the default schema to `test"quoted`
3. Run any query — the `SET search_path` prequery must execute without error and the schema must resolve correctly.
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix: escape SQL identifiers in db engine spec prequeries and metadata queries [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #39840:
URL: https://github.com/apache/superset/pull/39840#issuecomment-4370182139
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers a full AI review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix: escape SQL identifiers in db engine spec prequeries and metadata queries [superset]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #39840:
URL: https://github.com/apache/superset/pull/39840#issuecomment-4366935457
## [Codecov](https://app.codecov.io/gh/apache/superset/pull/39840?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `5.71429%` with `33 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 55.39%. Comparing base ([`dc1c0f6`](https://app.codecov.io/gh/apache/superset/commit/dc1c0f6ba190371b7a1349f5815c2461df2743c9?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`9750b6d`](https://app.codecov.io/gh/apache/superset/commit/9750b6d7ee4cce35be25f8a45b2913b88c315469?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
| [Files with missing lines](https://app.codecov.io/gh/apache/superset/pull/39840?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [superset/db\_engine\_specs/hive.py](https://app.codecov.io/gh/apache/superset/pull/39840?src=pr&el=tree&filepath=superset%2Fdb_engine_specs%2Fhive.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvZGJfZW5naW5lX3NwZWNzL2hpdmUucHk=) | 0.00% | [9 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/39840?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [superset/db\_engine\_specs/bigquery.py](https://app.codecov.io/gh/apache/superset/pull/39840?src=pr&el=tree&filepath=superset%2Fdb_engine_specs%2Fbigquery.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvZGJfZW5naW5lX3NwZWNzL2JpZ3F1ZXJ5LnB5) | 20.00% | [8 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/39840?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [superset/db\_engine\_specs/databricks.py](https://app.codecov.io/gh/apache/superset/pull/39840?src=pr&el=tree&filepath=superset%2Fdb_engine_specs%2Fdatabricks.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvZGJfZW5naW5lX3NwZWNzL2RhdGFicmlja3MucHk=) | 0.00% | [4 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/39840?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [superset/db\_engine\_specs/db2.py](https://app.codecov.io/gh/apache/superset/pull/39840?src=pr&el=tree&filepath=superset%2Fdb_engine_specs%2Fdb2.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvZGJfZW5naW5lX3NwZWNzL2RiMi5weQ==) | 0.00% | [4 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/39840?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [superset/db\_engine\_specs/postgres.py](https://app.codecov.io/gh/apache/superset/pull/39840?src=pr&el=tree&filepath=superset%2Fdb_engine_specs%2Fpostgres.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvZGJfZW5naW5lX3NwZWNzL3Bvc3RncmVzLnB5) | 0.00% | [4 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/39840?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [superset/db\_engine\_specs/gsheets.py](https://app.codecov.io/gh/apache/superset/pull/39840?src=pr&el=tree&filepath=superset%2Fdb_engine_specs%2Fgsheets.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvZGJfZW5naW5lX3NwZWNzL2dzaGVldHMucHk=) | 0.00% | [2 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/39840?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [superset/db\_engine\_specs/starrocks.py](https://app.codecov.io/gh/apache/superset/pull/39840?src=pr&el=tree&filepath=superset%2Fdb_engine_specs%2Fstarrocks.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvZGJfZW5naW5lX3NwZWNzL3N0YXJyb2Nrcy5weQ==) | 0.00% | [2 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/39840?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #39840 +/- ##
==========================================
- Coverage 64.35% 55.39% -8.97%
==========================================
Files 2569 2569
Lines 134680 134699 +19
Branches 31254 31256 +2
==========================================
- Hits 86679 74612 -12067
- Misses 46505 59429 +12924
+ Partials 1496 658 -838
```
| [Flag](https://app.codecov.io/gh/apache/superset/pull/39840/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [hive](https://app.codecov.io/gh/apache/superset/pull/39840/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `39.66% <5.71%> (?)` | |
| [mysql](https://app.codecov.io/gh/apache/superset/pull/39840/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [postgres](https://app.codecov.io/gh/apache/superset/pull/39840/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [presto](https://app.codecov.io/gh/apache/superset/pull/39840/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `41.41% <5.71%> (-0.01%)` | :arrow_down: |
| [python](https://app.codecov.io/gh/apache/superset/pull/39840/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `41.49% <5.71%> (-20.03%)` | :arrow_down: |
| [sqlite](https://app.codecov.io/gh/apache/superset/pull/39840/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [unit](https://app.codecov.io/gh/apache/superset/pull/39840/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/superset/pull/39840?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix: escape SQL identifiers in db engine spec prequeries and metadata queries [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #39840:
URL: https://github.com/apache/superset/pull/39840#issuecomment-4366945287
<!-- Bito Reply -->
The flagged issue is correct: table names with % or _ aren't escaped for LIKE wildcards, causing false 'table exists' detections. To resolve, escape % and _ in escaped_table and add an ESCAPE clause. No other comments in the PR.
**superset/db_engine_specs/hive.py**
```
escaped_table = table.table.replace("\\", "\\\\").replace("'", "\\'").replace("%", "\\%").replace("_", "\\_")
if table.schema:
escaped_schema = table.schema.replace("`", "``")
table_exists = not database.get_df(
f"SHOW TABLES IN `{escaped_schema}` LIKE '{escaped_table}' ESCAPE '\\'"
).empty
else:
table_exists = not database.get_df(
f"SHOW TABLES LIKE '{escaped_table}' ESCAPE '\\'"
).empty
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix: escape SQL identifiers in db engine spec prequeries and metadata queries [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #39840:
URL: https://github.com/apache/superset/pull/39840#issuecomment-4367162452
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers a full AI review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix: escape SQL identifiers in db engine spec prequeries and metadata queries [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on code in PR #39840:
URL: https://github.com/apache/superset/pull/39840#discussion_r3178635597
##########
superset/db_engine_specs/bigquery.py:
##########
@@ -883,6 +883,14 @@ def parse_error_exception(cls, exception: Exception) -> Exception:
# We will return the original exception
return exception
+ @staticmethod
+ def _information_schema_ref(schema: str, catalog: str | None) -> str:
+ escaped_schema = schema.replace("\\", "\\\\").replace("`", "\\`")
+ if catalog:
+ escaped_catalog = catalog.replace("\\", "\\\\").replace("`", "\\`")
+ return f"`{escaped_catalog}.{escaped_schema}.INFORMATION_SCHEMA.TABLES`"
+ return f"`{escaped_schema}.INFORMATION_SCHEMA.TABLES`"
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Incorrect SQL identifier escaping</b></div>
<div id="fix">
BigQuery identifiers require backticks to be escaped by doubling them, not with backslash. The current escaping will cause SQL syntax errors if schema or catalog names contain backticks. Also, backslashes do not need escaping in BigQuery identifiers.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
def _information_schema_ref(schema: str, catalog: str | None) -> str:
escaped_schema = schema.replace("`", "``")
if catalog:
escaped_catalog = catalog.replace("`", "``")
return f"`{escaped_catalog}.{escaped_schema}.INFORMATION_SCHEMA.TABLES`"
return f"`{escaped_schema}.INFORMATION_SCHEMA.TABLES`"
````
</div>
</details>
</div>
<small><i>Code Review Run #76834b</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix: escape SQL identifiers in db engine spec prequeries and metadata queries [superset]
Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #39840:
URL: https://github.com/apache/superset/pull/39840#discussion_r3178619107
##########
superset/db_engine_specs/hive.py:
##########
@@ -206,13 +206,15 @@ def df_to_sql(
if to_sql_kwargs["if_exists"] == "fail":
# Ensure table doesn't already exist.
+ escaped_table = table.table.replace("\\", "\\\\").replace("'", "\\'")
if table.schema:
+ escaped_schema = table.schema.replace("`", "``")
table_exists = not database.get_df(
- f"SHOW TABLES IN {table.schema} LIKE '{table.table}'"
+ f"SHOW TABLES IN `{escaped_schema}` LIKE '{escaped_table}'"
).empty
else:
table_exists = not database.get_df(
- f"SHOW TABLES LIKE '{table.table}'"
+ f"SHOW TABLES LIKE '{escaped_table}'"
).empty
Review Comment:
**Suggestion:** The table name is used inside a `LIKE` pattern but only quotes/backslashes are escaped; wildcard characters (`%` and `_`) are not. A table name containing these characters can match unrelated tables, causing incorrect `table_exists` detection and raising "Table already exists" for a non-existent table. Escape `LIKE` wildcards (and use an explicit `ESCAPE` clause) before building the query. [logic error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Hive file uploads fail for wildcard table names.
- ⚠️ False "Table already exists" errors confuse end users.
- ⚠️ Prevents creating new tables with `%` or `_` names.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Configure a Hive database in Superset so that `database.db_engine_spec` is
`HiveEngineSpec` (implementation at `superset/db_engine_specs/hive.py`, `df_to_sql` method
around lines 2–39 of the shown hunk).
2. Upload a file via the CSV/Excel upload flow, providing a `table_name` that contains a
`%` or `_` character (for example `sales_%_2024`), so that `_dataframe_to_database` in
`superset/commands/database/uploaders/base.py:18-37` constructs `data_table =
Table(table=table_name, schema=schema_name)` and `to_sql_kwargs = {"if_exists":
self._options.get("already_exists", "fail"), ...}`.
3. Observe that `_dataframe_to_database` calls
`database.db_engine_spec.df_to_sql(database, data_table, df, to_sql_kwargs)` at
`superset/commands/database/uploaders/base.py:31-37`, which dispatches to
`HiveEngineSpec.df_to_sql` in `superset/db_engine_specs/hive.py:2-39` because the engine
spec is Hive.
4. In `HiveEngineSpec.df_to_sql`, when `to_sql_kwargs["if_exists"] == "fail"`, the code at
`superset/db_engine_specs/hive.py:25-39` builds `escaped_table = table.table.replace("\\",
"\\\\").replace("'", "\\'")` but does not escape `%` or `_`, then executes
`database.get_df(f"SHOW TABLES IN `{escaped_schema}` LIKE '{escaped_table}'")`; Hive
interprets `%` and `_` as wildcards, so if any existing table name matches the pattern
(e.g., `sales_X_2024`), `get_df(...)` returns non-empty, `table_exists` becomes `True`,
and `SupersetException("Table already exists")` is raised even though the literal table
name `sales_%_2024` does not exist. This incorrectly blocks the upload.
```
</details>
[Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20superset%2Fdb_engine_specs%2Fhive.py%0A%2A%2ALine%3A%2A%2A%20209%3A218%0A%2A%2AComment%3A%2A%2A%0A%09%2ALogic%20Error%3A%20The%20table%20name%20is%20used%20inside%20a%20%60LIKE%60%20pattern%20but%20only%20quotes%2Fbackslashes%20are%20escaped%3B%20wildcard%20characters%20%28%60%25%60%20and%20%60_%60%29%20are%20not.%20A%20table%20name%20containing%20these%20characters%20can%20match%20unrelated%20tables%2C%20causing%20incorrect%20%60table_exists%60%20detection%20and%20raising%20%22Table%20already%20exists%22%20for%20a%20non-existent%20table.%20Escape%20%60LIKE%60%20wildcards%20%28and%20use%20an%20explicit%20%60ESCAPE%60%20clause%29%20before%20building%20the%20query.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20
it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A) | [Fix in VSCode Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20superset%2Fdb_engine_specs%2Fhive.py%0A%2A%2ALine%3A%2A%2A%20209%3A218%0A%2A%2AComment%3A%2A%2A%0A%09%2ALogic%20Error%3A%20The%20table%20name%20is%20used%20inside%20a%20%60LIKE%60%20pattern%20but%20only%20quotes%2Fbackslashes%20are%20escaped%3B%20wildcard%20characters%20%28%60%25%60%20and%20%60_%60%29%20are%20not.%20A%20table%20name%20containing%20these%20characters%20can%20match%20unrelated%20tables%2C%20causing%20incorrect%20%60table_exists%60%20
detection%20and%20raising%20%22Table%20already%20exists%22%20for%20a%20non-existent%20table.%20Escape%20%60LIKE%60%20wildcards%20%28and%20use%20an%20explicit%20%60ESCAPE%60%20clause%29%20before%20building%20the%20query.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/db_engine_specs/hive.py
**Line:** 209:218
**Comment:**
*Logic Error: The table name is used inside a `LIKE` pattern but only quotes/backslashes are escaped; wildcard characters (`%` and `_`) are not. A table name containing these characters can match unrelated tables, causing incorrect `table_exists` detection and raising "Table already exists" for a non-existent table. Escape `LIKE` wildcards (and use an explicit `ESCAPE` clause) before building the query.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39840&comment_hash=c82b14fe5f0e164cbc6c020eb4745d8a36b019a488c56cb52ee2d1012da8b33e&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39840&comment_hash=c82b14fe5f0e164cbc6c020eb4745d8a36b019a488c56cb52ee2d1012da8b33e&reaction=dislike'>👎</a>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix: escape SQL identifiers in db engine spec prequeries and metadata queries [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #39840:
URL: https://github.com/apache/superset/pull/39840#issuecomment-4366928201
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix: escape SQL identifiers in db engine spec prequeries and metadata queries [superset]
Posted by "betodealmeida (via GitHub)" <gi...@apache.org>.
betodealmeida merged PR #39840:
URL: https://github.com/apache/superset/pull/39840
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org