You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/08/08 06:05:46 UTC

[GitHub] [airflow] lwyszomi opened a new pull request, #25587: New Operators for the Google Cloud Dataform service

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

   New Operators for the Google Cloud Dataform service. 
   
   ---
   **^ 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] eladkal commented on a diff in pull request #25587: New Operators for the Google Cloud Dataform service

Posted by GitBox <gi...@apache.org>.
eladkal commented on code in PR #25587:
URL: https://github.com/apache/airflow/pull/25587#discussion_r939870821


##########
airflow/providers/google/cloud/hooks/dataform.py:
##########
@@ -0,0 +1,252 @@
+# 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.
+
+import time
+from typing import Dict, Optional, Sequence, Tuple, Union
+
+from google.api_core.gapic_v1.method import DEFAULT, _MethodDefault

Review Comment:
   We shouldnt import private resources of external library



-- 
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 #25587: New Operators for the Google Cloud Dataform service

Posted by GitBox <gi...@apache.org>.
pankajastro commented on code in PR #25587:
URL: https://github.com/apache/airflow/pull/25587#discussion_r940510612


##########
airflow/providers/google/cloud/operators/dataform.py:
##########
@@ -0,0 +1,408 @@
+# 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 typing import TYPE_CHECKING, Dict, Optional, Sequence, Tuple, Union
+
+from airflow.providers.google.cloud.links.dataform import DataformWorkflowInvocationLink
+
+if TYPE_CHECKING:
+    from airflow.utils.context import Context
+
+from google.api_core.gapic_v1.method import DEFAULT, _MethodDefault
+from google.api_core.retry import Retry
+from google.cloud.dataform_v1beta1.types import CompilationResult, WorkflowInvocation
+
+from airflow.models import BaseOperator
+from airflow.providers.google.cloud.hooks.dataform import DataformHook
+
+
+class DataformCreateCompilationResultOperator(BaseOperator):
+    """
+    Creates a new CompilationResult in a given project and location.
+
+    :param project_id: Required. The ID of the Google Cloud project that the task belongs to.
+    :param region: Required. The ID of the Google Cloud region that the task belongs to.
+    :param repository_id: Required. The ID of the Dataform repository that the task belongs to.
+    :param compilation_result:  Required. The compilation result to create.
+    :param retry: Designation of what errors, if any, should be retried.
+    :param timeout: The timeout for this request.
+    :param metadata: Strings which should be sent along with the request as metadata.
+    :param gcp_conn_id: The connection ID to use when fetching connection info.
+    :param delegate_to: The account to impersonate, if any. For this to work, the service accountmaking 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 gcp_conn_id:

Review Comment:
   This has been declared twice. Please remove 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] potiuk commented on a diff in pull request #25587: New Operators for the Google Cloud Dataform service

Posted by GitBox <gi...@apache.org>.
potiuk commented on code in PR #25587:
URL: https://github.com/apache/airflow/pull/25587#discussion_r939903133


##########
airflow/providers/google/cloud/hooks/dataform.py:
##########
@@ -0,0 +1,252 @@
+# 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.
+
+import time
+from typing import Dict, Optional, Sequence, Tuple, Union
+
+from google.api_core.gapic_v1.method import DEFAULT, _MethodDefault

Review Comment:
   I am afraid @eladkal  we can't avoid it because it's part of the type exposed by the API. One thing it is to make class start with _ and another is to put that class as definition of type exposed by a public method :) 



-- 
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 #25587: New Operators for the Google Cloud Dataform service

Posted by GitBox <gi...@apache.org>.
pankajastro commented on code in PR #25587:
URL: https://github.com/apache/airflow/pull/25587#discussion_r940504233


##########
airflow/providers/google/cloud/hooks/dataform.py:
##########
@@ -0,0 +1,252 @@
+# 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.
+
+import time
+from typing import Dict, Optional, Sequence, Tuple, Union
+
+from google.api_core.gapic_v1.method import DEFAULT, _MethodDefault
+from google.api_core.retry import Retry
+from google.cloud.dataform_v1beta1 import DataformClient
+from google.cloud.dataform_v1beta1.types import CompilationResult, WorkflowInvocation
+
+from airflow import AirflowException
+from airflow.providers.google.common.hooks.base_google import GoogleBaseHook
+
+
+class DataformHook(GoogleBaseHook):
+    """Hook for Google Cloud DataForm APIs."""
+
+    def get_dataform_client(
+        self,
+    ) -> DataformClient:
+        """Retrieves client library object that allow access to Cloud Dataform service."""
+        return DataformClient(credentials=self._get_credentials())
+
+    @GoogleBaseHook.fallback_to_default_project_id
+    def wait_for_workflow_invocation(
+        self,
+        workflow_invocation_id: str,
+        repository_id: str,
+        project_id: str,
+        region: str,
+        wait_time: int = 10,

Review Comment:
   We should expose `wait_time` in the operator also so that an user can control it.



##########
airflow/providers/google/cloud/hooks/dataform.py:
##########
@@ -0,0 +1,252 @@
+# 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.
+
+import time
+from typing import Dict, Optional, Sequence, Tuple, Union
+
+from google.api_core.gapic_v1.method import DEFAULT, _MethodDefault
+from google.api_core.retry import Retry
+from google.cloud.dataform_v1beta1 import DataformClient
+from google.cloud.dataform_v1beta1.types import CompilationResult, WorkflowInvocation
+
+from airflow import AirflowException
+from airflow.providers.google.common.hooks.base_google import GoogleBaseHook
+
+
+class DataformHook(GoogleBaseHook):
+    """Hook for Google Cloud DataForm APIs."""
+
+    def get_dataform_client(
+        self,
+    ) -> DataformClient:
+        """Retrieves client library object that allow access to Cloud Dataform service."""
+        return DataformClient(credentials=self._get_credentials())
+
+    @GoogleBaseHook.fallback_to_default_project_id
+    def wait_for_workflow_invocation(
+        self,
+        workflow_invocation_id: str,
+        repository_id: str,
+        project_id: str,
+        region: str,
+        wait_time: int = 10,

Review Comment:
   We should expose `wait_time` in the operator also so that a user can control 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] potiuk commented on pull request #25587: New Operators for the Google Cloud Dataform service

Posted by GitBox <gi...@apache.org>.
potiuk commented on PR #25587:
URL: https://github.com/apache/airflow/pull/25587#issuecomment-1207775551

   som docs failiure to fix (the helm failure was accidental).


-- 
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] potiuk commented on pull request #25587: New Operators for the Google Cloud Dataform service

Posted by GitBox <gi...@apache.org>.
potiuk commented on PR #25587:
URL: https://github.com/apache/airflow/pull/25587#issuecomment-1207921493

   docs/tests failing :(


-- 
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 #25587: New Operators for the Google Cloud Dataform service

Posted by GitBox <gi...@apache.org>.
pankajastro commented on code in PR #25587:
URL: https://github.com/apache/airflow/pull/25587#discussion_r940521472


##########
tests/system/providers/google/cloud/dataform/example_dataform.py:
##########
@@ -0,0 +1,170 @@
+#
+# 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.
+
+"""
+Example Airflow DAG for Google Cloud Dataform service
+"""
+import os
+from datetime import datetime
+
+from google.cloud.dataform_v1beta1 import WorkflowInvocation
+
+from airflow import models
+from airflow.models.baseoperator import chain
+from airflow.providers.google.cloud.operators.dataform import (
+    DataformCancelWorkflowInvocationOperator,
+    DataformCreateCompilationResultOperator,
+    DataformCreateWorkflowInvocationOperator,
+    DataformGetCompilationResultOperator,
+    DataformGetWorkflowInvocationOperator,
+)
+from airflow.providers.google.cloud.sensors.dataform import DataformWorkflowInvocationStateSensor
+
+ENV_ID = os.environ.get("SYSTEM_TESTS_ENV_ID")
+PROJECT_ID = os.environ.get("SYSTEM_TESTS_GCP_PROJECT", "test-project-id")
+
+DAG_ID = "dataform"
+
+REPOSITORY_ID = "dataform-test2"
+REGION = "us-central1"
+WORKSPACE_ID = "testing"
+
+with models.DAG(
+    DAG_ID,
+    schedule_interval='@once',  # Override to match your needs
+    start_date=datetime(2021, 1, 1),
+    catchup=False,
+    tags=['example', 'dataform'],
+) as dag:
+    # [START howto_operator_create_compilation_result]
+    create_compilation_result = DataformCreateCompilationResultOperator(
+        task_id="create_compilation_result",
+        project_id=PROJECT_ID,
+        region=REGION,
+        repository_id=REPOSITORY_ID,
+        compilation_result={
+            "git_commitish": "main",
+            "workspace": (
+                f"projects/{PROJECT_ID}/locations/{REGION}/repositories/{REPOSITORY_ID}/"
+                f"workspaces/{WORKSPACE_ID}"
+            ),
+        },
+    )
+    # [END howto_operator_create_compilation_result]
+
+    # [START howto_operator_get_compilation_result]
+    get_compilation_result = DataformGetCompilationResultOperator(
+        task_id="get_compilation_result",
+        project_id=PROJECT_ID,
+        region=REGION,
+        repository_id=REPOSITORY_ID,
+        compilation_result_id=(
+            "{{ task_instance.xcom_pull('create_compilation_result')['name'].split('/')[-1] }}"
+        ),
+    )
+    # [END howto_operator_get_compilation_result]]
+
+    # [START howto_operator_create_workflow_invocation]
+    create_workflow_invocation = DataformCreateWorkflowInvocationOperator(
+        task_id='create_workflow_invocation',
+        project_id=PROJECT_ID,
+        region=REGION,
+        repository_id=REPOSITORY_ID,
+        workflow_invocation={
+            "compilation_result": "{{ task_instance.xcom_pull('create_compilation_result')['name'] }}"
+        },
+    )
+    # [END howto_operator_create_workflow_invocation]

Review Comment:
   ```suggestion
       # [END howto_operator_create_workflow_invocation]
       
   ```



-- 
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] potiuk merged pull request #25587: New Operators for the Google Cloud Dataform service

Posted by GitBox <gi...@apache.org>.
potiuk merged PR #25587:
URL: https://github.com/apache/airflow/pull/25587


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