首页 > 解决方案 > 在火花中连接蜂巢模拟

问题描述

我有一个 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 \

标签: scalaapache-sparkhive

解决方案


在 spark2 中,一个参数控制一个分区的大小......因此当你“保存”时文件的数量。所以增加参数以减少分区和减少文件例如,每个分区 1 GB val maxSplit=1024*1024*1024 spark.conf.set("spark.sql.files.maxPartitionBytes", maxSplit)


推荐阅读