ClickHouse(22)ClickHouse集成HDFS表引擎详细解析

HDFS

这个引擎提供了与Apache Hadoop生态系统的集成,允许通过ClickHouse管理HDFS上的数据。这个引擎提供了Hadoop的特定功能。

用法

sql 复制代码
ENGINE = HDFS(URI, format)

URI 参数是HDFS中整个文件的URI
format 参数指定一种可用的文件格式。执行SELECT查询时,格式必须支持输入,以及执行INSERT查询时,格式必须支持输出.路径部分URI可能包glob通配符。在这种情况下,表将是只读的。

clickhouse支持的format,文件格式:

格式 输入 输出
TabSeparated
TabSeparatedRaw
TabSeparatedWithNames
TabSeparatedWithNamesAndTypes
Template
TemplateIgnoreSpaces
CSV
CSVWithNames
CustomSeparated
Values
Vertical
JSON
JSONAsString
JSONStrings
JSONCompact
JSONCompactStrings
JSONEachRow
JSONEachRowWithProgress
JSONStringsEachRow
JSONStringsEachRowWithProgress
JSONCompactEachRow
JSONCompactEachRowWithNamesAndTypes
JSONCompactStringsEachRow
JSONCompactStringsEachRowWithNamesAndTypes
TSKV
Pretty
PrettyCompact
PrettyCompactMonoBlock
PrettyNoEscapes
PrettySpace
Protobuf
ProtobufSingle
Avro
AvroConfluent
Parquet
Arrow
ArrowStream
ORC
RowBinary
RowBinaryWithNamesAndTypes
Native
Null
XML
CapnProto
LineAsString
Regexp
RawBLOB

示例:

1. 设置 hdfs_engine_table 表:

sql 复制代码
CREATE TABLE hdfs_engine_table (name String, value UInt32) ENGINE=HDFS('hdfs://hdfs1:9000/other_storage', 'TSV')

2. 填充文件:

sql 复制代码
INSERT INTO hdfs_engine_table VALUES ('one', 1), ('two', 2), ('three', 3)

3. 查询数据:

sql 复制代码
SELECT * FROM hdfs_engine_table LIMIT 2
text 复制代码
┌─name─┬─value─┐
│ one  │     1 │
│ two  │     2 │
└──────┴───────┘

实施细节

  • 读取和写入可以并行
  • 不支持:
    • ALTERSELECT...SAMPLE 操作。
    • 索引。
    • 复制。

路径中的通配符

多个路径组件可以具有 globs。 对于正在处理的文件应该存在并匹配到整个路径模式。 文件列表的确定是在 SELECT 的时候进行(而不是在 CREATE 的时候)。

  • * --- 替代任何数量的任何字符,除了 / 以及空字符串。
  • ? --- 代替任何单个字符.
  • {some_string,another_string,yet_another_one} --- 替代任何字符串 'some_string', 'another_string', 'yet_another_one'.
  • {N..M} --- 替换 N 到 M 范围内的任何数字,包括两个边界的值.

示例

  1. 假设我们在 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'
  1. 有几种方法可以创建由所有六个文件组成的表:
sql 复制代码
CREATE TABLE table_with_range (name String, value UInt32) ENGINE = HDFS('hdfs://hdfs1:9000/{some,another}_dir/some_file_{1..3}', 'TSV')

另一种方式:

sql 复制代码
CREATE TABLE table_with_question_mark (name String, value UInt32) ENGINE = HDFS('hdfs://hdfs1:9000/{some,another}_dir/some_file_?', 'TSV')

表由两个目录中的所有文件组成(所有文件都应满足query中描述的格式和模式):

sql 复制代码
CREATE TABLE table_with_asterisk (name String, value UInt32) ENGINE = HDFS('hdfs://hdfs1:9000/{some,another}_dir/*', 'TSV')

注意:

复制代码
如果文件列表包含带有前导零的数字范围,请单独使用带有大括号的构造或使用 `?`.

示例

创建具有名为文件的表 file000, file001, ... , file999:

sql 复制代码
CREARE TABLE big_table (name String, value UInt32) ENGINE = HDFS('hdfs://hdfs1:9000/big_dir/file{0..9}{0..9}{0..9}', 'CSV')

配置

与 GraphiteMergeTree 类似,HDFS 引擎支持使用 ClickHouse 配置文件进行扩展配置。有两个配置键可以使用:全局 (hdfs) 和用户级别 (hdfs_*)。首先全局配置生效,然后用户级别配置生效 (如果用户级别配置存在) 。

xml 复制代码
  <!-- HDFS 引擎类型的全局配置选项 -->
  <hdfs>
    <hadoop_kerberos_keytab>/tmp/keytab/clickhouse.keytab</hadoop_kerberos_keytab>
    <hadoop_kerberos_principal>clickuser@TEST.CLICKHOUSE.TECH</hadoop_kerberos_principal>
    <hadoop_security_authentication>kerberos</hadoop_security_authentication>
  </hdfs>

  <!-- 用户 "root" 的指定配置 -->
  <hdfs_root>
    <hadoop_kerberos_principal>root@TEST.CLICKHOUSE.TECH</hadoop_kerberos_principal>
  </hdfs_root>

可选配置选项及其默认值的列表

libhdfs3 支持的

| 参数 | 默认值 |

| rpc_client_connect_tcpnodelay | true |

| dfs_client_read_shortcircuit | true |

| output_replace-datanode-on-failure | true |

| input_notretry-another-node | false |

| input_localread_mappedfile | true |

| dfs_client_use_legacy_blockreader_local | false |

| rpc_client_ping_interval | 10 * 1000 |

| rpc_client_connect_timeout | 600 * 1000 |

| rpc_client_read_timeout | 3600 * 1000 |

| rpc_client_write_timeout | 3600 * 1000 |

| rpc_client_socekt_linger_timeout | -1 |

| rpc_client_connect_retry | 10 |

| rpc_client_timeout | 3600 * 1000 |

| dfs_default_replica | 3 |

| input_connect_timeout | 600 * 1000 |

| input_read_timeout | 3600 * 1000 |

| input_write_timeout | 3600 * 1000 |

| input_localread_default_buffersize | 1 * 1024 * 1024 |

| dfs_prefetchsize | 10 |

| input_read_getblockinfo_retry | 3 |

| input_localread_blockinfo_cachesize | 1000 |

| input_read_max_retry | 60 |

| output_default_chunksize | 512 |

| output_default_packetsize | 64 * 1024 |

| output_default_write_retry | 10 |

| output_connect_timeout | 600 * 1000 |

| output_read_timeout | 3600 * 1000 |

| output_write_timeout | 3600 * 1000 |

| output_close_timeout | 3600 * 1000 |

| output_packetpool_size | 1024 |

| output_heeartbeat_interval | 10 * 1000 |

| dfs_client_failover_max_attempts | 15 |

| dfs_client_read_shortcircuit_streams_cache_size | 256 |

| dfs_client_socketcache_expiryMsec | 3000 |

| dfs_client_socketcache_capacity | 16 |

| dfs_default_blocksize | 64 * 1024 * 1024 |

| dfs_default_uri | "hdfs://localhost:9000" |

| hadoop_security_authentication | "simple" |

| hadoop_security_kerberos_ticket_cache_path | "" |

| dfs_client_log_severity | "INFO" |

| dfs_domain_socket_path | "" |

HDFS 配置参考 也许会解释一些参数的含义.

ClickHouse 额外的配置

| 参数 | 默认值 |

|hadoop_kerberos_keytab | "" |

|hadoop_kerberos_principal | "" |

|hadoop_kerberos_kinit_command | kinit |

限制

  • hadoop_security_kerberos_ticket_cache_path 只能在全局配置, 不能指定用户

Kerberos 支持

如果 hadoop_security_authentication 参数的值为 'kerberos' ,ClickHouse 将通过 Kerberos 设施进行认证。

注意,由于 libhdfs3 的限制,只支持老式的方法。数据节点的安全通信无法由SASL保证 ( HADOOP_SECURE_DN_USER 是这种安全方法的一个可靠指标)。

如果指定了hadoop_kerberos_keytab, hadoop_kerberos_principal或者hadoop_kerberos_kinit_command,将会调用kinit工具.在此情况下,hadoop_kerberos_keytab和hadoop_kerberos_principal参数是必须配置的.kinit工具和 krb5 配置文件是必要的.

虚拟列

  • _path --- 文件路径.
  • _file --- 文件名.

资料分享

ClickHouse经典中文文档分享

系列文章

clickhouse系列文章

知乎系列文章

相关推荐
倔强的石头_16 小时前
KingbaseES 新版MySQL 兼容版体验:旧版迁移 + 功能实测
数据库
大大大大晴天1 天前
Hudi技术内幕:Key Generation原理与实践
大数据
倔强的石头_4 天前
《Kingbase护城河》——数据库存储空间全景探测与精细化瘦身实战
数据库
冬奇Lab4 天前
每日一个开源项目(第134篇):Zvec - 阿里开源的嵌入式向量数据库,向量搜索界的 SQLite
数据库·人工智能·llm
ClouGence5 天前
Oracle CDC 架构优化:从主库直连到 DataGuard 备库同步
数据库·后端·oracle
得物技术5 天前
从埋点需求到规则资产:Hermes Agent 重构得物数仓工作流
大数据·llm·ai编程
久美子5 天前
AI驱动数仓建设的Harness工程实践——本体建模、知识分层与上下文工程
大数据
无响应de神5 天前
三、用户与权限管理
数据库·mysql
大树885 天前
金刚石散热越强,管路越先见顶
大数据·运维·服务器·人工智能·ai
大志哥1235 天前
ES和Logstash日志链路系统上线后遭遇切片爆炸(解决)
大数据·elasticsearch