全部產品
Search
文件中心

ApsaraDB for ClickHouse:從MaxCompute外表匯入(19.15.2.2)

更新時間:Jun 30, 2024

本節主要介紹如何在雲資料庫ClickHouse(核心版本為19.15.2.2)中使用阿里雲MaxCompute外表方式匯入資料。

資料匯入

  1. 登入ClickHouse目標資料庫,建立外部表格。
    文法如下:
    CREATE TABLE <table_name> [on cluster default]
    (
    'col_name' col_type,[col_name col_type]
    )
    ENGINE = MaxCompute('<tunnel-endpoint>', '<project-name>', '<table-name>', '<partition-spec>', '<access-key-id>', '<access-key-secret>');
    參數名描述
    table_name自訂外部表格名。
    'col_name' col_type列名,列類型。

    建表時,ClickHouse的列類型,應該與MaxCompute列類型具有對應關係,請參見類型映射

    ENGINE = MaxCompute表示該表是外部表格,使用的儲存引擎是MaxCompute。
    tunnel-endpointMaxCompute的EndPoint(網域名稱節點)。
    說明 為了確保ClickHouse後端節點與您的MaxCompute服務之間網路通暢, tunnel-endpoint 必須是VPC網路類型的endpoint,且MaxCompute必須與您的ClickHouse執行個體在同一地區,比如都在上海Region。查看MaxCompute tunnel endpoint地址請參見Endpoint
    project-nameMaxCompute中資料來源所在的專案名。
    說明 必須完全與MaxCompute中的名稱保持一致。
    table-nameMaxCompute中資料來源所在的表名。
    說明 必須完全與MaxCompute中的名稱保持一致。
    partition-spec希望訪問的MaxCompute分區。

    需要指定特定分區,在多個分區運算式之間不能有空格,且不要包含單引號,比如正確的樣本為: sale_date=2020-09-01,region=beijing

    access-key-id您在訪問MaxCompute上的資料來源時所持有的AccessKey ID。
    說明 必須對MaxCompute中目標資料相應的專案、表有讀取許可權。
    access-key-secret您在訪問MaxCompute上的資料來源時所持有的AccessKey Secret。
    樣本
    CREATE TABLE default.odps_src_tbl on cluster default
    (
        `shop_name` String,
        `customer_id` String,
        `total_price` Float64
    )
    ENGINE = MaxCompute('http://dt.cn-shanghai.maxcompute.aliyun-inc.com', 'test_project', 'test_tbl', 'sale_date=2020-09-01,region=beijing', '<your-access-key-id>', '<your-access-key-secret>');
  2. 建立目標表。
    CREATE TABLE default.odps_dst_tbl_local on cluster default
    (
        `shop_name` String,
        `customer_id` String,
        `total_price` Float64
    )
    ENGINE= MergeTree()
    ORDER BY customer_id;
    
    CREATE TABLE default.odps_dst_tbl_dist on cluster default
    as default.odps_dst_tbl_local
    ENGINE= Distributed(default, default, odps_dst_tbl_local, rand());
  3. 將外部表格中資料匯入目標表。
    insert into odps_dst_tbl_dist select * from odps_src_tbl;

類型映射

MaxCompute類型ClickHouse類型
booleanUInt8
tinyintUInt8, Int8
smalllintUInt16, Int16
intUInt32, Int32
bigintUInt64, Int64
floatFloat32
doubleFloat64
charString
varcharString
binaryString
stringString
dateUInt16
datetimeUInt32
UUID暫不支援
INTERVAL暫不支援
Decimal暫不支援
Timestamp暫不支援
複合資料型別暫不支援