Spark Scala -读取不同模式的parquet文件,写入不同的输出路径



我有一个父文件夹和子文件夹,每个子文件夹包含一个parquet文件(代表一个表),如下所示:

|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中实现这个吗?

这样做的方法是将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")

祝你好运!

最新更新