hdfsCluster 表函数
允许从指定集群中的多个节点并行处理 HDFS 中的文件。在启动器上,它创建与集群中所有节点的连接,展开 HDFS 文件路径中的星号,并动态调度每个文件。在工作节点上,它向启动器询问要处理的下一个任务并进行处理。重复此操作,直到所有任务完成。
语法
hdfsCluster(cluster_name, URI, format, structure)
参数
cluster_name
— 用于构建一组地址和连接参数以连接远程和本地服务器的集群名称。URI
— 指向文件或一组文件的 URI。在只读模式下支持以下通配符:*
、**
、?
、{'abc','def'}` 和 `{N..M}
,其中N
、M
— 数字,abc
、def
— 字符串。有关更多信息,请参阅 路径中的通配符。format
— 文件的 格式。structure
— 表的结构。格式'column1_name column1_type, column2_name column2_type, ...'
。
返回值
一个具有指定结构的表,用于读取指定文件中的数据。
示例
- 假设我们有一个名为
cluster_simple
的 ClickHouse 集群,以及 HDFS 上具有以下 URI 的多个文件
- ‘hdfs://hdfs1:9000/some_dir/some_file_1’
- ‘hdfs://hdfs1:9000/some_dir/some_file_2’
- ‘hdfs://hdfs1:9000/some_dir/some_file_3’
- ‘hdfs://hdfs1:9000/another_dir/some_file_1’
- ‘hdfs://hdfs1:9000/another_dir/some_file_2’
- ‘hdfs://hdfs1:9000/another_dir/some_file_3’
- 查询这些文件中的行数
SELECT count(*)
FROM hdfsCluster('cluster_simple', 'hdfs://hdfs1:9000/{some,another}_dir/some_file_{1..3}', 'TSV', 'name String, value UInt32')
- 查询这两个目录中所有文件的行数
SELECT count(*)
FROM hdfsCluster('cluster_simple', 'hdfs://hdfs1:9000/{some,another}_dir/*', 'TSV', 'name String, value UInt32')
注意
如果您的文件列表包含带有前导零的数字范围,请对每个数字分别使用大括号构造或使用 ?
。
另请参阅