允许从指定集群中的多个节点并行处理 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')