airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From criccom...@apache.org
Subject [28/35] incubator-airflow-site git commit: 1.9.0
Date Wed, 03 Jan 2018 17:48:28 GMT
http://git-wip-us.apache.org/repos/asf/incubator-airflow-site/blob/28a3eb60/_modules/airflow/contrib/operators/dataproc_operator.html
----------------------------------------------------------------------
diff --git a/_modules/airflow/contrib/operators/dataproc_operator.html b/_modules/airflow/contrib/operators/dataproc_operator.html
new file mode 100644
index 0000000..d49719e
--- /dev/null
+++ b/_modules/airflow/contrib/operators/dataproc_operator.html
@@ -0,0 +1,1139 @@
+
+
+<!DOCTYPE html>
+<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
+<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
+<head>
+  <meta charset="utf-8">
+  
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  
+  <title>airflow.contrib.operators.dataproc_operator &mdash; Airflow Documentation</title>
+  
+
+  
+  
+  
+  
+
+  
+
+  
+  
+    
+
+  
+
+  
+  
+    <link rel="stylesheet" href="../../../../_static/css/theme.css" type="text/css" />
+  
+
+  
+
+  
+        <link rel="index" title="Index"
+              href="../../../../genindex.html"/>
+        <link rel="search" title="Search" href="../../../../search.html"/>
+    <link rel="top" title="Airflow Documentation" href="../../../../index.html"/>
+        <link rel="up" title="Module code" href="../../../index.html"/> 
+
+  
+  <script src="../../../../_static/js/modernizr.min.js"></script>
+
+</head>
+
+<body class="wy-body-for-nav" role="document">
+
+   
+  <div class="wy-grid-for-nav">
+
+    
+    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
+      <div class="wy-side-scroll">
+        <div class="wy-side-nav-search">
+          
+
+          
+            <a href="../../../../index.html" class="icon icon-home"> Airflow
+          
+
+          
+          </a>
+
+          
+            
+            
+          
+
+          
+<div role="search">
+  <form id="rtd-search-form" class="wy-form" action="../../../../search.html" method="get">
+    <input type="text" name="q" placeholder="Search docs" />
+    <input type="hidden" name="check_keywords" value="yes" />
+    <input type="hidden" name="area" value="default" />
+  </form>
+</div>
+
+          
+        </div>
+
+        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
+          
+            
+            
+              
+            
+            
+              <ul>
+<li class="toctree-l1"><a class="reference internal" href="../../../../project.html">Project</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../license.html">License</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../start.html">Quick Start</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../installation.html">Installation</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../tutorial.html">Tutorial</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../configuration.html">Configuration</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../ui.html">UI / Screenshots</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../concepts.html">Concepts</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../profiling.html">Data Profiling</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../cli.html">Command Line Interface</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../scheduler.html">Scheduling &amp; Triggers</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../plugins.html">Plugins</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../security.html">Security</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../api.html">Experimental Rest API</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../integration.html">Integration</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../faq.html">FAQ</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../../code.html">API Reference</a></li>
+</ul>
+
+            
+          
+        </div>
+      </div>
+    </nav>
+
+    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
+
+      
+      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
+        
+          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
+          <a href="../../../../index.html">Airflow</a>
+        
+      </nav>
+
+
+      
+      <div class="wy-nav-content">
+        <div class="rst-content">
+          
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+<div role="navigation" aria-label="breadcrumbs navigation">
+
+  <ul class="wy-breadcrumbs">
+    
+      <li><a href="../../../../index.html">Docs</a> &raquo;</li>
+        
+          <li><a href="../../../index.html">Module code</a> &raquo;</li>
+        
+      <li>airflow.contrib.operators.dataproc_operator</li>
+    
+    
+      <li class="wy-breadcrumbs-aside">
+        
+            
+        
+      </li>
+    
+  </ul>
+
+  
+  <hr/>
+</div>
+          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
+           <div itemprop="articleBody">
+            
+  <h1>Source code for airflow.contrib.operators.dataproc_operator</h1><div class="highlight"><pre>
+<span></span><span class="c1"># -*- coding: utf-8 -*-</span>
+<span class="c1">#</span>
+<span class="c1"># Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span>
+<span class="c1"># you may not use this file except in compliance with the License.</span>
+<span class="c1"># You may obtain a copy of the License at</span>
+<span class="c1">#</span>
+<span class="c1"># http://www.apache.org/licenses/LICENSE-2.0</span>
+<span class="c1">#</span>
+<span class="c1"># Unless required by applicable law or agreed to in writing, software</span>
+<span class="c1"># distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span>
+<span class="c1"># WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
+<span class="c1"># See the License for the specific language governing permissions and</span>
+<span class="c1"># limitations under the License.</span>
+<span class="c1">#</span>
+
+<span class="kn">import</span> <span class="nn">time</span>
+
+<span class="kn">from</span> <span class="nn">airflow.contrib.hooks.gcp_dataproc_hook</span> <span class="k">import</span> <span class="n">DataProcHook</span>
+<span class="kn">from</span> <span class="nn">airflow.models</span> <span class="k">import</span> <span class="n">BaseOperator</span>
+<span class="kn">from</span> <span class="nn">airflow.utils.decorators</span> <span class="k">import</span> <span class="n">apply_defaults</span>
+<span class="kn">from</span> <span class="nn">airflow.version</span> <span class="k">import</span> <span class="n">version</span>
+<span class="kn">from</span> <span class="nn">googleapiclient.errors</span> <span class="k">import</span> <span class="n">HttpError</span>
+
+
+<span class="k">class</span> <span class="nc">DataprocClusterCreateOperator</span><span class="p">(</span><span class="n">BaseOperator</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Create a new cluster on Google Cloud Dataproc. The operator will wait until the</span>
+<span class="sd">    creation is successful or an error occurs in the creation process.</span>
+
+<span class="sd">    The parameters allow to configure the cluster. Please refer to</span>
+
+<span class="sd">    https://cloud.google.com/dataproc/docs/reference/rest/v1/projects.regions.clusters</span>
+
+<span class="sd">    for a detailed explanation on the different parameters. Most of the configuration</span>
+<span class="sd">    parameters detailed in the link are available as a parameter to this operator.</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="n">template_fields</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;cluster_name&#39;</span><span class="p">,]</span>
+
+    <span class="nd">@apply_defaults</span>
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
+                 <span class="n">cluster_name</span><span class="p">,</span>
+                 <span class="n">project_id</span><span class="p">,</span>
+                 <span class="n">num_workers</span><span class="p">,</span>
+                 <span class="n">zone</span><span class="p">,</span>
+                 <span class="n">storage_bucket</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+                 <span class="n">init_actions_uris</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+                 <span class="n">metadata</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+                 <span class="n">image_version</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+                 <span class="n">properties</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+                 <span class="n">master_machine_type</span><span class="o">=</span><span class="s1">&#39;n1-standard-4&#39;</span><span class="p">,</span>
+                 <span class="n">master_disk_size</span><span class="o">=</span><span class="mi">500</span><span class="p">,</span>
+                 <span class="n">worker_machine_type</span><span class="o">=</span><span class="s1">&#39;n1-standard-4&#39;</span><span class="p">,</span>
+                 <span class="n">worker_disk_size</span><span class="o">=</span><span class="mi">500</span><span class="p">,</span>
+                 <span class="n">num_preemptible_workers</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
+                 <span class="n">labels</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+                 <span class="n">region</span><span class="o">=</span><span class="s1">&#39;global&#39;</span><span class="p">,</span>
+                 <span class="n">gcp_conn_id</span><span class="o">=</span><span class="s1">&#39;google_cloud_default&#39;</span><span class="p">,</span>
+                 <span class="n">delegate_to</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+                 <span class="n">service_account</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+                 <span class="n">service_account_scopes</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+                 <span class="o">*</span><span class="n">args</span><span class="p">,</span>
+                 <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Create a new DataprocClusterCreateOperator.</span>
+
+<span class="sd">        For more info on the creation of a cluster through the API, have a look at:</span>
+
+<span class="sd">        https://cloud.google.com/dataproc/docs/reference/rest/v1/projects.regions.clusters</span>
+
+<span class="sd">        :param cluster_name: The name of the DataProc cluster to create.</span>
+<span class="sd">        :type cluster_name: string</span>
+<span class="sd">        :param project_id: The ID of the google cloud project in which</span>
+<span class="sd">            to create the cluster</span>
+<span class="sd">        :type project_id: string</span>
+<span class="sd">        :param num_workers: The # of workers to spin up</span>
+<span class="sd">        :type num_workers: int</span>
+<span class="sd">        :param storage_bucket: The storage bucket to use, setting to None lets dataproc</span>
+<span class="sd">            generate a custom one for you</span>
+<span class="sd">        :type storage_bucket: string</span>
+<span class="sd">        :param init_actions_uris: List of GCS uri&#39;s containing</span>
+<span class="sd">            dataproc initialization scripts</span>
+<span class="sd">        :type init_actions_uris: list[string]</span>
+<span class="sd">        :param metadata: dict of key-value google compute engine metadata entries</span>
+<span class="sd">            to add to all instances</span>
+<span class="sd">        :type metadata: dict</span>
+<span class="sd">        :param image_version: the version of software inside the Dataproc cluster</span>
+<span class="sd">        :type image_version: string</span>
+<span class="sd">        :param properties: dict of properties to set on</span>
+<span class="sd">            config files (e.g. spark-defaults.conf), see</span>
+<span class="sd">            https://cloud.google.com/dataproc/docs/reference/rest/v1/ \</span>
+<span class="sd">            projects.regions.clusters#SoftwareConfig</span>
+<span class="sd">        :type properties: dict</span>
+<span class="sd">        :param master_machine_type: Compute engine machine type to use for the master node</span>
+<span class="sd">        :type master_machine_type: string</span>
+<span class="sd">        :param master_disk_size: Disk size for the master node</span>
+<span class="sd">        :type int</span>
+<span class="sd">        :param worker_machine_type:Compute engine machine type to use for the worker nodes</span>
+<span class="sd">        :type worker_machine_type: string</span>
+<span class="sd">        :param worker_disk_size: Disk size for the worker nodes</span>
+<span class="sd">        :type worker_disk_size: int</span>
+<span class="sd">        :param num_preemptible_workers: The # of preemptible worker nodes to spin up</span>
+<span class="sd">        :type num_preemptible_workers: int</span>
+<span class="sd">        :param labels: dict of labels to add to the cluster</span>
+<span class="sd">        :type labels: dict</span>
+<span class="sd">        :param zone: The zone where the cluster will be located</span>
+<span class="sd">        :type zone: string</span>
+<span class="sd">        :param region: leave as &#39;global&#39;, might become relevant in the future</span>
+<span class="sd">        :param gcp_conn_id: The connection ID to use connecting to Google Cloud Platform.</span>
+<span class="sd">        :type gcp_conn_id: string</span>
+<span class="sd">        :param delegate_to: The account to impersonate, if any.</span>
+<span class="sd">            For this to work, the service account making the request must have domain-wide</span>
+<span class="sd">            delegation enabled.</span>
+<span class="sd">        :type delegate_to: string</span>
+<span class="sd">        :param service_account: The service account of the dataproc instances.</span>
+<span class="sd">        :type service_account: string</span>
+<span class="sd">        :param service_account_scopes: The URIs of service account scopes to be included.</span>
+<span class="sd">        :type service_account_scopes: list[string]</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="nb">super</span><span class="p">(</span><span class="n">DataprocClusterCreateOperator</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">gcp_conn_id</span> <span class="o">=</span> <span class="n">gcp_conn_id</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">delegate_to</span> <span class="o">=</span> <span class="n">delegate_to</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">cluster_name</span> <span class="o">=</span> <span class="n">cluster_name</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">project_id</span> <span class="o">=</span> <span class="n">project_id</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">num_workers</span> <span class="o">=</span> <span class="n">num_workers</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">num_preemptible_workers</span> <span class="o">=</span> <span class="n">num_preemptible_workers</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">storage_bucket</span> <span class="o">=</span> <span class="n">storage_bucket</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">init_actions_uris</span> <span class="o">=</span> <span class="n">init_actions_uris</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">metadata</span> <span class="o">=</span> <span class="n">metadata</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">image_version</span> <span class="o">=</span> <span class="n">image_version</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">properties</span> <span class="o">=</span> <span class="n">properties</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">master_machine_type</span> <span class="o">=</span> <span class="n">master_machine_type</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">master_disk_size</span> <span class="o">=</span> <span class="n">master_disk_size</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">worker_machine_type</span> <span class="o">=</span> <span class="n">worker_machine_type</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">worker_disk_size</span> <span class="o">=</span> <span class="n">worker_disk_size</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">labels</span> <span class="o">=</span> <span class="n">labels</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">zone</span> <span class="o">=</span> <span class="n">zone</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">region</span> <span class="o">=</span> <span class="n">region</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">service_account</span> <span class="o">=</span> <span class="n">service_account</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">service_account_scopes</span> <span class="o">=</span> <span class="n">service_account_scopes</span>
+
+    <span class="k">def</span> <span class="nf">_get_cluster_list_for_project</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service</span><span class="p">):</span>
+        <span class="n">result</span> <span class="o">=</span> <span class="n">service</span><span class="o">.</span><span class="n">projects</span><span class="p">()</span><span class="o">.</span><span class="n">regions</span><span class="p">()</span><span class="o">.</span><span class="n">clusters</span><span class="p">()</span><span class="o">.</span><span class="n">list</span><span class="p">(</span>
+            <span class="n">projectId</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">project_id</span><span class="p">,</span>
+            <span class="n">region</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">region</span>
+        <span class="p">)</span><span class="o">.</span><span class="n">execute</span><span class="p">()</span>
+        <span class="k">return</span> <span class="n">result</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;clusters&#39;</span><span class="p">,</span> <span class="p">[])</span>
+
+    <span class="k">def</span> <span class="nf">_get_cluster</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service</span><span class="p">):</span>
+        <span class="n">cluster_list</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_cluster_list_for_project</span><span class="p">(</span><span class="n">service</span><span class="p">)</span>
+        <span class="n">cluster</span> <span class="o">=</span> <span class="p">[</span><span class="n">c</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">cluster_list</span> <span class="k">if</span> <span class="n">c</span><span class="p">[</span><span class="s1">&#39;clusterName&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">cluster_name</span><span class="p">]</span>
+        <span class="k">if</span> <span class="n">cluster</span><span class="p">:</span>
+            <span class="k">return</span> <span class="n">cluster</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
+        <span class="k">return</span> <span class="kc">None</span>
+
+    <span class="k">def</span> <span class="nf">_get_cluster_state</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service</span><span class="p">):</span>
+        <span class="n">cluster</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_cluster</span><span class="p">(</span><span class="n">service</span><span class="p">)</span>
+        <span class="k">if</span> <span class="s1">&#39;status&#39;</span> <span class="ow">in</span> <span class="n">cluster</span><span class="p">:</span>
+            <span class="k">return</span> <span class="n">cluster</span><span class="p">[</span><span class="s1">&#39;status&#39;</span><span class="p">][</span><span class="s1">&#39;state&#39;</span><span class="p">]</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="k">return</span> <span class="kc">None</span>
+
+    <span class="k">def</span> <span class="nf">_cluster_ready</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">state</span><span class="p">,</span> <span class="n">service</span><span class="p">):</span>
+        <span class="k">if</span> <span class="n">state</span> <span class="o">==</span> <span class="s1">&#39;RUNNING&#39;</span><span class="p">:</span>
+            <span class="k">return</span> <span class="kc">True</span>
+        <span class="k">if</span> <span class="n">state</span> <span class="o">==</span> <span class="s1">&#39;ERROR&#39;</span><span class="p">:</span>
+            <span class="n">cluster</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_cluster</span><span class="p">(</span><span class="n">service</span><span class="p">)</span>
+            <span class="k">try</span><span class="p">:</span>
+                <span class="n">error_details</span> <span class="o">=</span> <span class="n">cluster</span><span class="p">[</span><span class="s1">&#39;status&#39;</span><span class="p">][</span><span class="s1">&#39;details&#39;</span><span class="p">]</span>
+            <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
+                <span class="n">error_details</span> <span class="o">=</span> <span class="s1">&#39;Unknown error in cluster creation, &#39;</span> \
+                                <span class="s1">&#39;check Google Cloud console for details.&#39;</span>
+            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="n">error_details</span><span class="p">)</span>
+        <span class="k">return</span> <span class="kc">False</span>
+
+    <span class="k">def</span> <span class="nf">_wait_for_done</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service</span><span class="p">):</span>
+        <span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
+            <span class="n">state</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_cluster_state</span><span class="p">(</span><span class="n">service</span><span class="p">)</span>
+            <span class="k">if</span> <span class="n">state</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;No state for cluster &#39;</span><span class="si">%s</span><span class="s2">&#39;&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">cluster_name</span><span class="p">)</span>
+                <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">15</span><span class="p">)</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;State for cluster &#39;</span><span class="si">%s</span><span class="s2">&#39; is </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">cluster_name</span><span class="p">,</span> <span class="n">state</span><span class="p">)</span>
+                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cluster_ready</span><span class="p">(</span><span class="n">state</span><span class="p">,</span> <span class="n">service</span><span class="p">):</span>
+                    <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span>
+                        <span class="s2">&quot;Cluster &#39;</span><span class="si">%s</span><span class="s2">&#39; successfully created&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">cluster_name</span>
+                    <span class="p">)</span>
+                    <span class="k">return</span>
+                <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">15</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">_build_cluster_data</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="n">zone_uri</span> <span class="o">=</span> \
+            <span class="s1">&#39;https://www.googleapis.com/compute/v1/projects/</span><span class="si">{}</span><span class="s1">/zones/</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">project_id</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">zone</span>
+            <span class="p">)</span>
+        <span class="n">master_type_uri</span> <span class="o">=</span> \
+            <span class="s2">&quot;https://www.googleapis.com/compute/v1/projects/</span><span class="si">{}</span><span class="s2">/zones/</span><span class="si">{}</span><span class="s2">/machineTypes/</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">project_id</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">zone</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">master_machine_type</span>
+            <span class="p">)</span>
+        <span class="n">worker_type_uri</span> <span class="o">=</span> \
+            <span class="s2">&quot;https://www.googleapis.com/compute/v1/projects/</span><span class="si">{}</span><span class="s2">/zones/</span><span class="si">{}</span><span class="s2">/machineTypes/</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">project_id</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">zone</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">worker_machine_type</span>
+            <span class="p">)</span>
+        <span class="n">cluster_data</span> <span class="o">=</span> <span class="p">{</span>
+            <span class="s1">&#39;projectId&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">project_id</span><span class="p">,</span>
+            <span class="s1">&#39;clusterName&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">cluster_name</span><span class="p">,</span>
+            <span class="s1">&#39;config&#39;</span><span class="p">:</span> <span class="p">{</span>
+                <span class="s1">&#39;gceClusterConfig&#39;</span><span class="p">:</span> <span class="p">{</span>
+                    <span class="s1">&#39;zoneUri&#39;</span><span class="p">:</span> <span class="n">zone_uri</span>
+                <span class="p">},</span>
+                <span class="s1">&#39;masterConfig&#39;</span><span class="p">:</span> <span class="p">{</span>
+                    <span class="s1">&#39;numInstances&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
+                    <span class="s1">&#39;machineTypeUri&#39;</span><span class="p">:</span> <span class="n">master_type_uri</span><span class="p">,</span>
+                    <span class="s1">&#39;diskConfig&#39;</span><span class="p">:</span> <span class="p">{</span>
+                        <span class="s1">&#39;bootDiskSizeGb&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">master_disk_size</span>
+                    <span class="p">}</span>
+                <span class="p">},</span>
+                <span class="s1">&#39;workerConfig&#39;</span><span class="p">:</span> <span class="p">{</span>
+                    <span class="s1">&#39;numInstances&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">num_workers</span><span class="p">,</span>
+                    <span class="s1">&#39;machineTypeUri&#39;</span><span class="p">:</span> <span class="n">worker_type_uri</span><span class="p">,</span>
+                    <span class="s1">&#39;diskConfig&#39;</span><span class="p">:</span> <span class="p">{</span>
+                        <span class="s1">&#39;bootDiskSizeGb&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">worker_disk_size</span>
+                    <span class="p">}</span>
+                <span class="p">},</span>
+                <span class="s1">&#39;secondaryWorkerConfig&#39;</span><span class="p">:</span> <span class="p">{},</span>
+                <span class="s1">&#39;softwareConfig&#39;</span><span class="p">:</span> <span class="p">{}</span>
+            <span class="p">}</span>
+        <span class="p">}</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">num_preemptible_workers</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">cluster_data</span><span class="p">[</span><span class="s1">&#39;config&#39;</span><span class="p">][</span><span class="s1">&#39;secondaryWorkerConfig&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
+                <span class="s1">&#39;numInstances&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">num_preemptible_workers</span><span class="p">,</span>
+                <span class="s1">&#39;machineTypeUri&#39;</span><span class="p">:</span> <span class="n">worker_type_uri</span><span class="p">,</span>
+                <span class="s1">&#39;diskConfig&#39;</span><span class="p">:</span> <span class="p">{</span>
+                    <span class="s1">&#39;bootDiskSizeGb&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">worker_disk_size</span>
+                <span class="p">},</span>
+                <span class="s1">&#39;isPreemptible&#39;</span><span class="p">:</span> <span class="kc">True</span>
+            <span class="p">}</span>
+
+        <span class="n">cluster_data</span><span class="p">[</span><span class="s1">&#39;labels&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">labels</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">labels</span> <span class="k">else</span> <span class="p">{}</span>
+        <span class="c1"># Dataproc labels must conform to the following regex:</span>
+        <span class="c1"># [a-z]([-a-z0-9]*[a-z0-9])? (current airflow version string follows</span>
+        <span class="c1"># semantic versioning spec: x.y.z).</span>
+        <span class="n">cluster_data</span><span class="p">[</span><span class="s1">&#39;labels&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s1">&#39;airflow-version&#39;</span><span class="p">:</span>
+                                       <span class="s1">&#39;v&#39;</span> <span class="o">+</span> <span class="n">version</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">,</span> <span class="s1">&#39;-&#39;</span><span class="p">)})</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">storage_bucket</span><span class="p">:</span>
+            <span class="n">cluster_data</span><span class="p">[</span><span class="s1">&#39;config&#39;</span><span class="p">][</span><span class="s1">&#39;configBucket&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">storage_bucket</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">metadata</span><span class="p">:</span>
+            <span class="n">cluster_data</span><span class="p">[</span><span class="s1">&#39;config&#39;</span><span class="p">][</span><span class="s1">&#39;gceClusterConfig&#39;</span><span class="p">][</span><span class="s1">&#39;metadata&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">metadata</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">image_version</span><span class="p">:</span>
+            <span class="n">cluster_data</span><span class="p">[</span><span class="s1">&#39;config&#39;</span><span class="p">][</span><span class="s1">&#39;softwareConfig&#39;</span><span class="p">][</span><span class="s1">&#39;imageVersion&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">image_version</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">properties</span><span class="p">:</span>
+            <span class="n">cluster_data</span><span class="p">[</span><span class="s1">&#39;config&#39;</span><span class="p">][</span><span class="s1">&#39;softwareConfig&#39;</span><span class="p">][</span><span class="s1">&#39;properties&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">properties</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">init_actions_uris</span><span class="p">:</span>
+            <span class="n">init_actions_dict</span> <span class="o">=</span> <span class="p">[</span>
+                <span class="p">{</span><span class="s1">&#39;executableFile&#39;</span><span class="p">:</span> <span class="n">uri</span><span class="p">}</span> <span class="k">for</span> <span class="n">uri</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">init_actions_uris</span>
+            <span class="p">]</span>
+            <span class="n">cluster_data</span><span class="p">[</span><span class="s1">&#39;config&#39;</span><span class="p">][</span><span class="s1">&#39;initializationActions&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">init_actions_dict</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">service_account</span><span class="p">:</span>
+            <span class="n">cluster_data</span><span class="p">[</span><span class="s1">&#39;config&#39;</span><span class="p">][</span><span class="s1">&#39;gceClusterConfig&#39;</span><span class="p">][</span><span class="s1">&#39;serviceAccount&#39;</span><span class="p">]</span> <span class="o">=</span>\
+                    <span class="bp">self</span><span class="o">.</span><span class="n">service_account</span>
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">service_account_scopes</span><span class="p">:</span>
+            <span class="n">cluster_data</span><span class="p">[</span><span class="s1">&#39;config&#39;</span><span class="p">][</span><span class="s1">&#39;gceClusterConfig&#39;</span><span class="p">][</span><span class="s1">&#39;serviceAccountScopes&#39;</span><span class="p">]</span> <span class="o">=</span>\
+                    <span class="bp">self</span><span class="o">.</span><span class="n">service_account_scopes</span>
+        <span class="k">return</span> <span class="n">cluster_data</span>
+
+    <span class="k">def</span> <span class="nf">execute</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">context</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;Creating cluster: </span><span class="si">%s</span><span class="s1">&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">cluster_name</span><span class="p">)</span>
+        <span class="n">hook</span> <span class="o">=</span> <span class="n">DataProcHook</span><span class="p">(</span>
+            <span class="n">gcp_conn_id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">gcp_conn_id</span><span class="p">,</span>
+            <span class="n">delegate_to</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">delegate_to</span>
+        <span class="p">)</span>
+        <span class="n">service</span> <span class="o">=</span> <span class="n">hook</span><span class="o">.</span><span class="n">get_conn</span><span class="p">()</span>
+
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_cluster</span><span class="p">(</span><span class="n">service</span><span class="p">):</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span>
+                <span class="s1">&#39;Cluster </span><span class="si">%s</span><span class="s1"> already exists... Checking status...&#39;</span><span class="p">,</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">cluster_name</span>
+            <span class="p">)</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">_wait_for_done</span><span class="p">(</span><span class="n">service</span><span class="p">)</span>
+            <span class="k">return</span> <span class="kc">True</span>
+
+        <span class="n">cluster_data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_build_cluster_data</span><span class="p">()</span>
+        <span class="k">try</span><span class="p">:</span>
+            <span class="n">service</span><span class="o">.</span><span class="n">projects</span><span class="p">()</span><span class="o">.</span><span class="n">regions</span><span class="p">()</span><span class="o">.</span><span class="n">clusters</span><span class="p">()</span><span class="o">.</span><span class="n">create</span><span class="p">(</span>
+                <span class="n">projectId</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">project_id</span><span class="p">,</span>
+                <span class="n">region</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">region</span><span class="p">,</span>
+                <span class="n">body</span><span class="o">=</span><span class="n">cluster_data</span>
+            <span class="p">)</span><span class="o">.</span><span class="n">execute</span><span class="p">()</span>
+        <span class="k">except</span> <span class="n">HttpError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
+            <span class="c1"># probably two cluster start commands at the same time</span>
+            <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
+            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_cluster</span><span class="p">(</span><span class="n">service</span><span class="p">):</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span>
+                    <span class="s1">&#39;Cluster </span><span class="si">{}</span><span class="s1"> already exists... Checking status...&#39;</span><span class="p">,</span>
+                    <span class="bp">self</span><span class="o">.</span><span class="n">cluster_name</span>
+                 <span class="p">)</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">_wait_for_done</span><span class="p">(</span><span class="n">service</span><span class="p">)</span>
+                <span class="k">return</span> <span class="kc">True</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="k">raise</span> <span class="n">e</span>
+
+        <span class="bp">self</span><span class="o">.</span><span class="n">_wait_for_done</span><span class="p">(</span><span class="n">service</span><span class="p">)</span>
+
+
+<span class="k">class</span> <span class="nc">DataprocClusterDeleteOperator</span><span class="p">(</span><span class="n">BaseOperator</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Delete a cluster on Google Cloud Dataproc. The operator will wait until the</span>
+<span class="sd">    cluster is destroyed.</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="n">template_fields</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;cluster_name&#39;</span><span class="p">]</span>
+
+    <span class="nd">@apply_defaults</span>
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
+                 <span class="n">cluster_name</span><span class="p">,</span>
+                 <span class="n">project_id</span><span class="p">,</span>
+                 <span class="n">region</span><span class="o">=</span><span class="s1">&#39;global&#39;</span><span class="p">,</span>
+                 <span class="n">gcp_conn_id</span><span class="o">=</span><span class="s1">&#39;google_cloud_default&#39;</span><span class="p">,</span>
+                 <span class="n">delegate_to</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+                 <span class="o">*</span><span class="n">args</span><span class="p">,</span>
+                 <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Delete a cluster on Google Cloud Dataproc.</span>
+
+<span class="sd">        :param cluster_name: The name of the cluster to create.</span>
+<span class="sd">        :type cluster_name: string</span>
+<span class="sd">        :param project_id: The ID of the google cloud project in which</span>
+<span class="sd">            the cluster runs</span>
+<span class="sd">        :type project_id: string</span>
+<span class="sd">        :param region: leave as &#39;global&#39;, might become relevant in the future</span>
+<span class="sd">        :type region: string</span>
+<span class="sd">        :param gcp_conn_id: The connection ID to use connecting to Google Cloud Platform.</span>
+<span class="sd">        :type gcp_conn_id: string</span>
+<span class="sd">        :param delegate_to: The account to impersonate, if any.</span>
+<span class="sd">            For this to work, the service account making the request must have domain-wide</span>
+<span class="sd">            delegation enabled.</span>
+<span class="sd">        :type delegate_to: string</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="nb">super</span><span class="p">(</span><span class="n">DataprocClusterDeleteOperator</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">gcp_conn_id</span> <span class="o">=</span> <span class="n">gcp_conn_id</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">delegate_to</span> <span class="o">=</span> <span class="n">delegate_to</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">cluster_name</span> <span class="o">=</span> <span class="n">cluster_name</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">project_id</span> <span class="o">=</span> <span class="n">project_id</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">region</span> <span class="o">=</span> <span class="n">region</span>
+
+    <span class="k">def</span> <span class="nf">_wait_for_done</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">service</span><span class="p">,</span> <span class="n">operation_name</span><span class="p">):</span>
+        <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">15</span><span class="p">)</span>
+        <span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
+            <span class="n">response</span> <span class="o">=</span> <span class="n">service</span><span class="o">.</span><span class="n">projects</span><span class="p">()</span><span class="o">.</span><span class="n">regions</span><span class="p">()</span><span class="o">.</span><span class="n">operations</span><span class="p">()</span><span class="o">.</span><span class="n">get</span><span class="p">(</span>
+                <span class="n">name</span><span class="o">=</span><span class="n">operation_name</span>
+            <span class="p">)</span><span class="o">.</span><span class="n">execute</span><span class="p">()</span>
+
+            <span class="k">if</span> <span class="s1">&#39;done&#39;</span> <span class="ow">in</span> <span class="n">response</span> <span class="ow">and</span> <span class="n">response</span><span class="p">[</span><span class="s1">&#39;done&#39;</span><span class="p">]:</span>
+                <span class="k">if</span> <span class="s1">&#39;error&#39;</span> <span class="ow">in</span> <span class="n">response</span><span class="p">:</span>
+                    <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">response</span><span class="p">[</span><span class="s1">&#39;error&#39;</span><span class="p">]))</span>
+                <span class="k">else</span><span class="p">:</span>
+                    <span class="k">return</span>
+            <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">15</span><span class="p">)</span>
+
+    <span class="k">def</span> <span class="nf">execute</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">context</span><span class="p">):</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;Deleting cluster: </span><span class="si">%s</span><span class="s1">&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">cluster_name</span><span class="p">)</span>
+        <span class="n">hook</span> <span class="o">=</span> <span class="n">DataProcHook</span><span class="p">(</span>
+            <span class="n">gcp_conn_id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">gcp_conn_id</span><span class="p">,</span>
+            <span class="n">delegate_to</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">delegate_to</span>
+        <span class="p">)</span>
+        <span class="n">service</span> <span class="o">=</span> <span class="n">hook</span><span class="o">.</span><span class="n">get_conn</span><span class="p">()</span>
+
+        <span class="n">response</span> <span class="o">=</span> <span class="n">service</span><span class="o">.</span><span class="n">projects</span><span class="p">()</span><span class="o">.</span><span class="n">regions</span><span class="p">()</span><span class="o">.</span><span class="n">clusters</span><span class="p">()</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span>
+            <span class="n">projectId</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">project_id</span><span class="p">,</span>
+            <span class="n">region</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">region</span><span class="p">,</span>
+            <span class="n">clusterName</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">cluster_name</span>
+        <span class="p">)</span><span class="o">.</span><span class="n">execute</span><span class="p">()</span>
+        <span class="n">operation_name</span> <span class="o">=</span> <span class="n">response</span><span class="p">[</span><span class="s1">&#39;name&#39;</span><span class="p">]</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Cluster delete operation name: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">operation_name</span><span class="p">)</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">_wait_for_done</span><span class="p">(</span><span class="n">service</span><span class="p">,</span> <span class="n">operation_name</span><span class="p">)</span>
+
+
+<div class="viewcode-block" id="DataProcPigOperator"><a class="viewcode-back" href="../../../../integration.html#airflow.contrib.operators.dataproc_operator.DataProcPigOperator">[docs]</a><span class="k">class</span> <span class="nc">DataProcPigOperator</span><span class="p">(</span><span class="n">BaseOperator</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Start a Pig query Job on a Cloud DataProc cluster. The parameters of the operation</span>
+<span class="sd">    will be passed to the cluster.</span>
+
+<span class="sd">    It&#39;s a good practice to define dataproc_* parameters in the default_args of the dag</span>
+<span class="sd">    like the cluster name and UDFs.</span>
+
+<span class="sd">    ```</span>
+<span class="sd">    default_args = {</span>
+<span class="sd">        &#39;cluster_name&#39;: &#39;cluster-1&#39;,</span>
+<span class="sd">        &#39;dataproc_pig_jars&#39;: [</span>
+<span class="sd">            &#39;gs://example/udf/jar/datafu/1.2.0/datafu.jar&#39;,</span>
+<span class="sd">            &#39;gs://example/udf/jar/gpig/1.2/gpig.jar&#39;</span>
+<span class="sd">        ]</span>
+<span class="sd">    }</span>
+<span class="sd">    ```</span>
+
+<span class="sd">    You can pass a pig script as string or file reference. Use variables to pass on</span>
+<span class="sd">    variables for the pig script to be resolved on the cluster or use the parameters to</span>
+<span class="sd">    be resolved in the script as template parameters.</span>
+
+<span class="sd">    ```</span>
+<span class="sd">    t1 = DataProcPigOperator(</span>
+<span class="sd">        task_id=&#39;dataproc_pig&#39;,</span>
+<span class="sd">        query=&#39;a_pig_script.pig&#39;,</span>
+<span class="sd">        variables={&#39;out&#39;: &#39;gs://example/output/{{ds}}&#39;},</span>
+<span class="sd">    dag=dag)</span>
+<span class="sd">    ```</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="n">template_fields</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;query&#39;</span><span class="p">,</span> <span class="s1">&#39;variables&#39;</span><span class="p">,</span> <span class="s1">&#39;job_name&#39;</span><span class="p">,</span> <span class="s1">&#39;cluster_name&#39;</span><span class="p">]</span>
+    <span class="n">template_ext</span> <span class="o">=</span> <span class="p">(</span><span class="s1">&#39;.pg&#39;</span><span class="p">,</span> <span class="s1">&#39;.pig&#39;</span><span class="p">,)</span>
+    <span class="n">ui_color</span> <span class="o">=</span> <span class="s1">&#39;#0273d4&#39;</span>
+
+    <span class="nd">@apply_defaults</span>
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span>
+            <span class="bp">self</span><span class="p">,</span>
+            <span class="n">query</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+            <span class="n">query_uri</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+            <span class="n">variables</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+            <span class="n">job_name</span><span class="o">=</span><span class="s1">&#39;{{task.task_id}}_{{ds_nodash}}&#39;</span><span class="p">,</span>
+            <span class="n">cluster_name</span><span class="o">=</span><span class="s1">&#39;cluster-1&#39;</span><span class="p">,</span>
+            <span class="n">dataproc_pig_properties</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+            <span class="n">dataproc_pig_jars</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+            <span class="n">gcp_conn_id</span><span class="o">=</span><span class="s1">&#39;google_cloud_default&#39;</span><span class="p">,</span>
+            <span class="n">delegate_to</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+            <span class="o">*</span><span class="n">args</span><span class="p">,</span>
+            <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Create a new DataProcPigOperator.</span>
+
+<span class="sd">        For more detail on about job submission have a look at the reference:</span>
+
+<span class="sd">        https://cloud.google.com/dataproc/reference/rest/v1/projects.regions.jobs</span>
+
+<span class="sd">        :param query: The query or reference to the query file (pg or pig extension).</span>
+<span class="sd">        :type query: string</span>
+<span class="sd">        :param query_uri: The uri of a pig script on Cloud Storage.</span>
+<span class="sd">        :type query_uri: string</span>
+<span class="sd">        :param variables: Map of named parameters for the query.</span>
+<span class="sd">        :type variables: dict</span>
+<span class="sd">        :param job_name: The job name used in the DataProc cluster. This name by default</span>
+<span class="sd">            is the task_id appended with the execution data, but can be templated. The</span>
+<span class="sd">            name will always be appended with a random number to avoid name clashes.</span>
+<span class="sd">        :type job_name: string</span>
+<span class="sd">        :param cluster_name: The name of the DataProc cluster.</span>
+<span class="sd">        :type cluster_name: string</span>
+<span class="sd">        :param dataproc_pig_properties: Map for the Pig properties. Ideal to put in</span>
+<span class="sd">            default arguments</span>
+<span class="sd">        :type dataproc_pig_properties: dict</span>
+<span class="sd">        :param dataproc_pig_jars: URIs to jars provisioned in Cloud Storage (example: for</span>
+<span class="sd">            UDFs and libs) and are ideal to put in default arguments.</span>
+<span class="sd">        :type dataproc_pig_jars: list</span>
+<span class="sd">        :param gcp_conn_id: The connection ID to use connecting to Google Cloud Platform.</span>
+<span class="sd">        :type gcp_conn_id: string</span>
+<span class="sd">        :param delegate_to: The account to impersonate, if any.</span>
+<span class="sd">            For this to work, the service account making the request must have domain-wide</span>
+<span class="sd">            delegation enabled.</span>
+<span class="sd">        :type delegate_to: string</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="nb">super</span><span class="p">(</span><span class="n">DataProcPigOperator</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">gcp_conn_id</span> <span class="o">=</span> <span class="n">gcp_conn_id</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">delegate_to</span> <span class="o">=</span> <span class="n">delegate_to</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">query</span> <span class="o">=</span> <span class="n">query</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">query_uri</span> <span class="o">=</span> <span class="n">query_uri</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">variables</span> <span class="o">=</span> <span class="n">variables</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">job_name</span> <span class="o">=</span> <span class="n">job_name</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">cluster_name</span> <span class="o">=</span> <span class="n">cluster_name</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">dataproc_properties</span> <span class="o">=</span> <span class="n">dataproc_pig_properties</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">dataproc_jars</span> <span class="o">=</span> <span class="n">dataproc_pig_jars</span>
+
+    <span class="k">def</span> <span class="nf">execute</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">context</span><span class="p">):</span>
+        <span class="n">hook</span> <span class="o">=</span> <span class="n">DataProcHook</span><span class="p">(</span><span class="n">gcp_conn_id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">gcp_conn_id</span><span class="p">,</span>
+                            <span class="n">delegate_to</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">delegate_to</span><span class="p">)</span>
+        <span class="n">job</span> <span class="o">=</span> <span class="n">hook</span><span class="o">.</span><span class="n">create_job_template</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">task_id</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">cluster_name</span><span class="p">,</span> <span class="s2">&quot;pigJob&quot;</span><span class="p">,</span>
+                                       <span class="bp">self</span><span class="o">.</span><span class="n">dataproc_properties</span><span class="p">)</span>
+
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">query</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
+            <span class="n">job</span><span class="o">.</span><span class="n">add_query_uri</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">query_uri</span><span class="p">)</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="n">job</span><span class="o">.</span><span class="n">add_query</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">query</span><span class="p">)</span>
+        <span class="n">job</span><span class="o">.</span><span class="n">add_variables</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">variables</span><span class="p">)</span>
+        <span class="n">job</span><span class="o">.</span><span class="n">add_jar_file_uris</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dataproc_jars</span><span class="p">)</span>
+        <span class="n">job</span><span class="o">.</span><span class="n">set_job_name</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">job_name</span><span class="p">)</span>
+
+        <span class="n">hook</span><span class="o">.</span><span class="n">submit</span><span class="p">(</span><span class="n">hook</span><span class="o">.</span><span class="n">project_id</span><span class="p">,</span> <span class="n">job</span><span class="o">.</span><span class="n">build</span><span class="p">())</span></div>
+
+
+<div class="viewcode-block" id="DataProcHiveOperator"><a class="viewcode-back" href="../../../../integration.html#airflow.contrib.operators.dataproc_operator.DataProcHiveOperator">[docs]</a><span class="k">class</span> <span class="nc">DataProcHiveOperator</span><span class="p">(</span><span class="n">BaseOperator</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Start a Hive query Job on a Cloud DataProc cluster.</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="n">template_fields</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;query&#39;</span><span class="p">,</span> <span class="s1">&#39;variables&#39;</span><span class="p">,</span> <span class="s1">&#39;job_name&#39;</span><span class="p">,</span> <span class="s1">&#39;cluster_name&#39;</span><span class="p">]</span>
+    <span class="n">template_ext</span> <span class="o">=</span> <span class="p">(</span><span class="s1">&#39;.q&#39;</span><span class="p">,)</span>
+    <span class="n">ui_color</span> <span class="o">=</span> <span class="s1">&#39;#0273d4&#39;</span>
+
+    <span class="nd">@apply_defaults</span>
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span>
+            <span class="bp">self</span><span class="p">,</span>
+            <span class="n">query</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+            <span class="n">query_uri</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+            <span class="n">variables</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+            <span class="n">job_name</span><span class="o">=</span><span class="s1">&#39;{{task.task_id}}_{{ds_nodash}}&#39;</span><span class="p">,</span>
+            <span class="n">cluster_name</span><span class="o">=</span><span class="s1">&#39;cluster-1&#39;</span><span class="p">,</span>
+            <span class="n">dataproc_hive_properties</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+            <span class="n">dataproc_hive_jars</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+            <span class="n">gcp_conn_id</span><span class="o">=</span><span class="s1">&#39;google_cloud_default&#39;</span><span class="p">,</span>
+            <span class="n">delegate_to</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+            <span class="o">*</span><span class="n">args</span><span class="p">,</span>
+            <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Create a new DataProcHiveOperator.</span>
+
+<span class="sd">        :param query: The query or reference to the query file (q extension).</span>
+<span class="sd">        :type query: string</span>
+<span class="sd">        :param query_uri: The uri of a hive script on Cloud Storage.</span>
+<span class="sd">        :type query_uri: string</span>
+<span class="sd">        :param variables: Map of named parameters for the query.</span>
+<span class="sd">        :type variables: dict</span>
+<span class="sd">        :param job_name: The job name used in the DataProc cluster. This name by default</span>
+<span class="sd">            is the task_id appended with the execution data, but can be templated. The</span>
+<span class="sd">            name will always be appended with a random number to avoid name clashes.</span>
+<span class="sd">        :type job_name: string</span>
+<span class="sd">        :param cluster_name: The name of the DataProc cluster.</span>
+<span class="sd">        :type cluster_name: string</span>
+<span class="sd">        :param dataproc_hive_properties: Map for the Pig properties. Ideal to put in</span>
+<span class="sd">            default arguments</span>
+<span class="sd">        :type dataproc_hive_properties: dict</span>
+<span class="sd">        :param dataproc_hive_jars: URIs to jars provisioned in Cloud Storage (example: for</span>
+<span class="sd">            UDFs and libs) and are ideal to put in default arguments.</span>
+<span class="sd">        :type dataproc_hive_jars: list</span>
+<span class="sd">        :param gcp_conn_id: The connection ID to use connecting to Google Cloud Platform.</span>
+<span class="sd">        :type gcp_conn_id: string</span>
+<span class="sd">        :param delegate_to: The account to impersonate, if any.</span>
+<span class="sd">            For this to work, the service account making the request must have domain-wide</span>
+<span class="sd">            delegation enabled.</span>
+<span class="sd">        :type delegate_to: string</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="nb">super</span><span class="p">(</span><span class="n">DataProcHiveOperator</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">gcp_conn_id</span> <span class="o">=</span> <span class="n">gcp_conn_id</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">delegate_to</span> <span class="o">=</span> <span class="n">delegate_to</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">query</span> <span class="o">=</span> <span class="n">query</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">query_uri</span> <span class="o">=</span> <span class="n">query_uri</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">variables</span> <span class="o">=</span> <span class="n">variables</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">job_name</span> <span class="o">=</span> <span class="n">job_name</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">cluster_name</span> <span class="o">=</span> <span class="n">cluster_name</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">dataproc_properties</span> <span class="o">=</span> <span class="n">dataproc_hive_properties</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">dataproc_jars</span> <span class="o">=</span> <span class="n">dataproc_hive_jars</span>
+
+    <span class="k">def</span> <span class="nf">execute</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">context</span><span class="p">):</span>
+        <span class="n">hook</span> <span class="o">=</span> <span class="n">DataProcHook</span><span class="p">(</span><span class="n">gcp_conn_id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">gcp_conn_id</span><span class="p">,</span>
+                            <span class="n">delegate_to</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">delegate_to</span><span class="p">)</span>
+
+        <span class="n">job</span> <span class="o">=</span> <span class="n">hook</span><span class="o">.</span><span class="n">create_job_template</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">task_id</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">cluster_name</span><span class="p">,</span> <span class="s2">&quot;hiveJob&quot;</span><span class="p">,</span>
+                                       <span class="bp">self</span><span class="o">.</span><span class="n">dataproc_properties</span><span class="p">)</span>
+
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">query</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
+            <span class="n">job</span><span class="o">.</span><span class="n">add_query_uri</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">query_uri</span><span class="p">)</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="n">job</span><span class="o">.</span><span class="n">add_query</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">query</span><span class="p">)</span>
+        <span class="n">job</span><span class="o">.</span><span class="n">add_variables</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">variables</span><span class="p">)</span>
+        <span class="n">job</span><span class="o">.</span><span class="n">add_jar_file_uris</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dataproc_jars</span><span class="p">)</span>
+        <span class="n">job</span><span class="o">.</span><span class="n">set_job_name</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">job_name</span><span class="p">)</span>
+
+        <span class="n">hook</span><span class="o">.</span><span class="n">submit</span><span class="p">(</span><span class="n">hook</span><span class="o">.</span><span class="n">project_id</span><span class="p">,</span> <span class="n">job</span><span class="o">.</span><span class="n">build</span><span class="p">())</span></div>
+
+
+<div class="viewcode-block" id="DataProcSparkSqlOperator"><a class="viewcode-back" href="../../../../integration.html#airflow.contrib.operators.dataproc_operator.DataProcSparkSqlOperator">[docs]</a><span class="k">class</span> <span class="nc">DataProcSparkSqlOperator</span><span class="p">(</span><span class="n">BaseOperator</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Start a Spark SQL query Job on a Cloud DataProc cluster.</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="n">template_fields</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;query&#39;</span><span class="p">,</span> <span class="s1">&#39;variables&#39;</span><span class="p">,</span> <span class="s1">&#39;job_name&#39;</span><span class="p">,</span> <span class="s1">&#39;cluster_name&#39;</span><span class="p">]</span>
+    <span class="n">template_ext</span> <span class="o">=</span> <span class="p">(</span><span class="s1">&#39;.q&#39;</span><span class="p">,)</span>
+    <span class="n">ui_color</span> <span class="o">=</span> <span class="s1">&#39;#0273d4&#39;</span>
+
+    <span class="nd">@apply_defaults</span>
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span>
+            <span class="bp">self</span><span class="p">,</span>
+            <span class="n">query</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+            <span class="n">query_uri</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+            <span class="n">variables</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+            <span class="n">job_name</span><span class="o">=</span><span class="s1">&#39;{{task.task_id}}_{{ds_nodash}}&#39;</span><span class="p">,</span>
+            <span class="n">cluster_name</span><span class="o">=</span><span class="s1">&#39;cluster-1&#39;</span><span class="p">,</span>
+            <span class="n">dataproc_spark_properties</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+            <span class="n">dataproc_spark_jars</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+            <span class="n">gcp_conn_id</span><span class="o">=</span><span class="s1">&#39;google_cloud_default&#39;</span><span class="p">,</span>
+            <span class="n">delegate_to</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+            <span class="o">*</span><span class="n">args</span><span class="p">,</span>
+            <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Create a new DataProcSparkSqlOperator.</span>
+
+<span class="sd">        :param query: The query or reference to the query file (q extension).</span>
+<span class="sd">        :type query: string</span>
+<span class="sd">        :param query_uri: The uri of a spark sql script on Cloud Storage.</span>
+<span class="sd">        :type query_uri: string</span>
+<span class="sd">        :param variables: Map of named parameters for the query.</span>
+<span class="sd">        :type variables: dict</span>
+<span class="sd">        :param job_name: The job name used in the DataProc cluster. This name by default</span>
+<span class="sd">            is the task_id appended with the execution data, but can be templated. The</span>
+<span class="sd">            name will always be appended with a random number to avoid name clashes.</span>
+<span class="sd">        :type job_name: string</span>
+<span class="sd">        :param cluster_name: The name of the DataProc cluster.</span>
+<span class="sd">        :type cluster_name: string</span>
+<span class="sd">        :param dataproc_spark_properties: Map for the Pig properties. Ideal to put in</span>
+<span class="sd">            default arguments</span>
+<span class="sd">        :type dataproc_spark_properties: dict</span>
+<span class="sd">        :param dataproc_spark_jars: URIs to jars provisioned in Cloud Storage (example:</span>
+<span class="sd">            for UDFs and libs) and are ideal to put in default arguments.</span>
+<span class="sd">        :type dataproc_spark_jars: list</span>
+<span class="sd">        :param gcp_conn_id: The connection ID to use connecting to Google Cloud Platform.</span>
+<span class="sd">        :type gcp_conn_id: string</span>
+<span class="sd">        :param delegate_to: The account to impersonate, if any.</span>
+<span class="sd">            For this to work, the service account making the request must have domain-wide</span>
+<span class="sd">            delegation enabled.</span>
+<span class="sd">        :type delegate_to: string</span>
+<span class="sd">        &quot;&quot;&quot;</span>
+        <span class="nb">super</span><span class="p">(</span><span class="n">DataProcSparkSqlOperator</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">gcp_conn_id</span> <span class="o">=</span> <span class="n">gcp_conn_id</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">delegate_to</span> <span class="o">=</span> <span class="n">delegate_to</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">query</span> <span class="o">=</span> <span class="n">query</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">query_uri</span> <span class="o">=</span> <span class="n">query_uri</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">variables</span> <span class="o">=</span> <span class="n">variables</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">job_name</span> <span class="o">=</span> <span class="n">job_name</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">cluster_name</span> <span class="o">=</span> <span class="n">cluster_name</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">dataproc_properties</span> <span class="o">=</span> <span class="n">dataproc_spark_properties</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">dataproc_jars</span> <span class="o">=</span> <span class="n">dataproc_spark_jars</span>
+
+    <span class="k">def</span> <span class="nf">execute</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">context</span><span class="p">):</span>
+        <span class="n">hook</span> <span class="o">=</span> <span class="n">DataProcHook</span><span class="p">(</span><span class="n">gcp_conn_id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">gcp_conn_id</span><span class="p">,</span>
+                            <span class="n">delegate_to</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">delegate_to</span><span class="p">)</span>
+
+        <span class="n">job</span> <span class="o">=</span> <span class="n">hook</span><span class="o">.</span><span class="n">create_job_template</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">task_id</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">cluster_name</span><span class="p">,</span> <span class="s2">&quot;sparkSqlJob&quot;</span><span class="p">,</span>
+                                       <span class="bp">self</span><span class="o">.</span><span class="n">dataproc_properties</span><span class="p">)</span>
+
+        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">query</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
+            <span class="n">job</span><span class="o">.</span><span class="n">add_query_uri</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">query_uri</span><span class="p">)</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="n">job</span><span class="o">.</span><span class="n">add_query</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">query</span><span class="p">)</span>
+        <span class="n">job</span><span class="o">.</span><span class="n">add_variables</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">variables</span><span class="p">)</span>
+        <span class="n">job</span><span class="o">.</span><span class="n">add_jar_file_uris</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dataproc_jars</span><span class="p">)</span>
+        <span class="n">job</span><span class="o">.</span><span class="n">set_job_name</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">job_name</span><span class="p">)</span>
+
+        <span class="n">hook</span><span class="o">.</span><span class="n">submit</span><span class="p">(</span><span class="n">hook</span><span class="o">.</span><span class="n">project_id</span><span class="p">,</span> <span class="n">job</span><span class="o">.</span><span class="n">build</span><span class="p">())</span></div>
+
+
+<div class="viewcode-block" id="DataProcSparkOperator"><a class="viewcode-back" href="../../../../integration.html#airflow.contrib.operators.dataproc_operator.DataProcSparkOperator">[docs]</a><span class="k">class</span> <span class="nc">DataProcSparkOperator</span><span class="p">(</span><span class="n">BaseOperator</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Start a Spark Job on a Cloud DataProc cluster.</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+
+    <span class="n">template_fields</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;arguments&#39;</span><span class="p">,</span> <span class="s1">&#39;job_name&#39;</span><span class="p">,</span> <span class="s1">&#39;cluster_name&#39;</span><span class="p">]</span>
+    <span class="n">ui_color</span> <span class="o">=</span> <span class="s1">&#39;#0273d4&#39;</span>
+
+    <span class="nd">@apply_defaults</span>
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span>
+            <span class="bp">self</span><span class="p">,</span>
+            <span class="n">main_jar</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+            <span class="n">main_class</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+            <span class="n">arguments</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+            <span class="n">archives</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+            <span class="n">files</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+            <span class="n">job_name</span><span class="o">=</span><span class="s1">&#39;{{task.task_id}}_{{ds_nodash}}&#39;</span><span class="p">,</span>
+            <span class="n">cluster_name</span><span class="o">=</span><span class="s1">&#39;cluster-1&#39;</span><span class="p">,</span>
+            <span class="n">dataproc_spark_properties</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+            <span class="n">dataproc_spark_jars</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+            <span class="n">gcp_conn_id</span><span class="o">=</span><span class="s1">&#39;google_cloud_default&#39;</span><span class="p">,</span>
+            <span class="n">delegate_to</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+            <span class="o">*</span><span class="n">args</span><span class="p">,</span>
+            <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
+        <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">        Create a new DataProcSparkOperator.</span>
+
+<span class="sd">        :param main_jar: URI of the job jar provisioned on Cloud Storage. (use this or</span>
+<span class="sd">            the main_class, not both together).</span>
+<span class="sd">        :type main_jar: string</span>
+<span class="sd">        :param main_class: Name of the job class. (use this or the main_jar, not both</span>
+<span class="sd">            together).</span>
+<span class="sd">        :type main_class: string</span>
+<span class="sd">        :param arguments: Arguments for the job.</span>
+<span class="sd">        :type arguments: list</span>
+<span class="sd">        :param archives: List of archived files that will be unpacked in the work</span>
+<span class="sd">            directory. Should be stored in Cloud Storage.</span>
+<span class="sd">        :type archives: list</span>
+<span class="sd">        :param files: List of files to be copied to the working directory</span>
+<span class="sd">        :type files: list</span>
+<span class="sd">        :param job_name: The job name used in the DataProc cluster. This name by default</span>
+<span class="sd">            is the task_id appended with the execution data, but can be templated. The</span>
+<span class="sd">            name will always be appended with a random number to avoid name clashes.</span>
+<span class="sd">        :type job_name: string</span>
+<span class="sd">        :param cluster_name: The name of the DataProc cluster.</span>
+<span class="sd">        :type cluster_name: string</span>
+<span class="sd">        :param dataproc_spark_properties: Map for the Pig properties. Ideal to put in</span>
+<span class="sd">            default arguments</span>
+<span class="sd">        :type dataproc_spark_properties: dict</span>
+<span class="sd">        :param dataproc_spark_jars: URIs to jars provisioned in Cloud Storage (example:</span>
+<span class="sd">            for UDFs and libs) and are ideal to put in de

<TRUNCATED>


Mime
View raw message