【问题标题】:How to read partitioned parquets with same structure but different column names?如何读取具有相同结构但不同列名的分区镶木地板?
【发布时间】:2018-03-21 16:28:05
【问题描述】:

我有按创建日期 (BusinessDate) 和数据源 (SourceSystem) 分区的镶木地板文件。一些源系统使用不同的列名生成它们的数据(小写,如大写,即orderdate vs OrderDate),但总体数据结构相同(文件之间的列顺序和数据类型始终相同)。

我的文件系统中的数据如下所示:

dataroot
|-BusinessDate=20170809
  |-SourceSystem=StoreA
    |-data.parquet (has column "orderdate")
  |-SourceSystem=StoreB
    |-data.parquet (has column "OrderDate")

有没有办法从datarootdataroot/BusinessData=######/ 读取数据,并以某种方式将数据规范化为统一架构?

我的第一次尝试是尝试:

val inputDF = spark.read.parquet(samplePqt)
standardNames = Seq(...) //list of uniform column names in order
val uniformDF = inputDF.toDF(standardNames: _*)

但这不起作用(将重命名源系统之间具有相同列名的列,但将为来自源系统 B 的具有不同列名的记录填充 null)。

【问题讨论】:

    标签: scala apache-spark apache-spark-sql parquet


    【解决方案1】:

    我从来没有找到一次性处理所有数据的方法,我的解决方案遍历不同的源系统,创建指向每个源系统的文件路径,并单独处理它们。随着它们被单独处理,它们被转换为标准模式并与其他结果结合。

    val inputDF = spark.read.parquet(dataroot) //dataroot contains business date
    val sourceList = inputDF.select(inputDF("source_system")).distinct.collect.map(_(0)).toList //list of source systems for businessdate
    sourceList.foreach(println(_))
    for (ss <- sourceList){//process data}
    

    【讨论】:

      猜你喜欢
      • 2023-03-19
      • 1970-01-01
      • 2020-09-06
      • 2021-05-27
      • 2020-01-06
      • 2019-09-30
      • 2019-02-24
      • 2018-06-06
      • 2017-06-27
      相关资源
      最近更新 更多