This topic describes how to import data to ApsaraDB for ClickHouse using a MaxCompute external table.
Notes
-
The kernel version of your ApsaraDB for ClickHouse Community-Compatible cluster must be 20.3 or later.
-
MaxCompute is a paid service. For more information about billing methods, see MaxCompute billing methods.
-
To ensure a stable network connection between ApsaraDB for ClickHouse and MaxCompute, use an Alibaba Cloud VPC. The MaxCompute service and your ApsaraDB for ClickHouse cluster must be in the same region.
Prerequisites
-
The MaxCompute service is activated. For more information, see Activate MaxCompute.
-
A MaxCompute project is created in the same region as your ApsaraDB for ClickHouse cluster. For more information, see Create a MaxCompute project.
-
If a Resource Access Management (RAM) user needs to use MaxCompute, an Alibaba Cloud account holder must grant the required permissions to the RAM user. For more information, see Prepare a RAM user.
Procedure
-
Create a MaxCompute external table.
-
Log on to the MaxCompute console.
-
In the navigation pane on the left, choose .
-
On the Data Studio page, hover over the
icon, and choose . -
In the New Table dialog box, enter a Table Name. This topic uses maxcompute as an example.
-
Click Create.
-
In the Basic Properties section, configure the parameters.

The following table describes the parameters.
Configuration item
Description
Display Name
The display name of the table.
Theme
A subject in DataWorks is equivalent to a folder. Define the level-1 and level-2 folders for the table. You can classify tables based on business purposes and attach tables of the same type to the same folder.
NoteThe level-1 and level-2 Theme are presented as folders for table management in DataWorks to help you better manage tables. You can quickly find the current table by subject on the Table Management page. If no subject is available, you can create one. For more information, see Define table subjects.
-
In the toolbar, click DDL.
-
In the DDL dialog box, enter the following statement to create the table, and then click Generate Table Schema.
CREATE TABLE IF NOT EXISTS maxcompute ( v1 INT, v2 INT ) PARTITIONED BY ( v3 STRING ); -
Click Submit to Development Environment and Submit to Production Environment.
-
-
Write data to the MaxCompute external table.
-
On the Data Studio page, click Ad-hoc Query in the navigation pane on the left.
-
Hover over the
icon, and choose . -
In the New Node dialog box, select a Path and enter a Name.
-
Click Confirm.
-
On the node editing page, enter the following statement to write data to the MaxCompute external table.
insert into maxcompute PARTITION (v3='2021') values (1,2),(2,3); -
In the toolbar, click the
icon. -
In the Parameters window, select shared resource groups for scheduling and click OK.
-
In the MaxCompute Compute Cost Estimate window, confirm the Estimated Fee and click Run.
-
-
Create an ApsaraDB for ClickHouse table.
-
Log on to the ApsaraDB for ClickHouse console.
-
On the Clusters page, click the ID of the destination cluster.
-
In the upper-right corner of the navigation bar, click Log On to Database.
-
Enter a statement to create the table and click Execute (F8).
The syntax for creating a table is as follows.
CREATE TABLE <table_name> [on cluster default] ( 'col_name1' col_type1, 'col_name2' col_type2, ... ) ENGINE = MaxCompute('<tunnel-endpoint>', '<project-name>', '<table-name>', '<partition-spec>', '<access-key-id>', '<access-key-secret>',<read-thread-num>, '<quota>');NoteIf you use the MaxComputeRaw table engine, change
tunnel-endpointtoodps-endpointin the syntax. The odps-endpoint parameter specifies the VPC endpoint. For more information about how to obtain the VPC endpoint, see Endpoint.The following table describes the parameters.
Parameter name
Description
table_nameThe table name.
col_name1,col_name2The column names.
col_type1,col_type2The column types.
NoteThe schema of the ApsaraDB for ClickHouse table must correspond to the MaxCompute table. For more information about the data type mappings, see Data type mapping.
tunnel-endpointThe Tunnel Endpoint of the Tunnel service.
To ensure a stable network connection between ApsaraDB for ClickHouse and MaxCompute, use an Alibaba Cloud VPC. The MaxCompute service and your ApsaraDB for ClickHouse cluster must be in the same region.
NoteFor more information about how to view the
tunnel-endpointfor the VPC, see Endpoint.project-nameThe name of the MaxCompute project.
table-nameThe name of the MaxCompute external table.
partition-specThe MaxCompute partition.
access-key-idThe AccessKey ID used to access the MaxCompute project.
access-key-secretThe AccessKey secret used to access the MaxCompute project.
read-thread-num(Optional)The number of concurrent threads for reading a single shard of a MaxCompute table. The default value is 1.
quota(Optional)The unit of MaxCompute compute resources. By default, a shared quota is used.
The statement to create the table is as follows.
CREATE TABLE default.maxcomputetest ON CLUSTER default ( v1 Int32, v2 Int32 ) ENGINE = MaxCompute('http://dt.cn-hangzh******.aliyun-inc.com', 'ckfwt', 'maxcompute', 'v3=2021', 'LTAI****************', 'yourAccessKeySecret');
-
-
Query the ApsaraDB for ClickHouse table.
-
Log on to the ApsaraDB for ClickHouse console.
-
On the Clusters page, click the ID of the destination cluster.
-
In the upper-right corner of the navigation bar, click Log On to Database.
-
Enter a query statement and click Execute (F8).
SELECT * FROM maxcomputetest;The query results are as follows.

-
Data type mapping
|
MaxCompute type |
ClickHouse type |
|
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 |
Date |
|
Datetime |
Datetime |
|
UUID |
Not supported |
|
INTERVAL |
Not supported |
|
Decimal |
String |
|
Timestamp |
Not supported |
|
Map |
Nested(Nullable(keyType), Nullable(valueType)). Only single-level, non-nested Map structures are supported. For example, map<string, string> in MaxCompute corresponds to Nested(k Nullable(String), v Nullable(String)) in ApsaraDB for ClickHouse. Note
The types within Nested must be Nullable. Otherwise, an error occurs when you create the table. |
|
Array |
Array(Nullable(Type)). Only single-level, non-nested Array structures are supported. For example, array<int> in MaxCompute corresponds to Array(Nullable(Int32)) in ApsaraDB for ClickHouse. Note
The type within Array must be Nullable. Otherwise, an error occurs when you create the table. |
|
Struct |
Tuple(Nullable(Type)). Only single-level, non-nested Struct structures are supported. For example, struct<x:int, y:string> in MaxCompute corresponds to Tuple(Nullable(Int32), Nullable(String)) in ApsaraDB for ClickHouse. Note
The types within Tuple must be Nullable. Otherwise, an error occurs when you create the table. |