Spark-SQL任务提交方式

Spark-SQL在一定程度上可以代替Hive,但一般依赖Hive的元数据,即Metastore。Spark-SQL的交互式模式可以运行bin/spark-sql进入,按照类似hive方式写SQL代码。

Spark 通过 Thrift RPC 向 Hive Metastore Service(HMS) 发请求,HMS 再去访问 MySQL 里的元数据,这种方式可以让Hive、Spark、Presto、Impala 等多种引擎共享同一套元数据,此时需要启动Hive元数据服务HMS:

shell 复制代码
hive --service metastore

使用Hive元数据时,需要将hive的配置文件hive-site.xml放到$SPARK_HOME/conf目录下或者提交作业时用--files参数指定该配置文件。配置文件内容如下:

xml 复制代码
<property>
  <name>hive.metastore.uris</name>
  <value>thrift://metastore-host:9083</value>
</property>

Spark SQL脚本任务使用spark-sql提交任务时,和Spark传统任务类似,可使用本地、Standalone、Yarn和K8S资源调度平台。提交方式如下:

shell 复制代码
# 任务提交方式:交互模式
spark-sql # 进入 Spark SQL CLI,可以直接写 SQL 语句交互式运行,本地模式
spark-sql --master local[*] # 同上
spark-sql --master yarn --deploy-mode cluster # 提交的语句在YARN集群执行
spark-sql --master k8s://https://<k8s-apiserver>:6443 \
  --conf spark.kubernetes.container.image=my-spark-image:latest \
  --deploy-mode cluster # Driver和Executor都在K8S的Pod中,client时Driver在本地

# 任务提交:指定脚本文件
spark-sql -f my.sql --conf spark.executor.memory=4g --conf spark.executor.cores=2
spark-sql --master local[*] -f my.sql # 本地模式提交脚本任务
# Standalone模式,master参数为Spark Master的RPC地址,资源分配由Master控制
spark-sql --master spark://<master>:7077 --deploy-mode client -f my.sql
# Yarn模式,client为Driver在提交节点上运行,日志直接可见,cluster为Driver在Yarn Container中运行
spark-sql --master yarn --deploy-mode cluster \
  --executor-memory 4g \
  --executor-cores 2 \
  --num-executors 20 \
  -f my.sql
相关推荐
ha_lydms1 小时前
Table Functions(表函数)
大数据·hadoop·阿里云·spark·数据处理·dataworks·maxcompute
roman_日积跬步-终至千里2 小时前
【数据Agent论文·查询与语义|11】EntSQL:给了业务文档,模型为何还是写不对SQL?
数据库·人工智能·sql·数据分析
ha_lydms4 小时前
Json Functions(JSON 函数)
大数据·hadoop·spark·json·数据处理·dataworks·maxcompute
l1t4 小时前
修改两处,让SQLite求解数独SQL在datafusion上运行
服务器·数据库·sql
ha_lydms4 小时前
Conditional Functions(条件函数)
大数据·hadoop·阿里云·spark·数据处理·dataworks·maxcompute
roman_日积跬步-终至千里5 小时前
【数据Agent论文·查询与语义|09】Spider 2.0:从生成SQL走向完成企业工作流
数据库·sql·数据分析
曦夜日长5 小时前
MySQL系统篇,数据库基础(二):数据库概念、SQL 分类与存储引擎
数据库·sql·mysql
泡海椒5 小时前
JQuick-SQL AST 解析:从 SQL 文本到强类型节点
数据库·sql
泡海椒6 小时前
JQuick-SQL 模块架构:从 SQL AST 到分布式执行
分布式·sql·架构
l1t6 小时前
duckdb、clickhouse、datafusion、cedardb、tableauhyperapi 5种分析型数据库执行递归求数独SQL比较
数据库·sql·clickhouse