如何在Spark中的partitionby方法中传递多列

How to pass multiple column in partitionby method in Spark

我是Spark.I的新手,想将dataframe数据写入hivetable。 Hive table 在多个列上分区。通过 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/")

当我执行上面的代码时,它给我错误分区 "country","state" 不存在。 我认为它将 "country","state" 作为字符串。

你能帮帮我吗?

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/")