You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "bkossakowska (via GitHub)" <gi...@apache.org> on 2023/02/24 07:58:54 UTC

[GitHub] [airflow] bkossakowska opened a new pull request, #29735: Add deferrable mode to BigQueryTablePartitionExistenceSensor.

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

   <!--
   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 deferrable mode to BigQueryTablePartitionExistenceSensor.
   
   ---
   **^ 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] pankajastro commented on a diff in pull request #29735: Add deferrable mode to BigQueryTablePartitionExistenceSensor.

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


##########
airflow/providers/google/cloud/sensors/bigquery.py:
##########
@@ -244,3 +247,69 @@ def execute_complete(self, context: dict[str, Any], event: dict[str, str] | None
                 return event["message"]
             raise AirflowException(event["message"])
         raise AirflowException("No event received in trigger callback")
+
+
+class BigQueryTableExistencePartitionAsyncSensor(BigQueryTablePartitionExistenceSensor):
+    """
+    Checks for the existence of a partition within a table in Google BigQuery.
+
+    :param project_id: The Google cloud project in which to look for the table.
+       The connection supplied to the hook must provide
+       access to the specified project.
+    :param dataset_id: The name of the dataset in which to look for the table.
+       storage bucket.
+    :param partition_id: The name of the partition to check the existence of.
+    :param table_id: The name of the table to check the existence of.
+    :param gcp_conn_id: The connection ID used to connect to Google Cloud.
+    :param bigquery_conn_id: (Deprecated) The connection ID used to connect to Google Cloud.
+       This parameter has been deprecated. You should pass the gcp_conn_id parameter instead.
+    :param delegate_to: The account to impersonate using domain-wide delegation of authority,

Review Comment:
   `delegate_to` has been deprecated so shall we avoid this adding here considering this is a new feature?



##########
airflow/providers/google/cloud/sensors/bigquery.py:
##########
@@ -244,3 +247,69 @@ def execute_complete(self, context: dict[str, Any], event: dict[str, str] | None
                 return event["message"]
             raise AirflowException(event["message"])
         raise AirflowException("No event received in trigger callback")
+
+
+class BigQueryTableExistencePartitionAsyncSensor(BigQueryTablePartitionExistenceSensor):
+    """
+    Checks for the existence of a partition within a table in Google BigQuery.
+
+    :param project_id: The Google cloud project in which to look for the table.
+       The connection supplied to the hook must provide
+       access to the specified project.
+    :param dataset_id: The name of the dataset in which to look for the table.
+       storage bucket.
+    :param partition_id: The name of the partition to check the existence of.
+    :param table_id: The name of the table to check the existence of.
+    :param gcp_conn_id: The connection ID used to connect to Google Cloud.
+    :param bigquery_conn_id: (Deprecated) The connection ID used to connect to Google Cloud.
+       This parameter has been deprecated. You should pass the gcp_conn_id parameter instead.
+    :param delegate_to: The account to impersonate using domain-wide delegation of authority,
+       if any. For this to work, the service account making the request must have
+       domain-wide delegation enabled.
+    :param impersonation_chain: Optional service account to impersonate using short-term
+       credentials, or chained list of accounts required to get the access_token
+       of the last account in the list, which will be impersonated in the request.
+       If set as a string, the account must grant the originating account
+       the Service Account Token Creator IAM role.
+       If set as a sequence, the identities from the list must grant
+       Service Account Token Creator IAM role to the directly preceding identity, with first
+       account from the list granting this role to the originating account (templated).
+    :param polling_interval_seconds: The interval in seconds to wait between checks table existence.

Review Comment:
   sensors expose `poke_interval ` can we reuse that here?



-- 
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] dimberman merged pull request #29735: Add deferrable mode to BigQueryTablePartitionExistenceSensor.

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


-- 
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] dimberman commented on a diff in pull request #29735: Add deferrable mode to BigQueryTablePartitionExistenceSensor.

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


##########
airflow/providers/google/cloud/triggers/bigquery.py:
##########
@@ -529,3 +529,67 @@ async def _table_exists(
                 if err.status == 404:
                     return False
                 raise err
+
+
+class BigQueryTablePartitionExistenceTrigger(BigQueryTableExistenceTrigger):
+    """
+    Initialize the BigQuery Table Partition Existence Trigger with needed parameters
+    :param partition_id: The name of the partition to check the existence of.
+    :param project_id: Google Cloud Project where the job is running
+    :param dataset_id: The dataset ID of the requested table.
+    :param table_id: The table ID of the requested table.
+    :param gcp_conn_id: Reference to google cloud connection id
+    :param hook_params: params for hook
+    :param polling_interval_seconds: polling period in seconds to check for the status
+    """
+
+    def __init__(self, partition_id: str, **kwargs):
+        super().__init__(**kwargs)
+        self.partition_id = partition_id
+
+    def serialize(self) -> tuple[str, dict[str, Any]]:
+        """Serializes BigQueryTablePartitionExistenceTrigger arguments and classpath."""
+        return (
+            "airflow.providers.google.cloud.triggers.bigquery.BigQueryTablePartitionExistenceTrigger",
+            {
+                "partition_id": self.partition_id,
+                "dataset_id": self.dataset_id,
+                "project_id": self.project_id,
+                "table_id": self.table_id,
+                "gcp_conn_id": self.gcp_conn_id,
+                "poll_interval": self.poll_interval,
+                "hook_params": self.hook_params,
+            },
+        )
+
+    async def run(self) -> AsyncIterator["TriggerEvent"]:  # type: ignore[override]
+        """Will run until the table exists in the Google Big Query."""
+        hook = BigQueryAsyncHook(gcp_conn_id=self.gcp_conn_id)
+        job_id = None
+        while True:
+            if job_id is not None:
+                status = await hook.get_job_status(job_id=job_id, project_id=self.project_id)
+                if status == "success":
+                    query_results = await hook.get_job_output(job_id=job_id, project_id=self.project_id)
+                    records = hook.get_records(query_results)
+                    if records:
+                        records = [row[0] for row in records]
+                        if self.partition_id in records:
+                            yield TriggerEvent(
+                                {
+                                    "status": "success",
+                                    "message": f"Partition: {self.partition_id} in table: {self.table_id}",
+                                }
+                            )
+                            return

Review Comment:
   Can you break this out into a helper function?



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