用法
ENGINE = HDFS(URI, format)
- URI 参数是HDFS中的整个文件URI。
- format 参数指定一种可用的文件格式。 执行
DEMO
1. 设置 hdfs_engine_table
表:
CREATE TABLE hdfs_engine_table (name String, value UInt32) ENGINE=HDFS('hdfs://hdfs1:9000/other_storage', 'TSV')
2. 填充文件:
INSERT INTO hdfs_engine_table VALUES ('one', 1), ('two', 2), ('three', 3)
3. 查询数据:
SELECT * FROM hdfs_engine_table LIMIT 2
- 假设我们在HDFS上有几个TSV格式的文件,其中包含以下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’
有几种方法可以创建由所有六个文件组成的表:
CREATE TABLE table_with_range (name String, value UInt32) ENGINE = HDFS('hdfs://hdfs1:9000/{some,another}_dir/some_file_{1..3}', 'TSV') CREATE TABLE table_with_question_mark (name String, value UInt32) ENGINE = HDFS('hdfs://hdfs1:9000/{some,another}_dir/some_file_?', 'TSV') CREATE TABLE table_with_asterisk (name String, value UInt32) ENGINE = HDFS('hdfs://hdfs1:9000/{some,another}_dir/*', 'TSV')