すべてのプロダクト
Search
ドキュメントセンター

ApsaraDB for ClickHouse:外部テーブルを使用してMaxComputeからApsaraDB for ClickHouseにデータをインポートする (V 19.15.2.2)

最終更新日:Oct 17, 2024

このトピックでは、外部テーブルを使用してMaxComputeデータをApsaraDB for ClickHouseクラスターにインポートする方法について説明します。 クラスターのカーネルバージョンは19.15.2.2です。

MySQL からのデータインポート

  1. ターゲットApsaraDB for 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

    列の名前とデータ型。

    ApsaraDB for ClickHouseの列のデータ型は、MaxComputeの列のデータ型にマッピングする必要があります。 詳細については、「MaxComputeとApsaraDB For ClickHouse間のデータ型マッピング」をご参照ください。

    エンジン=MaxCompute

    外部テーブルに使用されるMaxComputeストレージエンジン。

    tunnel-endpoint

    MaxComputeのエンドポイント。

    説明

    ApsaraDB for ClickHouseクラスターとMaxCompute間の接続を確保するには、tunnel-endpointの値がVPCエンドポイントであり、MaxComputeがApsaraDB for ClickHouseクラスターと同じリージョンにデプロイされている必要があります。 たとえば、MaxComputeおよびApsaraDB For ClickHouseクラスターは中国 (上海) リージョンにデプロイされています。 MaxComputeのトンネルエンドポイントについては、「エンドポイント」をご参照ください。

    プロジェクト名

    インポートするデータを含むMaxComputeプロジェクトの名前。

    説明

    プロジェクト名は、MaxComputeで使用されるプロジェクト名と同じである必要があります。

    テーブル名

    インポートするデータを含むMaxComputeテーブルの名前。

    説明

    テーブル名は、MaxComputeで使用されるテーブル名と同じである必要があります。

    partition-spec

    アクセスするMaxComputeパーティション。

    パーティションを指定する必要があります。 複数のパーティションを指定する式には、スペースまたは単一引用符 (') を含めることはできません。 例: sale_date=2020-09-01,region=beijing

    access-key-id

    データへのアクセスに使用されるアカウントのAccessKey ID。

    説明

    アカウントには、MaxComputeプロジェクトとMaxComputeテーブルに対する読み取り権限が必要です。

    {access-key-secret}

    MaxComputeテーブルへのアクセスに使用されるアカウントのAccessKeyシークレット。

    クラスターのデフォルトのCREATE TABLEの

    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とApsaraDB for ClickHouse間のデータ型マッピング

MaxComputeのデータ型

ApsaraDB for ClickHouseのデータ型

Boolean

UInt8

tinyint

UInt8、Int8

smalllint

UInt16、Int16

int

UInt32、Int32

bigint

UInt64、Int64

float

Float32

double

Float64

char

String

varchar

String

binary

String

String

String

date

UInt16

datetime

UInt32

UUID

非対応

INTERVAL

非対応

小数点

非対応

Timestamp

非対応

複合データ型

非対応