scala - 在火花中连接蜂巢模拟
问题描述
我有一个 spark 作业,它在 Hive 中创建一个结果表并从其他表加载数据。这项工作每天都在执行,并在 HDFS 上生成大量文件。当我使用 Hive 时,我制作了一个脚本:alter table quality_of_service_1 concatenate;
implicit val spark: SparkSession = SparkSession
.builder()
.enableHiveSupport()
.appName("Test")
.getOrCreate()
def build(implicit session: SparkSession, config: Config): Unit = {
import session.implicits._
loadData
.flatMap(Item.buildInternal(_, config))
.write
.mode(SaveMode.Overwrite)
.format("orc")
.saveAsTable(s"${config.schema}.result_table")
}
你能写下如何合并这些文件以及它在哪里调整吗?带有 HDFS、spark 或 spark 会话配置的 Shell 脚本。
配置:
--deploy-mode cluster \
--conf spark.rpc.message.maxSize=300 \
--conf spark.rdd.compress=true \
--conf spark.default.parallelism=1009 \
--conf spark.sql.shuffle.partitions=1009 \
--conf spark.sql.autoBroadcastJoinThreshold=31457280 \
--conf spark.dynamicAllocation.enabled=true \
--conf spark.shuffle.service.enabled=true \
--conf spark.dynamicAllocation.initialExecutors=1200 \
--conf spark.dynamicAllocation.minExecutors=400 \
--conf spark.dynamicAllocation.maxExecutors=1200 \
--conf spark.sql.files.maxPartitionBytes=1073741824 \
--executor-cores 3 \
--executor-memory 7g \
--driver-memory 4g \
解决方案
在 spark2 中,一个参数控制一个分区的大小......因此当你“保存”时文件的数量。所以增加参数以减少分区和减少文件例如,每个分区 1 GB
val maxSplit=1024*1024*1024
spark.conf.set("spark.sql.files.maxPartitionBytes", maxSplit)
推荐阅读
- python - 如何在 PIL 中围绕中心剪切图像?
- php - Woocommerce单品页面背景如何显示产品图库图片
- python-3.x - 如何通过将另一个矩阵的第一列用作新矩阵的第一行来从另一个矩阵创建一个新矩阵?
- azure - 为具有身份验证的应用服务部署 ARM 模板时自动创建应用服务标识
- java - ArrayAdapter() 构造函数中的第二个参数是什么?
- java - Google 登录 Firebase 身份验证,显示“选择帐户”
- haskell - Haskell 图中文本的自定义字体
- docker - Kubernetes pod 部署失败;docker 图像丢失/放错文件?
- c# - 保存/检索时是否需要对 RichEditBox 文本进行编码/解码?(UWP)
- python - Tensorflow 数据集 API - .from_tensor_slices() / .from_tensor() - 无法创建内容大于 2gb 的张量原型