vincbeck commented on code in PR #32785:
URL: https://github.com/apache/airflow/pull/32785#discussion_r1272269208


##########
airflow/providers/amazon/aws/hooks/redshift_data.py:
##########
@@ -95,6 +100,12 @@ def execute_query(
 
         statement_id = resp["Id"]
 
+        if kwargs["ClusterIdentifier"] and kwargs["WorkgroupName"]:

Review Comment:
   Another solution: merge the two if into one with:
   
   ```python
   if bool(cluster_identifier) == bool(workgroup_name):
   ```



##########
tests/providers/amazon/aws/hooks/test_redshift_data.py:
##########
@@ -39,22 +41,53 @@ def test_conn_attribute(self):
     
@mock.patch("airflow.providers.amazon.aws.hooks.redshift_data.RedshiftDataHook.conn")
     def test_execute_without_waiting(self, mock_conn):
         mock_conn.execute_statement.return_value = {"Id": STATEMENT_ID}
+        cluster_identifier = "cluster_identifier"
 
         hook = RedshiftDataHook()
         hook.execute_query(
             database=DATABASE,
+            cluster_identifier=cluster_identifier,
             sql=SQL,
             wait_for_completion=False,
         )
         mock_conn.execute_statement.assert_called_once_with(
             Database=DATABASE,
+            ClusterIdentifier=cluster_identifier,
             Sql=SQL,
             WithEvent=False,
         )
         mock_conn.describe_statement.assert_not_called()
 
     
@mock.patch("airflow.providers.amazon.aws.hooks.redshift_data.RedshiftDataHook.conn")
-    def test_execute_with_all_parameters(self, mock_conn):
+    def test_execute_requires_cluster_identifier_or_workgroup_name(self, 
mock_conn):
+        mock_conn.execute_statement.return_value = {"Id": STATEMENT_ID}
+
+        with pytest.raises(ValueError):
+            hook = RedshiftDataHook()
+            hook.execute_query(
+                database=DATABASE,
+                sql=SQL,
+                wait_for_completion=False,
+            )
+
+    
@mock.patch("airflow.providers.amazon.aws.hooks.redshift_data.RedshiftDataHook.conn")
+    def 
test_execute_requires_cluster_identifier_or_workgroup_name_not_both(self, 
mock_conn):
+        mock_conn.execute_statement.return_value = {"Id": STATEMENT_ID}
+        cluster_identifier = "cluster_identifier"
+        workgroup_name = "workgroup_name"
+
+        with pytest.raises(ValueError):
+            hook = RedshiftDataHook()
+            hook.execute_query(
+                database=DATABASE,
+                cluster_identifier=cluster_identifier,
+                workgroup_name=workgroup_name,
+                sql=SQL,
+                wait_for_completion=False,
+            )

Review Comment:
   nit: you can merge these two tests into one using @parametrize



##########
airflow/providers/amazon/aws/hooks/redshift_data.py:
##########
@@ -95,6 +100,12 @@ def execute_query(
 
         statement_id = resp["Id"]
 
+        if kwargs["ClusterIdentifier"] and kwargs["WorkgroupName"]:
+            raise ValueError("Specify either 'cluster_identifier' or 
'workgroup_name', not both.")
+
+        if not kwargs["ClusterIdentifier"] and not kwargs["WorkgroupName"]:

Review Comment:
   ```suggestion
           if not cluster_identifier and not workgroup_name:
   ```



##########
airflow/providers/amazon/aws/operators/redshift_data.py:
##########
@@ -113,12 +120,19 @@ def hook(self) -> RedshiftDataHook:
 
     def execute(self, context: Context) -> GetStatementResultResponseTypeDef | 
str:
         """Execute a statement against Amazon Redshift."""
+        if self.cluster_identifier and self.workgroup_name:
+            raise AirflowException("Specify either 'cluster_identifier' or 
'workgroup_name', not both.")
+
+        if not self.cluster_identifier and not self.workgroup_name:
+            raise AirflowException("Either 'cluster_identifier' or 
'workgroup_name' must be specified.")

Review Comment:
   You're already making these checks in the hook, no need to do it again here



##########
airflow/providers/amazon/aws/hooks/redshift_data.py:
##########
@@ -95,6 +100,12 @@ def execute_query(
 
         statement_id = resp["Id"]
 
+        if kwargs["ClusterIdentifier"] and kwargs["WorkgroupName"]:

Review Comment:
   ```suggestion
           if cluster_identifier and workgroup_name:
   ```



-- 
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-unsubscr...@airflow.apache.org

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

Reply via email to