跳到主要内容
跳到主要内容

hdfsCluster 表函数

允许从指定集群中的多个节点并行处理 HDFS 中的文件。在发起者上,它创建与集群中所有节点的连接,暴露 HDFS 文件路径中的星号,并动态分派每个文件。在工作节点上,它向发起者请求处理的下一个任务并进行处理。这个过程会重复,直到所有任务完成。

语法

hdfsCluster(cluster_name, URI, format, structure)

参数

参数描述
cluster_name用于构建对远程和本地服务器的地址和连接参数集的集群名称。
URI指向文件或一系列文件的 URI。在只读模式下支持以下通配符:*, **, ?, {'abc','def'}{N..M},其中 NM 是数字,abcdef 是字符串。有关更多信息,请参见 路径中的通配符
format文件的 格式
structure表的结构。格式为 'column1_name column1_type, column2_name column2_type, ...'

返回值

一个具有指定结构的表,用于读取指定文件中的数据。

示例

  1. 假设我们有一个名为 cluster_simple 的 ClickHouse 集群,以及以下 URI 的几个文件位于 HDFS 上:
  • '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'
  1. 查询这些文件的行数:
SELECT count(*)
FROM hdfsCluster('cluster_simple', 'hdfs://hdfs1:9000/{some,another}_dir/some_file_{1..3}', 'TSV', 'name String, value UInt32')
  1. 查询这两个目录中所有文件的行数:
SELECT count(*)
FROM hdfsCluster('cluster_simple', 'hdfs://hdfs1:9000/{some,another}_dir/*', 'TSV', 'name String, value UInt32')
备注

如果文件列表中包含带前导零的数字范围,请为每个数字单独使用带括号的结构或使用 ?