【问题标题】:get latest schema for partitionned parquet dataframe获取分区镶木地板数据帧的最新模式
【发布时间】:2017-10-18 18:44:40
【问题描述】:

我们开始使用 spark 和 parquet 文件在 hadoop 集群中收集数据……但我们很难保证 parquet 模式在未来不会改变。我们试图找到读取镶木地板的最佳方式,即使架构发生变化...

我们要实现的规则是最新的 parquet 文件将作为我们的参考...

我们进行了不同的测试,包括:

spark.read.parquet("test").filter("year=2017 and month=10 and day>=15")
spark.read.parquet("test/year=2017/month=10/day=17", "test/year=2017/month=10/day=16", "test/year=2017/month=10/day=15")
// tested with different order
spark.read.parquet("test/year=2017/month=10/day={15,16,17}")

等等……

并且 read 方法保留的模式始终是最旧的模式(即 10 月 15 日的模式)。

有人知道如何获取最新的架构(即 10 月 17 日的架构)吗?

当然spark.read.option("mergeSchema", "true") 不起作用,因为如果我们在最新的镶木地板中删除一列,它不会删除一列。我们在这里进行了超过 3 天的测试......但它可能会覆盖非常大范围的分区。

提前致谢

问候

【问题讨论】:

    标签: apache-spark dataframe apache-spark-2.0


    【解决方案1】:

    我在 pyspark 中写这个。应该适用于其他语言。

    schema = spark.read.parquet("test/year=2017/month=10/day=17/").schema
    df = spark.read.schema(schema).parquet("test/*/*/*/")
    

    【讨论】:

    • 非常感谢您的提议...现在我们重建了我们所有的历史,但您的提议确实很有趣。
    猜你喜欢
    • 2018-12-28
    • 1970-01-01
    • 1970-01-01
    • 2018-11-10
    • 1970-01-01
    • 2020-09-18
    • 2019-03-27
    • 2017-05-24
    • 2021-03-30
    相关资源
    最近更新 更多