我对这个话题做了很多研究。我有一个 3 TB 大小的数据集。 以下是该表的数据架构:
root
|-- user: string (nullable = true)
|-- attributes: array (nullable = true)
| |-- element: string (containsNull = true)
每天,我都会得到一份我需要其属性的用户列表。我想知道我是否可以将上述模式写入包含前 2 个用户字母的 Parquet 文件。例如,
Omkar | [a,b,c,d,e]
Mac | [a,b,c,d,e]
Zee | [a,b,c,d,e]
Kim | [a,b,c,d,e]
Kelly | [a,b,c,d,e]
在上面的数据集上,我可以做这样的事情吗:
spark.write.mode("overwrite").partitionBy("user".substr(0,2)).parquet("path/to/location")
这样做,我觉得下次加入用户时加载到内存中的数据会非常少,因为我们只能命中那些分区。
如果有人这样实现,有什么意见吗?
谢谢!!
最佳答案
可以。只需将您的代码替换为:
df
.withColumn("prefix", $"user".substr(0,2)) // Add prefix column
.write.mode("overwrite")
.partitionBy("prefix") // Use it for partitioning
.parquet("path/to/location")
关于apache-spark - Spark 根据字母分区写入 Parquet ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50395139/