Source code for airflow.providers.apache.spark.operators.spark_sql
## Licensed to the Apache Software Foundation (ASF) under one# or more contributor license agreements. See the NOTICE file# distributed with this work for additional information# regarding copyright ownership. The ASF licenses this file# to you under the Apache License, Version 2.0 (the# "License"); you may not use this file except in compliance# with the License. You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing,# software distributed under the License is distributed on an# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY# KIND, either express or implied. See the License for the# specific language governing permissions and limitations# under the License.from__future__importannotationsfromcollections.abcimportSequencefromtypingimportTYPE_CHECKING,Anyfromairflow.modelsimportBaseOperatorfromairflow.providers.apache.spark.hooks.spark_sqlimportSparkSqlHookifTYPE_CHECKING:fromairflow.utils.contextimportContext
[docs]classSparkSqlOperator(BaseOperator):""" Execute Spark SQL query. .. seealso:: For more information on how to use this operator, take a look at the guide: :ref:`howto/operator:SparkSqlOperator` :param sql: The SQL query to execute. (templated) :param conf: arbitrary Spark configuration property :param conn_id: connection_id string :param total_executor_cores: (Standalone & Mesos only) Total cores for all executors (Default: all the available cores on the worker) :param executor_cores: (Standalone & YARN only) Number of cores per executor (Default: 2) :param executor_memory: Memory per executor (e.g. 1000M, 2G) (Default: 1G) :param keytab: Full path to the file that contains the keytab :param master: spark://host:port, mesos://host:port, yarn, or local (Default: The ``host`` and ``port`` set in the Connection, or ``"yarn"``) :param name: Name of the job :param num_executors: Number of executors to launch :param verbose: Whether to pass the verbose flag to spark-sql :param yarn_queue: The YARN queue to submit to (Default: The ``queue`` value set in the Connection, or ``"default"``) """
[docs]defexecute(self,context:Context)->None:"""Call the SparkSqlHook to run the provided sql query."""ifself._hookisNone:self._hook=self._get_hook()self._hook.run_query()