Source code for airflow.providers.google.cloud.operators.looker
## 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."""This module contains Google Cloud Looker operators."""from__future__importannotationsfromtypingimportTYPE_CHECKINGfromairflow.exceptionsimportAirflowExceptionfromairflow.providers.google.cloud.hooks.lookerimportLookerHookfromairflow.providers.google.cloud.operators.cloud_baseimportGoogleCloudBaseOperatorifTYPE_CHECKING:fromairflow.utils.contextimportContext
[docs]classLookerStartPdtBuildOperator(GoogleCloudBaseOperator):""" Submits a PDT materialization job to Looker. :param looker_conn_id: Required. The connection ID to use connecting to Looker. :param model: Required. The model of the PDT to start building. :param view: Required. The view of the PDT to start building. :param query_params: Optional. Additional materialization parameters. :param asynchronous: Optional. Flag indicating whether to wait for the job to finish or return immediately. This is useful for submitting long running jobs and waiting on them asynchronously using the LookerCheckPdtBuildSensor :param cancel_on_kill: Optional. Flag which indicates whether cancel the hook's job or not, when on_kill is called. :param wait_time: Optional. Number of seconds between checks for job to be ready. Used only if ``asynchronous`` is False. :param wait_timeout: Optional. How many seconds wait for job to be ready. Used only if ``asynchronous`` is False. """def__init__(self,looker_conn_id:str,model:str,view:str,query_params:dict|None=None,asynchronous:bool=False,cancel_on_kill:bool=True,wait_time:int=10,wait_timeout:int|None=None,**kwargs,)->None:super().__init__(**kwargs)self.model=modelself.view=viewself.query_params=query_paramsself.looker_conn_id=looker_conn_idself.asynchronous=asynchronousself.cancel_on_kill=cancel_on_killself.wait_time=wait_timeself.wait_timeout=wait_timeoutself.hook:LookerHook|None=Noneself.materialization_id:str|None=None
[docs]defexecute(self,context:Context)->str:self.hook=LookerHook(looker_conn_id=self.looker_conn_id)resp=self.hook.start_pdt_build(model=self.model,view=self.view,query_params=self.query_params,)self.materialization_id=resp.materialization_idifnotself.materialization_id:raiseAirflowException(f"No `materialization_id` was returned for model: {self.model}, view: {self.view}.")self.log.info("PDT materialization job submitted successfully. Job id: %s.",self.materialization_id)ifnotself.asynchronous:self.hook.wait_for_job(materialization_id=self.materialization_id,wait_time=self.wait_time,timeout=self.wait_timeout,)returnself.materialization_id