You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "BTeclaw (via GitHub)" <gi...@apache.org> on 2024/07/31 10:28:17 UTC

[PR] Fix: Pass hook parameters to SnowflakeSqlApiHook and prep them for AP… [airflow]

BTeclaw opened a new pull request, #41150:
URL: https://github.com/apache/airflow/pull/41150

   This PR is a resolution to the given issue #39622. The main bug here was that the hook parameters were not properly given to the SnowflakeSqlAPIHook and then they were not properly assigned. The query execution method of the hook statically assigned configuration from Airflow connection. In this PR it is changed so that:
   1. hook_params from SnowflakeSqlApiOperator object is passed into the hook object through unpacking the variable.
   2. In SnowflakeSqlApiHook, for each of the parameter (database, role, schema, warehouse) there is a check performed for whether they were provided in the parameters (in their parent class SnowflakeHook, they are initialized to None, hence the if self.database|schema|role|warehouse) and if not, they are taken from connection definition.
   
   If merged:
   closes: #39622 
   
   
   
   ---
   **^ Add meaningful description above**
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix: Pass hook parameters to SnowflakeSqlApiHook and prep them for AP… [airflow]

Posted by "BTeclaw (via GitHub)" <gi...@apache.org>.
BTeclaw commented on PR #41150:
URL: https://github.com/apache/airflow/pull/41150#issuecomment-2277724791

   Pushed unit test for parametrization of the API call, haven't really written any unit tests like that before so feedback is welcome! Thanks


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix: Pass hook parameters to SnowflakeSqlApiHook and prep them for AP… [airflow]

Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal commented on PR #41150:
URL: https://github.com/apache/airflow/pull/41150#issuecomment-2276982158

   @BTeclaw reminder about adding tests


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix: Pass hook parameters to SnowflakeSqlApiHook and prep them for AP… [airflow]

Posted by "BTeclaw (via GitHub)" <gi...@apache.org>.
BTeclaw commented on PR #41150:
URL: https://github.com/apache/airflow/pull/41150#issuecomment-2291058816

   @Lee-W applied suggested changes - thank you!


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix: Pass hook parameters to SnowflakeSqlApiHook and prep them for AP… [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #41150:
URL: https://github.com/apache/airflow/pull/41150#discussion_r1718233631


##########
airflow/providers/snowflake/hooks/snowflake_sql_api.py:
##########
@@ -158,10 +158,13 @@ def execute_query(
         data = {
             "statement": sql,
             "resultSetMetaData": {"format": "json"},
-            "database": conn_config["database"],
-            "schema": conn_config["schema"],
-            "warehouse": conn_config["warehouse"],
-            "role": conn_config["role"],
+            # If database, schema, warehouse, role parameters have been provided set them accordingly
+            # If either of them has been not (Parent class initializes them to None in that case)
+            # set them to what in the Airflow connection configuration
+            "database": self.database if self.database else conn_config["database"],
+            "schema": self.schema if self.schema else conn_config["schema"],
+            "warehouse": self.warehouse if self.warehouse else conn_config["warehouse"],
+            "role": self.role if self.role else conn_config["role"],

Review Comment:
   ```suggestion
               "database": self.database or conn_config["database"],
               "schema": self.schema or conn_config["schema"],
               "warehouse": self.warehouse or conn_config["warehouse"],
               "role": self.role or conn_config["role"],
   ```



##########
tests/providers/snowflake/hooks/test_snowflake_sql_api.py:
##########
@@ -580,3 +587,136 @@ async def test_get_sql_api_query_status_async(
         hook = SnowflakeSqlApiHook(snowflake_conn_id="test_conn")
         response = await hook.get_sql_api_query_status_async("uuid")
         assert response == expected_response
+
+    @pytest.mark.parametrize("hook_params", [(HOOK_PARAMS), ({})])
+    def test_hook_parameter_propagation(self, hook_params):
+        """
+        This tests the proper propagation of unpacked hook params into the SnowflakeSqlApiHook object.
+        """
+        hook = SnowflakeSqlApiHook(snowflake_conn_id="test_conn", **hook_params)
+        assert hook.database == hook_params.get("database", None)
+        assert hook.schema == hook_params.get("schema", None)
+        assert hook.warehouse == hook_params.get("warehouse", None)
+        assert hook.role == hook_params.get("role", None)
+
+    @pytest.mark.parametrize(
+        "test_hook_params,sql,statement_count,expected_payload,expected_response",

Review Comment:
   ```suggestion
           "test_hook_params, sql, statement_count, expected_payload, expected_response",
   ```



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix: Pass hook parameters to SnowflakeSqlApiHook and prep them for AP… [airflow]

Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #41150:
URL: https://github.com/apache/airflow/pull/41150#issuecomment-2291091372

   Awesome work, congrats on your first merged pull request! You are invited to check our [Issue Tracker](https://github.com/apache/airflow/issues) for additional contributions.
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix: Pass hook parameters to SnowflakeSqlApiHook and prep them for AP… [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W merged PR #41150:
URL: https://github.com/apache/airflow/pull/41150


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix: Pass hook parameters to SnowflakeSqlApiHook and prep them for AP… [airflow]

Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #41150:
URL: https://github.com/apache/airflow/pull/41150#issuecomment-2260190154

   Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
   Here are some useful points:
   - Pay attention to the quality of your code (ruff, mypy and type annotations). Our [pre-commits]( https://github.com/apache/airflow/blob/main/contributing-docs/08_static_code_checks.rst#prerequisites-for-pre-commit-hooks) will help you with that.
   - In case of a new feature add useful documentation (in docstrings or in `docs/` directory). Adding a new operator? Check this short [guide](https://github.com/apache/airflow/blob/main/docs/apache-airflow/howto/custom-operator.rst) Consider adding an example DAG that shows how users should use it.
   - Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/dev/breeze/doc/README.rst) for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
   - Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
   - Please follow [ASF Code of Conduct](https://www.apache.org/foundation/policies/conduct) for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
   - Be sure to read the [Airflow Coding style]( https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#coding-style-and-best-practices).
   - Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
   Apache Airflow is a community-driven project and together we are making it better 🚀.
   In case of doubts contact the developers at:
   Mailing List: dev@airflow.apache.org
   Slack: https://s.apache.org/airflow-slack
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix: Pass hook parameters to SnowflakeSqlApiHook and prep them for AP… [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #41150:
URL: https://github.com/apache/airflow/pull/41150#issuecomment-2265585287

   Can you please add/modify a unit test for this?


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org