【问题标题】:Spark Scala - Read different parquet files with different schema and write to different output pathsSpark Scala - 读取具有不同模式的不同镶木地板文件并写入不同的输出路径
【发布时间】:2022-12-01 08:15:38
【问题描述】:

我有一个带有子文件夹的父文件夹,每个子文件夹都包含一个镶木地板文件(代表一个表格),如下所示:

|Parent_input_folder:
|--- Children_folder1:
|      |--- file1.parquet
|--- Children_folder2 :
       |--- file2.parquet

目标是在使用 spark scala 转换后从这些文件夹中读取并写入输出文件夹:

|Parent_output_folder:
|--- Children_folder1:
|      |--- file1.parquet
|--- Children_folder2 :
       |--- file2.parquet

注意:每个文件都有不同的架构

你有什么想法在 spark scala 中做到这一点吗?

【问题讨论】:

  • 您想应用哪些转换?如果您不知道模式,您如何应用转换?

标签: scala apache-spark


【解决方案1】:

一种可以让您几乎得到您想要的东西的方法是 input_file_pathpartitionBy 的组合,如下所示:

val results = table
  .withColumn("path", input_file_name())
  .withColumn("path", concat_ws("\", slice(split(col("path"), "/"), 8, 2))) // get the path in the format that you want

results
  .write
  .partitionBy("path") // partition by your path column
  .parquet("structured")

祝你好运!

【讨论】:

    猜你喜欢
    • 2019-02-24
    • 2020-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-27
    • 2020-09-09
    • 2019-01-20
    • 2018-06-28
    相关资源
    最近更新 更多