循环使用相同架构的s3拼花文件路径序列,并保存在scala中的单个数据框中

问题描述

给出了s3序列所需的内容。任何两个位置的区别是表的分区列值。

每个实木复合地板文件夹都具有相同的架构。

因此,我们需要以相同的模式循环s3实木复合地板文件路径的序列,并一起保存在scala中的单个数据框中。

解决方法

如果您有一个要导入的所有目录的数组,则可以遍历该数组并收集一组数据帧,然后将它们合并为一个。

尝试这样的事情。

//You have now a collection of dataframes
val dataframes = directories.map(dir =>
      spark.read.parquet(dir))

//Let's union them into one
val df_union = dataframes.reduce(_ union _)
,

如果打开这些选项,则只需递归加载文件即可。

spark.read.parquet("s3a://path/to/root/")

选项如下。

spark.hive.mapred.supports.subdirectories    true
spark.hadoop.mapreduce.input.fileinputformat.input.dir.recursive    true

可以通过以下方式使用

import org.apache.spark.{SparkContext,SparkConf}
import org.apache.spark.sql.SparkSession

val conf = new SparkConf()
    .setMaster("local[2]")
    .setAppName("test")
    .set("spark.hive.mapred.supports.subdirectories","true")
    .set("spark.hadoop.mapreduce.input.fileinputformat.input.dir.recursive","true")

val spark = SparkSession.builder.config(conf).getOrCreate()

val df = spark.read.parquet("s3a://path/to/root/")

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...