uranusjr commented on a change in pull request #17974:
URL: https://github.com/apache/airflow/pull/17974#discussion_r702393699
##########
File path: airflow/hooks/dbapi.py
##########
@@ -286,11 +290,20 @@ def _generate_insert_sql(table, values, target_fields,
replace, **kwargs):
else:
target_fields = ''
- if not replace:
- sql = "INSERT INTO "
+ if not kwargs.get("before_statement"):
+ if not replace:
+ sql = "INSERT INTO "
+ else:
+ sql = "REPLACE INTO "
else:
- sql = "REPLACE INTO "
+ sql = (
+ kwargs.get("before_statement") + " "
+ ) # ensure that there is at least a white space after that
+
sql += f"{table} {target_fields} VALUES ({','.join(placeholders)})"
+ if kwargs.get("after_statement"):
+ sql += " " + kwargs.get("after_statement")
Review comment:
This repeated `dict.get(key)` is needless. It’s better to make
`before_statement` and `after_statement` [keyword-only
arguments](https://www.python.org/dev/peps/pep-3102/#specification) instead.
The `" " + kwargs.get("after_statement")` idiom is also fragile since both
`before_statement` and `after_statement` can be arbitrary values at run-time.
You need to first check they are valid strings (and raise `TypeError` if they
are not), or use f-string to join them instead.
--
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]