pyspark - 使用 pySpark 将部分文件从 hdfs 读入数据帧
问题描述
我有多个文件存储在 hdfs 位置,如下所示
/user/project/202005/part-01798
/user/project/202005/part-01799
有 2000 个这样的零件文件。每个文件的格式
{'Name':'abc','Age':28,'Marks':[20,25,30]}
{'Name':...}
等等 。我有 2 个问题
1) How to check whether these are multiple files or multiple partitions of the same file
2) How to read these in a data frame using pyspark
解决方案
- As these files are in one directory, and these are named as part-xxxxx files, so you can safely assume these are multiple part files of the same dataset. If these are partitions, they should be saved like this /user/project/date=202005/*
- You can specify the dir "/user/project/202005" as input for spark like below assuming these are csv files
df = spark.read.csv('/user/project/202005/*',header=True, inferSchema=True)
推荐阅读
- python - 角色移动问题
- android - 在 android studio 中创建图表
- kubernetes - Kubernetes 中的 KSQL Server 弹性伸缩
- java - 数组列表和迭代
- c# - Console.ReadKey() 奇怪的行为?
- javascript - 如何在渲染方法中制作组件循环?
- validation - 使用 SCORE 语句生成预测与实际表
- c# - 带有 WPF 桌面桥包的 UWP 中的 System.BadImageFormatException
- javascript - Flowtype:如何正确使用 $ObjMap 使所有函数可链接?
- angular - 自定义验证器无法以 Angular 反应形式正常工作