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

外部表

CnchHive

CnchHive 是 ByConity 研发的表引擎,支持外部表联合查询,用户无需导入数据即可直接加速数据查询。CnchHive 支持查询存储在 HDFS 和 S3 的数据。它目前支持查询以 Parquet 和 ORC 格式存储的 Hive 数据文件。

建表示例

CREATE TABLE [IF NOT EXISTS] [db.]hive_ext
ENGINE = CnchHive('thrift://127.0.0.1:9083', 'hive_db', 'hive_table')
[SETTING vw_default = '']

表的信息既能自动从hive的元数据中导入又能手动指定具体的列名即其类型。

表的参数设置

CnchHive 允许通过指定配置文件的值来设置表,如下:

<yandex>
<hive>
<vw_default>vw_default</vw_default>
</hive>
</yandex>
  • vw_default: 用来执行查询的虚拟表
  • hdfs_fs: hdfs namenode的 url.
  • endpoint: S3 的enpoint
  • region: S3 的region
  • ak_id: S3 access key 密钥名
  • ak_secret: S3 secret key 密钥内容

配置 HDFS hive table 举例

<hive>
<hdfs_fs>hdfs://127.0.0.1:9010</hdfs_fs>
</hive>

配置 S3 hive table 举例

<hive>
<endpoint>http://127.0.0.1:9000</endpoint>
<ak_id>id</ak_id>
<ak_secret>secret</ak_secret>
</hive>

Disk 缓存配置

把下面配置加到 worker.xml 中打开缓存功能

<yandex>
<disk_cache_strategies>
<Hive>
<disk_cache_dir>hive</disk_cache_dir>
</Hive>
</disk_cache_strategies>
</yandex>

查询设置

磁盘缓存模式

是否在 SELECT 查询中使用磁盘缓存。可能的值:

  • AUTO - 当磁盘缓存可用时使用。
  • SKIP_DISK_CACHE - 不使用磁盘缓存。

如果缓存未命中,Hive 文件将在后台被缓存。

默认值:AUTO

使用 hive_metastore_filter

如果启用,CnchHive 将检查查询是否包含可传递给 Hive metastore以限制分区的分区键条件。Hive metastore将根据条件返回过滤后的分区列表。Hive metastore只能识别简单条件。

示例

# d列是hive的分区键
# d=1/, d=2/, d=3/

SELECT * FROM hive_ext WHERE d = 1
# Hive metastore 只返回 d=1/ 的分区

默认值: true

使用 hive_partition_filter

如果启用,CnchHive 将进一步对 Hive 元数据存储返回的分区列表进行分区过滤。

示例

# d列是 Hive 分区键,Hive 有分区
# d=20220203/, d=20220204/, d=20220205/

SELECT * FROM hive_ext WHERE toDate(d) = '2022-02-03'

# Hive metastore将返回所有三个分区,CnchHive 将进行分区过滤。最后只有分区 d=20220203/ 将被读取。

默认值: true

使用 hive_split_level_filter

Parquet and ORC files have index data for each row group/stripe. If enabled, CnchHive will filter row groups/stripes.

Parquet 和 ORC 文件对每个row group/stripe都有索引数据。如果启用,CnchHive 将过滤 row group/stripe。

默认值: false

表功能

SELECT count() FROM hive('thrift://127.0.0.1', 'hive_db', 'hive_table)

无需显式创建表即可查询 Hive 表。

SELECT * FROM hiveMetadata('thrift://127.0.0.1', 'hive_db', 'hive_table')

从 Hive 元数据存储返回 Hive 表的存储描述。