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

ByteHouse Cloud Data Warehouse Version

Copy page
Download PDF
Appearance
S3 external tables
Copy page
Download PDF
S3 external tables

The CnchS3 engine developed by ByteHouse integrates object storage and supports managing data stored in S3-compatible object storage via ByteHouse. This article will introduce how to use S3 external tables in ByteHouse cloud data warehouse edition.

Background information

ByteHouse, using the CnchS3 engine, enables integration with S3-compatible object storage without needing to migrate data into ByteHouse, allowing queries, writes, and other operations on the original data in object storage. ByteHouse provides two usage methods: CnchS3 table engine (persistent external table) and CnchS3 table function, which you can flexibly choose according to business scenarios.
The comparison between CnchS3 table engine and CnchS3 table function is as follows:

Method

Use cases

CnchS3 table engine

  • Supports repeated queries without repeatedly specifying connection, format, and other parameters. Suitable for scenarios requiring multiple accesses to external data.
  • Applicable to both small-batch and large-batch data import.

CnchS3 table function

  • One-time query, no need to create a table in advance. The syntax is relatively flexible, but each query requires all parameters to be specified in full. This approach is more suitable for one-time data loading tasks.
  • Suitable for one-time import or query of small or large batches of data.

Fee description

The purpose of external tables is to provide processing capabilities for data 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 computation resource billing rules.
  • When using the external table feature, the data of the external table will not be copied to ByteHouse and incur storage fees. For storage fees, please refer to the billing rules of the external data source's storage side.
  • When using ByteHouse external tables to access external data sources, the external data source may incur computation, access, data transfer, and other fees. The specific fees depend on the external data source's billing method. Please refer to the relevant product's description.

Prerequisites

Before starting, please ensure you have access privileges to the object storage bucket you use:

Important notes
  1. Security: Ensure the security of Access Key ID and Secret Access Key, and do not expose them to unauthorized personnel.
  2. Performance: When performing large-volume data import, pay attention to the database and network load. You can import data in batches to reduce the load.
  3. S3 URL correctness: When using TOS external tables to import data, note that the endpoint provided by BytePlus TOS differs from the S3 endpoint. As shown below, the link https://tos-{REGION}.volces.com/xxx copied from the BytePlus TOS console cannot be used directly. The domain name must be changed to the S3 endpoint domain name and modified to the format https://tos-s3-{REGION}.volces.com/xxx. For details, see BytePlus TOS supported regions and access domain names.

Use CnchS3 table engine

Create table

Syntax

CREATE TABLE [db_name.]table_name (
    column1 type1, column2 type2, ...
) ENGINE=CnchS3(
  'http://....' or 'https://' or 's3://', 
  '[FORMAT]',
  '[COMPRESSION]', 
  'access_key_id', 
  'secret_access_key'
);

Parameter name

Required

Description

db_name

No

Specify the name of the database where the table is located. If you run USE db_name before creating the table, you do not need to specify the database name.
Example: demo_db.target_table_name.

table_name

Yes

Specify the table name of the S3 external table. Example: demo_db.target_table_name.

column1 type1

Yes

Specify the structure of the S3 external table, including column names and column types. Example: id UInt64, name String.

ENGINE

Yes

The table engine is specified as CnchS3.

'http://....' or 'https://' or 's3://'

Yes

Specify the path to the object storage bucket corresponding to the S3 external table. The path description is as follows:

  • 'http://....' or 'https://': Specify the data source path for the S3 external table. For example:

    https://bucket.endpoint/file_path/file
    
  • s3://bucket/file_path will use the ByteHouse cluster's default S3 storage configuration.

  • If you use TOS, you can navigate to TOS console > Bucket list > Bucket name > File list > click the details button next to the file name to view and copy the URL, and change the domain name to the S3 endpoint domain name. For details, see BytePlus TOS supported regions and access domain names. For example:

    https://{bucket_name}.tos-s3-{region}.volces.com/file_path
    

FORMAT

Yes

Specify the file format of the S3 external table. Please fill in according to your file format. For formats currently supported by ByteHouse, see Related reference: File formats supported by the CnchS3 table engine.

COMPRESSION

Yes

Specify the compression format for the S3 external table. Currently, gzip, zstd, lz4, snappy, bzip2, xz, and brotli compression formats are supported. You can also set it to none. If not specified, the system will infer the compression format from the file suffix.

access_key_id

Yes

Specify the Access Key ID of the object storage service used by the S3 external table. You can refer to the official documentation of your object storage service to obtain the Access Key ID. If you use BytePlus TOS, refer to Access Key (key) management.

secret_access_key

Yes

Specify the Secret Access Key of the object storage service used by the S3 external table. You can refer to the official documentation of your object storage service to obtain the Secret Access Key. If you use BytePlus TOS, refer to Access Key (key) management.

Example

  • Create single file table

    CREATE TABLE
        s3_engine_table(name String, value UInt32) ENGINE = CnchS3(
            'https://bucket.endpoint/file_path/fileSample.csv',
            'CSV',
            'none',
            'access_key_id',
            'secret_access_key'
        );
    
  • Use wildcard character to create multi-file table

    CREATE TABLE
        s3_engine_table_glob_uri(name String, value UInt32) ENGINE = CnchS3(
            'https://bucket.endpoint/file_path/fileSample*.csv',
            'CSV',
            'none',
            'access_key_id',
            'secret_access_key'
        );
    

Write data

You can use the INSERT INTO statement to write data to S3 external tables. The usage is the same as writing to normal tables.
Examples are as follows:

INSERT INTO s3_engine_table 
VALUES ('one', 1), ('two', 2), ('three', 3);

Query data

You can use the SELECT statement to query data in S3 external tables. The usage is the same as querying normal tables. ByteHouse also supports pruning queries by the _path and _file columns. Examples are as follows:

  • Query data

    SELECT * FROM s3_engine_table;
    
  • Use the _file column for pruning queries

    SELECT * FROM s3_engine_table_glob_uri WHERE _file = 'fileSample.csv';
    

Modify configuration

By default, the resources_assign_type **** value of external tables is server_push. In this mode, data files are sent to workers for querying. To query locally on the server, change resources_assign_type to server_local.

ALTER TABLE s3_engine_table MODIFY SETTING resources_assign_type='server_local'

Change AK/SK

You can update AK/SK by using the SELECT statement.

SELECT * FROM s3_engine_table SETTINGS s3_access_key_id = 'your_new_ak', s3_access_key_secret = 'your_new_sk'

Use CnchS3 table function

Write data

Syntax

INSERT INTO FUNCTION CnchS3(
    'http://....' or 'https://', 
    'column1 type1, column2 type2, ...',
    'FORMAT',
    'COMPRESSION',
    'access_key_id', 
    'secret_access_key'
) VALUES (value1_1, value1_2, ...),    
    (value2_1, value2_2, ...),  
    (...);

Parameter name

Required

Description

FUNCTION

Yes

The table function is specified as CnchS3.

'http://....' or 'https://'

Yes

Specify the path of the source table in object storage.

  • 'http://....' or 'https://': Specify the data source path. For example:

    https://bucket.endpoint/file_path/file
    
  • If you are using TOS, you can view and copy the URL via TOS Console > Bucket List > Bucket Name > File List > the details button next to the file name, and replace the domain name with the S3 Endpoint domain name. For more information, see BytePlus TOS supported regions and access domain names. Example:

    https://{bucket_name}.tos-s3-{region}.volces.com/file_path/file
    

column1 type1, column2 type2, ...

Yes

Specify the target columns and column types for writing data. Example: city String, name String.

FORMAT

Yes

Specify the file format of the source table data. Please fill in according to your file format. For the file formats currently supported by ByteHouse, see Related reference: File formats supported by the CnchS3 table engine.

COMPRESSION

Yes

Specify the compression format for the S3 external table. Currently, gzip, zstd, lz4, snappy, bzip2, xz, and brotli compression formats are supported, and you can also set it to none. If not specified, the system will infer the format from the file suffix.

access_key_id

Yes

The Access Key ID of the object storage service. You can refer to the official documentation of your object storage service to obtain the Access Key ID. If you are using BytePlus TOS, refer to Access Key (key) management.

secret_access_key

Yes

The Secret Access Key of the object storage service. You can refer to the official documentation of your object storage service to obtain the Secret Access Key. If you are using BytePlus TOS, refer to Access Key (key) management.

VALUES

Yes

Specify the data to be written.

Example

INSERT INTO FUNCTION
    CnchS3(
        'http://bucket_endpoint/bucket/normal_write.csv', 
        'name String, id String',
        'CSV',
        'none',
        'your_access_key_id', 
        'your_secret_access_key'
     ) VALUES ('one', '1'), 
     ('two', '2'), 
     ('three', '3');

Partition-level write data

The syntax for partition-level data writing is the same as normal data writing, but the object storage path must contain the '{_partition_id}' field. For other parameters, please refer to the parameter description above.
Examples are as follows:

INSERT INTO FUNCTION
    CnchS3(
       'http://bucket_endpoint/bucket/{_partition_id}_partition_write.csv', 
       'name String, id String',
       'CSV',
       'none',
        'your_access_key_id', 
        'your_secret_access_key'
       )
PARTITION BY 
    name VALUES ('one', '1'),
    ('one', '2'),
    ('two', '1'),
    ('two', '2');

Query data

Use the CnchS3 function to directly query S3 external tables.
Syntax

SELECT *
FROM
    CnchS3(
        ''http://....' or 'https://',
        'column1 type1, column2 type2, ...',
        '[FORMAT]',
        '[COMPRESSION]',
        'access_key_id', 
        'secret_access_key'
    )
[WHERE where_clause];

Parameter

Required

Configuration description

CnchS3

Yes

Specify the table function as CnchS3.

'http://....' or 'https://'

Yes

Specify the path of the source table in object storage.

  • 'http://....' or 'https://': Specify the data source path. Example:

    https://bucket.endpoint/file_path/file
    
  • If you are using TOS, you can view and copy the URL via TOS Console > Bucket List > Bucket Name > File List > the details button next to the file name, and replace the domain name with the S3 Endpoint domain name. For more information, see BytePlus TOS supported regions and access domain names. Example:

    https://{bucket_name}.tos-s3-{region}.volces.com/file_path/file
    

column1 type1

Yes

Specify the table structure of the S3 external table. It must be consistent with the source table, including column names and column types. Example: id UInt32, name String.

[FORMAT]

No

Optional configuration. Specify the file format of the S3 external table. Please fill in according to your file format. For the file formats currently supported by CnchS3, see Related reference: File formats supported by the CnchS3 table engine.

[COMPRESSION]

No

Optional configuration. Currently, gzip, zstd, lz4, snappy, bzip2, xz, and brotli compression formats are supported, and you can also set it to none. If not specified, the system will infer the format from the file suffix.

[WHERE]

No

Specify filter conditions. ByteHouse S3 external tables support pruning queries by _path and _file.

Example

  • Query a single file

    SELECT *
    FROM
        CnchS3(
            'http://bucket_endpoint/bucket/fileSample.csv',
            'city String, name String',
            'CSV',
            'none',
            'your_access_key_id', 
            'your_secret_access_key'
        );
    
  • Use wildcard character to query multiple files and perform pruning queries

    SELECT *
    FROM
        CnchS3(
            'http://bucket_endpoint/bucket/fileSample.csv',
            'city String, name String',
            'CSV',
            'none',
            'your_access_key_id', 
            'your_secret_access_key'
        )
    WHERE
        _path LIKE '%test%';
    

File format

Read

Write

TabSeparated

✅

✅

TabSeparatedRaw

✅

❌

TabSeparatedWithNames

✅

✅

TabSeparatedWithNamesAndTypes

✅

❌

CSV

✅

✅

CSVWithNames

✅

✅

CustomSeparated

✅

❌

JSON

❌

✅

JSONCompact

❌

✅

JSONEachRow

✅

✅

JSONObjectEachRow

❌

✅

TSKV

✅

✅

Pretty

❌

✅

PrettyCompact

❌

✅

PrettyCompactNoEscapes

❌

✅

PrettyCompactMonoBlock

❌

✅

PrettySpace

❌

✅

PrettySpaceNoEscapes

❌

✅

Protobuf

✅

✅

Parquet

✅

✅

RowBinary

✅

✅

RowBinaryWithNamesAndTypes

✅

✅

Native

✅

✅

XML

❌

✅

CapnProto

✅

❌

Last updated: 2026.03.31 10:32:37