codeant-ai-for-open-source[bot] commented on code in PR #41917:
URL: https://github.com/apache/superset/pull/41917#discussion_r3555895016


##########
superset/db_engine_specs/hive.py:
##########
@@ -260,22 +261,23 @@ def _get_hive_type(dtype: np.dtype[Any]) -> str:
                 catalog=table.catalog,
                 schema=table.schema,
             ) as engine:
-                engine.execute(
-                    text(
-                        f"""
-                        CREATE TABLE {str(table)} ({schema_definition})
-                        STORED AS PARQUET
-                        LOCATION :location
-                        """
-                    ),
-                    location=upload_to_s3(
-                        filename=file.name,
-                        
upload_prefix=app.config["CSV_TO_HIVE_UPLOAD_DIRECTORY_FUNC"](
-                            database, g.user, table.schema
+                with engine.begin() as conn:
+                    conn.execute(
+                        text(
+                            f"""
+                            CREATE TABLE {str(table)} ({schema_definition})
+                            STORED AS PARQUET
+                            LOCATION :location
+                            """
                         ),
-                        table=table,
-                    ),
-                )
+                        location=upload_to_s3(
+                            filename=file.name,
+                            upload_prefix=app.config[
+                                "CSV_TO_HIVE_UPLOAD_DIRECTORY_FUNC"
+                            ](database, g.user, table.schema),
+                            table=table,
+                        ),
+                    )

Review Comment:
   **Suggestion:** The parameter binding call uses a keyword argument in 
`Connection.execute`, which is not supported by SQLAlchemy 2-style execution 
and will raise a runtime argument error when this code runs on 2.x-compatible 
connections. Pass bind values as a single mapping/dict argument instead of 
`location=`. [api mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Hive DataFrame uploads fail when replacing existing tables.
   - ⚠️ CSV upload UI errors on Hive replace strategy.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Trigger a DataFrame upload to a Hive database via the upload command in
   `superset/commands/database/uploaders/base.py:110-21`, choosing the “if 
table already
   exists” option as `"replace"` so `to_sql_kwargs["if_exists"]` becomes 
`"replace"` (line
   8).
   
   2. The upload command calls `database.db_engine_spec.df_to_sql(database, 
data_table, df,
   to_sql_kwargs=...)` at `superset/commands/database/uploaders/base.py:15-20`, 
and for a
   Hive backend `database.db_engine_spec` resolves to `HiveEngineSpec` (see
   `superset/models/core.py:20-22` for engine spec resolution).
   
   3. Inside `HiveEngineSpec.df_to_sql` in 
`superset/db_engine_specs/hive.py:181-81`, when
   `to_sql_kwargs["if_exists"] == "replace"` (line 32) the code opens an engine 
and
   transaction, then executes the CREATE TABLE statement with 
`conn.execute(text(...),
   location=upload_to_s3(...))` at lines 65-81 (corresponding to diff lines 
264-280).
   
   4. On SQLAlchemy 2.x-style connections, calling `Connection.execute(...)` 
with keyword
   bind parameters instead of a mapping can result in an argument error (e.g., 
unexpected
   keyword `'location'`), causing the Hive table creation to fail and surfacing 
as a
   `DatabaseUploadFailed` from the upload command’s exception handling at
   `superset/commands/database/uploaders/base.py:21-31`.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=a8ff2af704a947ea8e5dce08fcaa3bab&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=a8ff2af704a947ea8e5dce08fcaa3bab&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(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:** 264:280
   **Comment:**
        *Api Mismatch: The parameter binding call uses a keyword argument in 
`Connection.execute`, which is not supported by SQLAlchemy 2-style execution 
and will raise a runtime argument error when this code runs on 2.x-compatible 
connections. Pass bind values as a single mapping/dict argument instead of 
`location=`.
   
   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%2F41917&comment_hash=228570e3e5a2afc34c2a1906e1286cffe33afaf13a5c6222d707ed862abd79a2&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41917&comment_hash=228570e3e5a2afc34c2a1906e1286cffe33afaf13a5c6222d707ed862abd79a2&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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to