【问题标题】:How to pass multiple column in partitionby method in Spark如何在 Spark 中的 partitionby 方法中传递多列
【发布时间】:2023-04-07 18:50:01
【问题描述】:

我是 Spark 的新手。我想将数据帧数据写入 hive 表。 Hive 表在多列上分区。通过 Hivemetastore 客户端,我获取了分区列,并将其作为数据帧写入方法的 partitionby 子句中的变量传递。

var1="country","state" (Getting the partiton column names of hive table)
dataframe1.write.partitionBy(s"$var1").mode("overwrite").save(s"$hive_warehouse/$dbname.db/$temp_table/")

当我执行上面的代码时,它给了我错误partiton "country","state" does not exist。 我认为它将“国家”、“州”作为字符串。

你能帮帮我吗?

【问题讨论】:

    标签: apache-spark apache-spark-sql hive-metastore


    【解决方案1】:

    partitionBy 函数采用 varargs 而不是列表。您可以将其用作

    dataframe1.write.partitionBy("country","state").mode("overwrite").save(s"$hive_warehouse/$dbname.db/$temp_table/")
    

    或者在 scala 中,您可以将列表转换为可变参数,例如

    val columns = Seq("country","state")
    dataframe1.write.partitionBy(columns:_*).mode("overwrite").save(s"$hive_warehouse/$dbname.db/$temp_table/")
    

    【讨论】:

    • 这对scala中的bucketby有用吗?我试过没有用
    猜你喜欢
    • 1970-01-01
    • 2020-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-17
    • 2015-12-30
    • 2017-08-01
    • 2018-06-29
    相关资源
    最近更新 更多