You need to enable JavaScript to run this app.
ByteHouse Cloud Data Warehouse Version

ByteHouse Cloud Data Warehouse Version

Copy page
Download PDF
Appearance
Hive external table
Copy page
Download PDF
Hive external table

CnchHive is a table engine provided by the ByteHouse team that supports federated queries using external tables. Users do not need to import data and can directly query data in Hive external tables, enhancing the flexibility and convenience of data processing. This article will introduce how to create, query, and write to external tables.

Background information

Hive data mapping methods

For Hive tables, ByteHouse currently supports three methods for data mapping between ByteHouse and Hive: create Hive external table, create Hive external database, and create Hive external catalog.

Data mapping Method / way

Data mapping Description

create Hive External table

Establish mapping from ByteHouse table to Hive table at the table (Table) Dimension. Source table schema changes will No Sync directly. If there are changes, Delete the External table in ByteHouse and create a new External table.

create Hive External Database

Establish mapping from ByteHouse Database to Hive Database at the Database (Database) Dimension. After establishing the Database mapping, Manual table mapping is not required. Table mapping under the Database can be Automatic Sync, and Add or Delete Hive tables can be detected. Source table schema changes can be directly Sync to ByteHouse.

create Hive External Catalog

Establish mapping from ByteHouse Catalog to Hive Catalog at the data directory (Catalog) Dimension. After establishing the Catalog mapping, manual creation of database and table mappings is no longer required. The database and table mappings under the Catalog can be automatically synchronized, and additions or deletions of Hive databases and tables can be detected. Changes to the source table schema can be directly synchronized to ByteHouse. For operation details on creating a Hive external Catalog, please refer to Hive Catalog.

Fee description

The feature of external tables is designed to provide data processing capabilities for sources other than ByteHouse internal tables. With a simple DDL statement, you can create an external table in ByteHouse, establishing an association between ByteHouse tables and external data sources.

  • External tables in ByteHouse only incur computation fees, following ByteHouse's computing resource billing rules. For details, please refer to Compute resources.
  • When using the external table feature, the data in external tables will not be copied and stored in ByteHouse, and therefore does not incur storage fees. For storage fees, please refer to the billing rules of the external data source's storage side.
  • When accessing external data sources through ByteHouse external tables, the external data source may incur computation, access, data transmission, and other fees. The specific fees are subject to the billing method of the external data source. Please refer to the relevant product documentation.

Prerequisites
  • ByteHouse's Hive external tables support two data reading scenarios: one is reading data stored in Hive itself, and the other is reading Hive data stored in BytePlus AI Data Lake Service (LAS). The following introduces the permissions and information you need to obtain before creating Hive external tables in these two scenarios:

    Data reading scenarios

    Required permissions and connection information

    Hive on Hive

    • Obtain permission to access the S3-compatible object storage service used by Hive.
    • Connection address for Hive metadata storage.
    • Access Key ID (AK) / Secret Access Key (SK) with permission to access the S3-compatible object storage service. If you use BytePlus object storage service TOS, see Access Key (key) management for the method to obtain access keys.
    • Endpoint of the S3-compatible object storage service. If you use BytePlus object storage service TOS, see Region and access domain name (Endpoint) for the method to obtain the endpoint.

    Hive on LAS

    • LAS Catalog permissions, as well as database and table-level read/write permissions. For configuration details, please refer to LAS permission management.
    • Connection information:
      • Endpoint and access keys (Access Key ID (AK) / Secret Access Key (SK)) for the TOS service used by LAS.
        • Endpoint: You can log in to the TOS console and view the required endpoint via the path Bucket list > Bucket name > Overview > Access domain name. For a list of common endpoints, refer to the S3 Endpoint column in Region and access domain name (Endpoint).
        • For the method to obtain access keys, please refer to Access Key (key) management.
      • Region of the physical data center for BytePlus object storage service TOS used by LAS. For a list of common regions, refer to Region and access domain name.
      • LAS access keys AK/SK. For the method to obtain them, please refer to Access Key (key) management.
      • LAS Catalog name. You can log in to LAS console, select Data lake > Metadata management in the left navigation bar, and view and obtain the required Catalog name.
      • LAS metadata storage service address. For addresses corresponding to common regions, refer to URL.
  • To write data to Hive on LAS external tables, confirm that the account you use has enabled the HNS (tiered bucket) feature of TOS.

Limitations
  • Currently, only Parquet, ORC, CSV, and Text format data are supported.
  • Currently, only SELECT and INSERT operations are supported for Hive external tables. ALTER is not supported yet; currently, only Hive tables are supported, and views are not supported.
  • When the schema of a Hive table in an External data source changes, automatic Sync to ByteHouse External tables is Not supported. You need to create the Hive External table again in ByteHouse.

Create Hive external table

By creating a ByteHouse External table, you establish a mapping from ByteHouse table to Hive table at the table Dimension. ByteHouse Hive External tables Support project two Data reading Scenes: Yes, reading Data stored in Hive itself; Two, reading Hive Data stored in BytePlus AI Data Lake Service (LAS). The following Intro details the table creation statements for ByteHouse connecting to Hive External tables in these two Scenes:

Hive on Hive

After the following CREATE command runs Success, you can view the newly created hive_table External table in the demo_db Database of ByteHouse.

CREATE TABLE demo_db.hive_table
Engine = CnchHive('thrift://hive_thrift_server_ip:port', 'default', 'test_table')
SETTINGS 
    meta_type = 'hive',
    endpoint = 's3_endpoint',
    ak_id = 's3_ak',
    ak_secret = 's3_sk';

Parameters

Configuration description

Table creation description

demo_db.hive_table: Creates a Hive external table in the specified ByteHouse database and supports custom table names.
When creating a table, the system will automatically map and create Hive table column names and types, as well as Partition By key, Cluster By key, and other information. Columns are created as nullable type by default, see the General reference: Column Type mappingsection below for column type mapping rules.

Engine parameters

  • The engine type is fixed as CnchHive.
  • thrift://hive_thrift_server_ip:port: Connection address for the Hive Metastore Service, where <hive_thrift_server_ip> is the IP address of the Hive Thrift Server, <port> is the port number. Refer to the official documentation of the Hive Service you use to obtain the connection address information. Example: thrift:// 101.xxx.xx.xxx:9083.
  • default: Specifies the source database name in Hive to which the external table being created will be mapped.
  • test_table: Specifies the source table name in Hive to which the external table being created will be mapped.

Settings parameters (SETTINGS)

  • meta_type: Fixed as hive.
  • Information about the S3-compatible object storage service used by Hive:
    • endpoint: Endpoint of the S3-compatible object storage.
    • ak_id: Access Key ID of the S3-compatible object storage.
    • ak_secret: Secret Access Key of the S3-compatible object storage.

Hive on LAS

After the following CREATE command runs Success, you can view the newly created hive_las_table External table in the demo_db Database of ByteHouse.

CREATE TABLE demo_db.hive_las_table
Engine = CnchHive('thrift://lakeformation.las.region.ivolces.com:48869', 'default', 'test_table')
SETTINGS 
    meta_type = 'lf', 
    endpoint = 'tos-s3-region.ivolces.com', 
    ak_id = 'your_access_key_id', 
    ak_secret='your_secret_access_key', 
    lf_metastore_url = 'thrift://lakeformation.las.region.ivolces.com:48869', 
    lf_metastore_region = 'region', 
    lf_metastore_ak_id = 'xxx', 
    lf_metastore_ak_secret = 'xxx==', 
    lf_metastore_catalog = 'hive_catalog';

Parameters

Configuration description

Table creation description

demo_db.hive_las_table: Create a Hive external table in the specified Database of ByteHouse, supporting custom table names.
When creating the table, the system will automatically create the column names and types of the Hive table, as well as information such as Partition By key, Cluster By key, and others. Columns are created as nullable type by default, see the mapping rules for column types in the section below General reference: Column Type mappingchapter.

Engine parameters (Engine)

  • Engine type is fixed as CnchHive.
  • thrift:// lakeformation.las.region.ivolces.com:48869: Specifies the access domain name of the region where your LAS is located. You can use the content in the Endpoint column of the link address to fill in this parameter according to your region.
  • default: Specifies the source database name in Hive to which the external table being created will be mapped.
  • test_table: Specifies the source table name in Hive to which the external table being created will be mapped.

Settings parameters (SETTINGS)

  • meta_type: Fixed as lf.
  • Information about the TOS data storage used by LAS:
  • Authentication parameters for LAS:
    • lf_metastore_url: Specifies the access domain name of the region where your LAS is located. You can use the content in the Endpoint column of the link address to fill in this parameter according to your region.
    • lf_metastore_region: The region where LAS is located. For the method to obtain it, please refer to region and available zone selection.
    • lf_metastore_ak_id: Access Key ID of LAS. For the method to obtain it, please refer to AccessKey (key) management.
    • lf_metastore_ak_secret: Secret Access Key of LAS. For the method to obtain it, please refer to AccessKey (key) management.
    • lf_metastore_catalog = 'hive_catalog': Indicates that the external table being created is mapped to the data directory named hive_catalog in LAS. When using, modify the name to the actual data directory in Hive. For example, in BytePlus LAS, log in to the LAS Console, select Data Lake > Metadata management in the left navigation bar, and view and obtain the required data directory name.

Create Hive external database

By creating a ByteHouse External Database, you establish a mapping from ByteHouse Database to Hive Database at the Database Dimension. After establishing the Database mapping, manual table mapping is no longer required. Table mappings under the Database can be automatically Synced.
ByteHouse Hive External tables Support project two Data reading Scenes: Yes, reading Data stored in Hive itself; Two, reading Hive Data stored in BytePlus AI Data Lake Service (LAS). The following Intro details the table creation statements for ByteHouse connecting to Hive External tables in these two Scenes:

Hive on Hive

After the following CREATE command runs Success, ByteHouse will New a Database named hive_db, and you can view the corresponding Hive External tables in this Database.

DROP DATABASE IF EXISTS hive_db;

CREATE DATABASE hive_db
Engine = Hive('thrift://hive_thrift_server_ip:port', 'default')
SETTINGS 
    meta_type = 'hive',
    endpoint = 's3_endpoint',
    ak_id = 's3_ak',
    ak_secret = 's3_sk';

Parameters

Configuration description

DROP statement

(Optional) The following command is used to ensure that any old database with the same name is removed before creating a new database, to avoid creation conflicts. Use this command with caution in production environments.

Database description

hive_db: Create a Hive external database in ByteHouse, supports custom database name.

Engine parameters (Engine)

  • The engine type is fixed as Hive.
  • thrift://hive_thrift_server_ip:port: Connection address of the Hive metadata storage service (metastore), where <hive_thrift_server_ip> is the IP address of the Hive Thrift server and <port> is the port number. Refer to the official documentation of your Hive service to obtain the connection address information. Example: thrift:// 101.xxx.xx.xxx:9083.
  • default: Specifies the source database name in Hive to which the currently created external database is mapped.

Settings parameters (SETTINGS)

  • meta_type: Fixed as hive.
  • Information about the S3-compatible object storage service used by Hive:
    • endpoint: Endpoint of the S3-compatible object storage.
    • ak_id: Access Key ID of the S3-compatible object storage.
    • ak_secret: Secret Access Key of the S3-compatible object storage.

Hive on LAS

After the following CREATE command runs Success, ByteHouse will New a Database named hive_db_las, and you can view the corresponding Hive External tables in this Database.

DROP DATABASE IF EXISTS hive_db_las;

CREATE DATABASE hive_db_las
Engine = Hive('thrift://lakeformation.las.region.ivolces.com:48869', 'default')
SETTINGS 
    meta_type = 'lf', 
    endpoint = 'tos-s3-region.ivolces.com', 
    ak_id = 'xxx', 
    ak_secret= 'xxx==', 
    lf_metastore_url = 'thrift://lakeformation.las.region.ivolces.com:48869', 
    lf_metastore_region = 'region', 
    lf_metastore_ak_id = 'your_access_key_id',
    lf_metastore_ak_secret = 'your_secret_access_key', 
    lf_metastore_catalog = 'hive_catalog';

Parameters

Configuration description

DROP statement

(Optional) The following command is used to ensure that any old database with the same name is removed before creating a new database, to avoid creation conflicts. Use this command with caution in production environments.

Database description

hive_db_las: Create a Hive external database in ByteHouse, supports custom database name.

Engine parameters (Engine)

  • The engine type is fixed as Hive.
  • thrift:// lakeformation.las.region.ivolces.com:48869: Specifies the access domain name of the region where your LAS is located. You can fill in this parameter using the content in the Endpoint column of the link address according to your region.
  • default: Specifies the source database name in Hive to which the currently created external table is mapped.

Settings parameters (SETTINGS)

  • meta_type: Fixed as lf.
  • Information about the data storage TOS (BytePlus object storage service) used by LAS:
  • LAS authentication parameters:
    • lf_metastore_url: Specifies the access domain name for LAS in your region. You can fill in this parameter using the content in the Endpoint column of the URL based on your region.
    • lf_metastore_region: The region where LAS is located. For how to obtain it, see Region and Available Zone selection, and fill in based on your region.
    • lf_metastore_ak_id: The Access Key ID of LAS. For how to obtain it, see AccessKey (key) management.
    • lf_metastore_ak_secret: The Secret Access Key of LAS. For how to obtain it, see AccessKey (key) management.
    • lf_metastore_catalog = 'hive_catalog': Indicates that the created external database is mapped to the data directory named hive_catalog in LAS. When using, change to the actual data directory name in Hive. For example, in BytePlus LAS, you can log in to the LAS Console, select Data Lake > Metadata Management in the left navigation bar, and view and obtain the required data directory name.

Search external table

The Search Actions for Hive External tables are consistent with those for Normal tables. When specifying the Database, here the Database can be either the ByteHouse Database where only the Hive External table is created, or the Hive External Database. For example:

SELECT * FROM demo_db.hive_las_table WHERE xxx;

When searching External table Data, ByteHouse Support project activating BSP Mode. For Activity details, see Activate BSP Mode.

Search acceleration: Activate cache loading (Disk Cache)

  1. Apply to activate cache loading Function.
    ByteHouse is providing you with Local disk cache loading capability, allowing Part of the Data to be cached on your Local hard disk to improve Search efficiency. This Function is Default Terminated. To use this Function, contact ByteHouse RD Personnel to Open function.
  2. After the Function is activated, the cache loading Function will be used by Default when searching External table Data.

    tip

    To disable local disk cache loading for a specific query, set the SETTINGS parameter disk_cache_mode = 'SKIP_DISK_CACHE' when creating the external table.

Write to External table

The write Actions for Hive External tables are basically consistent with those for Normal tables. Support project writing to External tables Pass INSERT INTO or INSERT OVERWRITE Method / way.

warning

Before writing to Hive on LAS external tables, confirm that your account has the following permissions and functions:

  • Has LAS Formation access permission for BytePlus LAS AI Database Service;
  • Has access permission for BytePlus Object Storage TOS;
  • TOS has enabled the HNS (hierarchical bucket) function.

Currently, ByteHouse Cloud Data Warehouse Edition does not support writing to TOS buckets without HNS enabled. For more information about HNS of TOS buckets, see TOS Help Documentation.

INSERT INTO

You can use the basic INSERT INTO statement to write Data.

# 方式 1
INSERT INTO database.table VALUES (val1, val2, ...), (val1, val2, ...), ...;

# 方式 2
INSERT INTO database.table SELECT [col1, col2, ... | *] FROM source_db.source_table;

Parameter

Configuration description

Database and table description

database.table: Specifies the database and table name to query. Here, the database can be the ByteHouse database where only Hive external tables are created, or it can be a Hive external database.

Description of write parameters

  • VALUES: Fill in the values to be inserted. The format is (val1, val2, ...), (val1, val2, ...),.... Examples are as follows:

    INSERT INTO demo_db.hive_las_table VALUES (1, 'a', '2021-07-27'), (2, 'b', '2021-07-27')
    
  • SELECT: Write data using the result of a SELECT query. Fill in according to the syntax of the SELECT statement. Examples are as follows:

    # SELECT 源表中的所有数据插入目标表
    INSERT INTO demo_db.hive_las_table SELECT * FROM example_table
    
    # SELECT 源表中的指定数据插入目标表
    INSERT INTO demo_db.hive_las_table SELECT s,d,n FROM example_table
    

INSERT OVERWRITE

The Function of this statement is to rewrite the table.

# 方式 1
INSERT OVERWRITE database.table VALUES (val1, val2, ...), (val1, val2, ...), ...;

# 方式 2
INSERT OVERWRITE database.table SELECT [col1, col2, ... | *] FROM source_db.source_table;

Parameter

Configuration description

Database and table description

database.table: Specifies the database and table name to query. Here, the database can be the ByteHouse database where only Hive external tables are created, or it can be a Hive external database.

Description of write parameters

  • VALUES: Fill in the values to be inserted. The format is (val1, val2, ...), (val1, val2, ...),.... Examples are as follows:

    INSERT OVERWRITE demo_db.hive_las_table VALUES (1, 'a', '2021-07-27'), (2, 'b', '2021-07-27')
    
  • SELECT: Use the result of a SELECT query to write data. You can fill in the statement according to the syntax of the SELECT query. Examples are as follows:

    # SELECT 源表中的所有数据插入目标表
    INSERT OVERWRITE demo_db.hive_las_table SELECT * FROM example_table
    
    # SELECT 源表中的指定数据插入目标表
    INSERT OVERWRITE demo_db.hive_las_table SELECT s,d,n FROM example_table
    

When writing Data to an External table, ByteHouse also Support project Activate BSP Mode. For Activity details, see Activate BSP Mode.

Activate BSP Mode

BSP Mode can Carry on mission-level fault tolerance and finer-grained scheduling:

  • When a query encounters an Error during Running, it can Automatic Retry the current Mission instead of retrying from the Head, reducing Retry costs.
  • When a query requires a Large amount of memory, even Bigger than the memory of a single machine, you can reduce memory usage per Unit Time by increasing the Degree of parallelism.

You can specify the settings Param to Activate BSP Mode during Search. The parameter description for the settings Param is as follows:

Parameter name

Type

Default value

Description

bsp_mode

Bool

0 (off)

Set to 1 to enable BSP mode. After enabling BSP mode, queries are executed in stages. Shuffle connections are used between stages. Task-level retries are performed in the event of failure.

distributed_max_parallel_size

UInt64

Equal to the number of workers

When a single query uses a large amount of memory, increasing this parameter can increase the operator's degree of parallelism, reduce the amount of data processed by each parallel operator, and reduce memory usage per unit time. The value of distributed_max_parallel_size can exceed the number of workers only when BSP mode is enabled. It is recommended to set this parameter as a multiple of the number of workers.

bsp_max_retry_num

UInt64

The default value varies by version.

The maximum number of task retries. ByteHouse supports setting the bsp_max_retry_num parameter starting from version 2.0.4. The default values for different versions are as follows:
In ByteHouse 2.0.4/2.1, counted at the query granularity, the default is 5 times. In ByteHouse 2.2, counted at the segment granularity, the default is 3 times.
You can view the current ByteHouse version via the ByteHouse Console>Tenant Management>Basic Information path.

Example:

SELECT * FROM demo_db.hive_las_table 
SETTINGS bsp_mode = 1, distributed_max_parallel_size = 4;

General reference: Column Type mapping

Hive column type

CnchHive column type

Description

INT/INTEGER

Nullable INT/INTEGER

None

BIGINT

Nullable BIGINT

None

TIMESTAMP

Nullable DateTime

None

STRING

Nullable String

None

VARCHAR

Nullable FixedString

Internally converted to FixedString

CHAR

Nullable FixedString

Internally converted to FixedString

DOUBLE

Nullable DOUBLE

None

FLOAT

Nullable FLOAT

None

DECIMAL

Nullable DECIMAL

None

MAP

Nullable Map

None

ARRAY

Nullable Array

None

Last updated: 2026.03.31 16:21:57