语法
参数
| 参数 | 描述 |
|---|---|
URI | 文件在 HDFS 中的相对 URI。文件路径在只读模式下支持以下通配符:*、?、{abc,def} 和 {N..M},其中 N、M 表示数字,'abc'、'def' 表示字符串。 |
format | 文件的格式。 |
structure | 表的结构。格式为 'column1_name column1_type, column2_name column2_type, ...'。 |
返回值
hdfs://hdfs1:9000/test 的表,以及从中选取前两行:
路径中的通配符
*— 表示任意多个字符,但不包括/,也可以表示空字符串。**— 表示递归匹配文件夹内的所有文件。?— 表示任意单个字符。{some_string,another_string,yet_another_one}— 替换为字符串'some_string'、'another_string'、'yet_another_one'中的任意一个。这些字符串可以包含/符号。{N..M}— 表示任何>= N且<= M的数字。
{} 的构造与 remote 和 file 表函数中的写法类似。
示例
- 假设我们在 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’
- 查询这些文件中的行数:
- 查询这两个目录下所有文件的行数:
如果文件列表中包含带前导零的数字范围,请对每一位数字分别使用花括号写法,或使用
?。file000、file001、…、file999 的文件中的数据:
虚拟列
_path— 文件路径。类型:LowCardinality(String)。_file— 文件名。类型:LowCardinality(String)。_size— 文件大小 (单位:字节) 。类型:Nullable(UInt64)。如果大小未知,则值为NULL。_time— 文件的最后修改时间。类型:Nullable(DateTime)。如果时间未知,则值为NULL。
use_hive_partitioning 设置
use_hive_partitioning 设置为 1 时,ClickHouse 会检测路径中采用 Hive 风格的分区 (/name=value/) ,并允许在查询中将分区列作为虚拟列使用。这些虚拟列的名称将与分区路径中的名称相同。
示例
使用通过 Hive 风格分区生成的虚拟列
存储设置
- hdfs_truncate_on_insert - 允许在插入前截断文件。默认禁用。
- hdfs_create_new_file_on_insert - 如果 格式 带有后缀,则允许在每次插入时创建新文件。默认禁用。
- hdfs_skip_empty_files - 允许在读取时跳过空文件。默认禁用。