跳到主要内容
版本:0.4.x

Hive External Catalog

Byconity 除了支持使用外表访问Hive数据意外,也支持通过External Catalog 方式访问。

配置 external_catalog_mgr

我们需要将External Catalog的元信息存储在Byconity的元数据存储中. 因此我们需要在 cnch_config.yaml 中配置 external_catalog_mgr,以配置External Catalog 相关的元数据的存放位置.

一般而言, 用户可以选择将External Catalog 元数据和 Byconity 元数据信息放在一个位置,所以用户可以直接复用之前元数据使用的 catalog_service配置的内容,比如

external_catalog_mgr:
type: fdb
fdb:
cluster_file: /config/fdb.cluster

创建 External Catalog

目前只支持IAM鉴权.

创建 Hive Catalog

数据在s3使用

create external catalog hive_s3
properties
type='hive',
hive.metastore.uri = 'thrift://hive_thrift_server_ip:port',
aws.s3.region= 's3_region',
aws.s3.endpoint = 's3_endpoint',
aws.s3.access_key = 's3_ak',
aws.s3.secret_key = 's3_sk'

数据在hdfs使用

create external catalog hive_hdfs
properties
type='hive',
hive.metastore.uri = 'thrift://hive_thrift_server_ip:port',

需要注意, 对于存储在HDFS上的Hive外表, 我们只支持读配置在 cnch-config.yaml 中的HDFS的数据.

创建 Glue Catalog

我们也试验性的支持了AWS Glue Datacatalog.

create external catalog glue_s3
properties
type='glue',
aws.glue.endpoint = 'glue_endpoint',
aws.glue.region='glue_region',
aws.glue.catalog_id='glue_catalog_id',
aws.glue.access_key = 'glue_ak',
aws.glue.secret_key = 'glue_sk',
aws.s3.region= 's3_region',
aws.s3.endpoint = 's3_endpoint',
aws.s3.access_key = 's3_ak',
aws.s3.secret_key = 's3_sk'

这里的glue_catalog_id是一个12位数字的AWS账号名,具体可以参考Aws Account ID Doc.

删除 External Catalog

用户可以如下删除External Catalog

drop external catalog your_catalog_name;

基本使用

假设用户已经创建好了一个名叫hive_s3的External Catalog

三段式命名

用户可以通过 catalog_name.db_name.table_name 这种三段式命名方式直接访问Hive中的表, 比如

    select * from hive_s3.hive_db_name.hive_table_name;

Byconity 原生的 CnchMergeTree 表 也可以用如下SQL 访问

    select * from cnch.cnch_db_name.cnch_db_name;
-- this is equivalent to select * from cnch_db_name.cnch_db_name;

cnch (cloud-native-clickhouse的缩写) 被用作了Byconity 默认Catalog的名字。

跨Catalog查询

利用External Catalog,用户可以直接将Hive 外表和Cnch的CnchMergeTree表做join

 select * from hive_s3.hive_db.hive_table union all select (1) from cnch.cnch_db.cnch_table;

Show Databases and Tables

列出Catalog 中的数据库名

 show databases [from hive_catalog]

列出数据库中的表名

 show tables from [hive_catalog.][database]

获取表的创建语句

 show create table [hive_catalog.][database.][table]

请注意, 外表的show create table 结果类似下面

CREATE TABLE `hive_catalog$$hive_db_name`.hive_table_name UUID 'some-uuid' (--field list -- `cc_call_center_sk` Nullable(Int64), `cc_call_center_id` Nullable(String))) ENGINE = CnchHive(hive_catalog, hive_db_name, hive_table_name) PARTITION BY tuple() SETTINGS endpoint = 'hive_endpoint', ak_id = 's3_ak', ak_secret = 's3_sk', region = 's3_region'

这个只用于展示外表的schema信息,不能用来在Hive中创建外表

目前Byconity 还没有支持直接创建Hive表的功能

Switch Catalog

用户可以使用如下SQL来改变默认的Catalog

    switch catalog hive_s3;

此时再运行

    select * from tpcds.call_center;

Byconity 就会从Hive中的tpcds数据库的call_center表读取数据 要切换会默认的Catalog,用户可以使用

    switch catalog cnch;

用户也可以使用

    use hive_s3.tpcds

直接将默认的数据库改到Hive的tpcds数据库。 为了切换换来, 直接使用

    use cnch.cnch_database_name

实现细节

我们采用了一种类似改写SQL的方式来支持多Catalog

    select * from catalog_name.db.tbl

实际上会被改写到

    select * from `catalog_name$$db`.tbl

所以请用户在日志中看到相关内容的时候不要惊讶