首页 > 解决方案 > 使用 Apache Beam 和 ParquetIO 读取多个 parquet 文件

问题描述

我需要在 Apache Beam 中读取多个 parquet 文件,所有文件都在同一个文件夹中。我尝试使用通配符 *.

我已经设法使用 ParquetIO 读取了单独的 parquet 文件,这是我读取一个 parquet 文件的片段:

pipeline.apply(ParquetIO.read(SCHEMA).from(filePath + File.separator + "*"));

其中 filePath 是例如 /path/xxx.parquet。

我尝试读取多个镶木地板文件的代码片段是

pipeline.apply(ParquetIO.read(SCHEMA).from(folderPath + File.separator + "*.parquet" + File.separator + "*"));

其中文件夹路径例如 /path/to/parquet/files/

我也试过没有最后一部分 File.separator + "*",但结果是一样的。我得到的信息是:

FileIO:654 - 匹配 0 个文件模式 /path/to/parquet/files/*.parquet/ *

此外,我可以拥有各种数量和名称的镶木地板文件。

是否可以使用 Apache Beam 读取多个 parquet 文件,因为我找到了读取多个 txt 文件的方法?

标签: apache-beamparquet

解决方案


是的,可以读取多个镶木地板文件,ParquetIO因为它FileIO在引擎盖下使用。只需尝试使用另一种匹配模式即可。在您的情况下,它可能是这样的(我希望folderPath是“/path/to”):

pipeline.apply(ParquetIO.read(SCHEMA).from(folderPath + File.separator + "parquet" + File.separator + "*" + File.separator + "*"));

或者最后只是双星:

pipeline.apply(ParquetIO.read(SCHEMA).from(folderPath + File.separator + "parquet" + File.separator + "**");

您不能将.其用作 glob 模式的一部分,因为它可以是文件路径的合法部分。用于?匹配单个目录中的任何单个字符或*任何字符串。此外,“**”模式匹配任何字符串,并跨越目录边界。


推荐阅读