ashb commented on code in PR #76828:
URL: https://github.com/apache/airflow/pull/76828#discussion_r4633668908


##########
providers/common/sql/src/airflow/providers/common/sql/operators/sql.py:
##########
@@ -503,6 +503,10 @@ class SQLExecuteQueryOperator(BaseSQLOperator):
     :param requires_result_fetch: (optional) if True, ensures that query 
results are fetched before
         completing execution. If `do_xcom_push` is True, results are fetched 
automatically,
         making this parameter redundant.  (default: False).
+    :param validate_sql: (optional) if True, validates SQL syntax locally 
before execution (default: False).
+    :param check_partition_filters: (optional) if True, checks for partition 
filters and unbounded queries (default: False).
+    :param partition_columns: (optional) column names or mapping of table to 
column names required in WHERE clauses.
+    :param dialect: (optional) SQL dialect name to use for validation. If 
None, detected from hook.

Review Comment:
   Why would you need to specify this. i.e. when isn't taking it from the hook 
the right anser?



##########
providers/common/sql/src/airflow/providers/common/sql/operators/sql.py:
##########
@@ -503,6 +503,10 @@ class SQLExecuteQueryOperator(BaseSQLOperator):
     :param requires_result_fetch: (optional) if True, ensures that query 
results are fetched before
         completing execution. If `do_xcom_push` is True, results are fetched 
automatically,
         making this parameter redundant.  (default: False).
+    :param validate_sql: (optional) if True, validates SQL syntax locally 
before execution (default: False).
+    :param check_partition_filters: (optional) if True, checks for partition 
filters and unbounded queries (default: False).
+    :param partition_columns: (optional) column names or mapping of table to 
column names required in WHERE clauses.

Review Comment:
   Why do we need to specify these? Shouldn't they be come form the query 
itself?



##########
providers/common/sql/src/airflow/providers/common/sql/utils/sql_validation.py:
##########
@@ -0,0 +1,588 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+import re
+from collections.abc import Mapping, Sequence
+from typing import Any
+
+from airflow.providers.common.compat.sdk import 
AirflowOptionalProviderFeatureException
+
+try:
+    import sqlglot
+    from sqlglot import exp
+    from sqlglot.dialects import Dialects
+    from sqlglot.errors import ErrorLevel, ParseError
+except ImportError:
+    sqlglot = None  # type: ignore[assignment]
+    exp = None  # type: ignore[assignment]
+    Dialects = None  # type: ignore[assignment]
+    ErrorLevel = None  # type: ignore[assignment,misc]
+    ParseError = None  # type: ignore[assignment,misc]
+
+_KNOWN_SQLGLOT_DIALECTS: frozenset[str] = (
+    frozenset(d.value for d in Dialects) if Dialects is not None else 
frozenset()

Review Comment:
   Looking more at it, so much of this file is dealing with sqlglot not being 
installed. Why don't we raise AirflowOptionalProviderFeatureException on L31 
instead of all of it, as this file is only imported when it's requested by a 
user.



##########
providers/common/sql/src/airflow/providers/common/sql/utils/sql_validation.py:
##########
@@ -0,0 +1,588 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+import re
+from collections.abc import Mapping, Sequence
+from typing import Any
+
+from airflow.providers.common.compat.sdk import 
AirflowOptionalProviderFeatureException
+
+try:
+    import sqlglot
+    from sqlglot import exp
+    from sqlglot.dialects import Dialects
+    from sqlglot.errors import ErrorLevel, ParseError
+except ImportError:
+    sqlglot = None  # type: ignore[assignment]
+    exp = None  # type: ignore[assignment]
+    Dialects = None  # type: ignore[assignment]
+    ErrorLevel = None  # type: ignore[assignment,misc]
+    ParseError = None  # type: ignore[assignment,misc]
+
+_KNOWN_SQLGLOT_DIALECTS: frozenset[str] = (
+    frozenset(d.value for d in Dialects) if Dialects is not None else 
frozenset()

Review Comment:
   Could be simplified by making L33 say `Dialects = []`



##########
providers/common/sql/src/airflow/providers/common/sql/utils/sql_validation.py:
##########


Review Comment:
   -1 to introducing a uitls/ package for this. Jyave have it `as 
.../common/sql/sql_validation.py`



-- 
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]

Reply via email to