apache-spark - 使用 PySpark/Python 一次从 HDFS 分区顺序读取一条记录
问题描述
我想从 HDFS 分区中按顺序一次读取一条记录。我找到了一个处理此逻辑的示例 Java 片段。有没有办法使用 PySpark/Python 来实现这一点?
下面的示例 Java 片段(注意 while 循环):
FileSystem fileSystem = FileSystem.get(conf);
Path path = new Path("/path/file1.txt");
if (!fileSystem.exists(path)) {
System.out.println("File does not exists");
return;
}
FSDataInputStream in = fileSystem.open(path);
int numBytes = 0;
while ((numBytes = in.read(b))> 0) {
System.out.prinln((char)numBytes));// code to manipulate the data which is read
}
in.close();
out.close();
fileSystem.close();
解决方案
推荐阅读
- python - 将 pyyaml 与 FastAPI 一起使用时出现 CORS 错误
- excel - Excel 2019 - 使用 VBA 在单元格上自动插入时间
- c# - 反序列化 JSON 并分配给模型
- maven - 无法解析捆绑包,缺少需求 JAX-RS
- flutter - 使用动态 url 参数在 Webview 中打开网页 [Flutter - WebViewScaffold]
- angular - Angular 8 - 扩展 DevExpress 库的数据网格
- c - 如何添加互斥锁和条件变量来保证这种行为?
- unity3d - 统一玩家移动,速度不固定
- java - 在创建对象时生成 UUID 作为 Id,而不是使用 @GeneratedValue
- java - 从 CalenderView 禁用星期五