You need to enable JavaScript to run this app.
ByteHouse云数仓版

ByteHouse云数仓版

复制全文
外表
Hive Catalog
复制全文
Hive Catalog

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

创建 Catalog

创建 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 外表, ByteHouse 只支持读配置在 cnch-config.yaml 中的 HDFS 的数据。

创建 Glue Catalog

ByteHouse 也试验性地支持了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 文档

删除 External Catalog

您可以使用如下命令删除 External Catalog。

drop external catalog your_catalog_name;

查看 Catalog

查看所有 Catalog。

show external catalogs;

查看某个 Catalog 的 Schema 信息。

show create external catalog your_catalog_name;

使用 Catalog

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

三段式命名

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

select * from hive_s3.hive_db_name.hive_table_name;

ByteHouse 原生的 CnchMergeTree 表也可以用如下 SQL 访问。其中,cnch(cloud-native-clickhouse的缩写)被用作了 Bytehouse CDW 默认 Catalog 的名字。

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

跨 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'

Switch Catalog

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

switch catalog hive_s3;

此时再运行

select * from tpcds.call_center;

Bytehouse CDW 就会从 Hive 中的 tpcds 数据库的 call_center 表读取数据。如果要切换会默认的 Catalog,您可以使用以下命令:

switch catalog cnch; 

您也可以使用以下命令,直接将默认的数据库切换到 Hive 的 tpcds 数据库:

use hive_s3.tpcds

如需切换回 Bytehouse CDW 内表,可使用以下命令:

use cnch.cnch_database_name
最近更新时间:2025.07.18 10:14:23
这个页面对您有帮助吗?
有用
有用
无用
无用