You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "phanikumv (via GitHub)" <gi...@apache.org> on 2023/05/12 11:35:36 UTC

[GitHub] [airflow] phanikumv opened a new pull request, #31249: Optimize deferred mode execution for `BigQueryInsertJobOperator`

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

   This PR  verifies if a BigQuery job has already completed before deferring the task to prevent unnecessary deferring. This way, we can skip deferring the task if it has already been finished.
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of an existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   ---
   **^ Add meaningful description above**
   
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.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


[GitHub] [airflow] phanikumv commented on a diff in pull request #31249: Optimize deferrable mode execution for `BigQueryInsertJobOperator`

Posted by "phanikumv (via GitHub)" <gi...@apache.org>.
phanikumv commented on code in PR #31249:
URL: https://github.com/apache/airflow/pull/31249#discussion_r1193927389


##########
airflow/providers/google/cloud/operators/bigquery.py:
##########
@@ -2698,16 +2698,18 @@ def execute(self, context: Any):
             self._handle_job_error(job)
 
             return self.job_id
-        self.defer(
-            timeout=self.execution_timeout,
-            trigger=BigQueryInsertJobTrigger(
-                conn_id=self.gcp_conn_id,
-                job_id=self.job_id,
-                project_id=self.project_id,
-                poll_interval=self.poll_interval,
-            ),
-            method_name="execute_complete",
-        )
+        else:
+            if job.running():

Review Comment:
   Please check [39610fe](https://github.com/apache/airflow/pull/31249/commits/39610fed29360ef91db685e40a1aa9662105ad18) and let me know wdyt about it



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


[GitHub] [airflow] phanikumv commented on a diff in pull request #31249: Optimize deferrable mode execution for `BigQueryInsertJobOperator`

Posted by "phanikumv (via GitHub)" <gi...@apache.org>.
phanikumv commented on code in PR #31249:
URL: https://github.com/apache/airflow/pull/31249#discussion_r1202722990


##########
airflow/providers/google/cloud/operators/bigquery.py:
##########
@@ -2698,16 +2698,19 @@ def execute(self, context: Any):
             self._handle_job_error(job)
 
             return self.job_id
-        self.defer(
-            timeout=self.execution_timeout,
-            trigger=BigQueryInsertJobTrigger(
-                conn_id=self.gcp_conn_id,
-                job_id=self.job_id,
-                project_id=self.project_id,
-                poll_interval=self.poll_interval,
-            ),
-            method_name="execute_complete",
-        )
+        else:
+            if job.running():
+                self.defer(
+                    timeout=self.execution_timeout,
+                    trigger=BigQueryInsertJobTrigger(
+                        conn_id=self.gcp_conn_id,
+                        job_id=self.job_id,
+                        project_id=self.project_id,
+                        poll_interval=self.poll_interval,
+                    ),
+                    method_name="execute_complete",
+                )
+            self.log.info("Current state of job %s is %s", job.job_id, job.state)

Review Comment:
   Done in [1f76434](https://github.com/apache/airflow/pull/31249/commits/1f7643416455fdd0ba3d11107278471d25902c36)



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


[GitHub] [airflow] phanikumv commented on a diff in pull request #31249: Optimize deferrable mode execution for `BigQueryInsertJobOperator`

Posted by "phanikumv (via GitHub)" <gi...@apache.org>.
phanikumv commented on code in PR #31249:
URL: https://github.com/apache/airflow/pull/31249#discussion_r1193135426


##########
airflow/providers/google/cloud/operators/bigquery.py:
##########
@@ -2698,16 +2698,17 @@ def execute(self, context: Any):
             self._handle_job_error(job)
 
             return self.job_id
-        self.defer(
-            timeout=self.execution_timeout,
-            trigger=BigQueryInsertJobTrigger(
-                conn_id=self.gcp_conn_id,
-                job_id=self.job_id,
-                project_id=self.project_id,
-                poll_interval=self.poll_interval,
-            ),
-            method_name="execute_complete",
-        )
+        elif self.deferrable and job.running():

Review Comment:
   1.Corrected in d443fa3
   2.If there's an error it will be sent to `execute_complete()` from `BigQueryInsertJobTrigger`.The task will fail due to the AirflowException raised there.



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


[GitHub] [airflow] phanikumv commented on pull request #31249: Optimize deferrable mode execution for `BigQueryInsertJobOperator`

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

   > We should also add the documentation changes along with example DAGs
   
   Documentation and example DAG already added in a previous PR. Check out #26433


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


[GitHub] [airflow] shahar1 commented on a diff in pull request #31249: Optimize deferrable mode execution for `BigQueryInsertJobOperator`

Posted by "shahar1 (via GitHub)" <gi...@apache.org>.
shahar1 commented on code in PR #31249:
URL: https://github.com/apache/airflow/pull/31249#discussion_r1193781362


##########
airflow/providers/google/cloud/operators/bigquery.py:
##########
@@ -2698,16 +2698,18 @@ def execute(self, context: Any):
             self._handle_job_error(job)
 
             return self.job_id
-        self.defer(
-            timeout=self.execution_timeout,
-            trigger=BigQueryInsertJobTrigger(
-                conn_id=self.gcp_conn_id,
-                job_id=self.job_id,
-                project_id=self.project_id,
-                poll_interval=self.poll_interval,
-            ),
-            method_name="execute_complete",
-        )
+        else:
+            if job.running():

Review Comment:
   +1, in my previous comment, I referred to the fact that it may silently exit with an error, and we won't be aware of it



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


[GitHub] [airflow] sunank200 commented on a diff in pull request #31249: Optimize deferrable mode execution for `BigQueryInsertJobOperator`

Posted by "sunank200 (via GitHub)" <gi...@apache.org>.
sunank200 commented on code in PR #31249:
URL: https://github.com/apache/airflow/pull/31249#discussion_r1193826725


##########
airflow/providers/google/cloud/operators/bigquery.py:
##########
@@ -2698,16 +2698,18 @@ def execute(self, context: Any):
             self._handle_job_error(job)
 
             return self.job_id
-        self.defer(
-            timeout=self.execution_timeout,
-            trigger=BigQueryInsertJobTrigger(
-                conn_id=self.gcp_conn_id,
-                job_id=self.job_id,
-                project_id=self.project_id,
-                poll_interval=self.poll_interval,
-            ),
-            method_name="execute_complete",
-        )
+        else:
+            if job.running():

Review Comment:
   +1



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


[GitHub] [airflow] shahar1 commented on a diff in pull request #31249: Optimize deferrable mode execution for `BigQueryInsertJobOperator`

Posted by "shahar1 (via GitHub)" <gi...@apache.org>.
shahar1 commented on code in PR #31249:
URL: https://github.com/apache/airflow/pull/31249#discussion_r1192790058


##########
airflow/providers/google/cloud/operators/bigquery.py:
##########
@@ -2698,16 +2698,17 @@ def execute(self, context: Any):
             self._handle_job_error(job)
 
             return self.job_id
-        self.defer(
-            timeout=self.execution_timeout,
-            trigger=BigQueryInsertJobTrigger(
-                conn_id=self.gcp_conn_id,
-                job_id=self.job_id,
-                project_id=self.project_id,
-                poll_interval=self.poll_interval,
-            ),
-            method_name="execute_complete",
-        )
+        elif self.deferrable and job.running():

Review Comment:
   1. The first part of the `elif` is always `True`, as it is the `else` case  `if not self.deferrable`
   2. What happens if there's an error in the result? Currently, it will finish the `execute()` successfully.



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


[GitHub] [airflow] pankajkoti commented on a diff in pull request #31249: Optimize deferrable mode execution for `BigQueryInsertJobOperator`

Posted by "pankajkoti (via GitHub)" <gi...@apache.org>.
pankajkoti commented on code in PR #31249:
URL: https://github.com/apache/airflow/pull/31249#discussion_r1198565718


##########
airflow/providers/google/cloud/operators/bigquery.py:
##########
@@ -2698,16 +2698,19 @@ def execute(self, context: Any):
             self._handle_job_error(job)
 
             return self.job_id
-        self.defer(
-            timeout=self.execution_timeout,
-            trigger=BigQueryInsertJobTrigger(
-                conn_id=self.gcp_conn_id,
-                job_id=self.job_id,
-                project_id=self.project_id,
-                poll_interval=self.poll_interval,
-            ),
-            method_name="execute_complete",
-        )
+        else:
+            if job.running():
+                self.defer(
+                    timeout=self.execution_timeout,
+                    trigger=BigQueryInsertJobTrigger(
+                        conn_id=self.gcp_conn_id,
+                        job_id=self.job_id,
+                        project_id=self.project_id,
+                        poll_interval=self.poll_interval,
+                    ),
+                    method_name="execute_complete",
+                )
+            self.log.info("Current state of job %s is %s", job.job_id, job.state)

Review Comment:
   I think it's nice to capture and assert this log in the test too.



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


[GitHub] [airflow] ephraimbuddy merged pull request #31249: Optimize deferrable mode execution for `BigQueryInsertJobOperator`

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


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


[GitHub] [airflow] pankajkoti commented on a diff in pull request #31249: Optimize deferrable mode execution for `BigQueryInsertJobOperator`

Posted by "pankajkoti (via GitHub)" <gi...@apache.org>.
pankajkoti commented on code in PR #31249:
URL: https://github.com/apache/airflow/pull/31249#discussion_r1193775854


##########
airflow/providers/google/cloud/operators/bigquery.py:
##########
@@ -2698,16 +2698,18 @@ def execute(self, context: Any):
             self._handle_job_error(job)
 
             return self.job_id
-        self.defer(
-            timeout=self.execution_timeout,
-            trigger=BigQueryInsertJobTrigger(
-                conn_id=self.gcp_conn_id,
-                job_id=self.job_id,
-                project_id=self.project_id,
-                poll_interval=self.poll_interval,
-            ),
-            method_name="execute_complete",
-        )
+        else:
+            if job.running():

Review Comment:
   If the job has completed, can we add some log for the user to tell that query has finished processing? It looks like we silently exit here without any information for the user.



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