获取分区镶木地板数据框的最新模式

get latest schema for partitionned parquet dataframe

我们开始使用 spark 和 parquet 文件在 hadoop 集群中收集数据...但是我们很难保证 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}")

等...

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

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

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

提前致谢

此致

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

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