Migrate MaxCompute data

更新时间:
复制 MD 格式

Use a MaxCompute catalog to import offline data from MaxCompute into ApsaraDB for SelectDB for analysis.

Prerequisites

Before you begin, make sure that you have:

Example environment

The following example migrates the bank_data table from MaxCompute into a SelectDB table named test_mc2SelectDB in the mc_db database.

RoleValue
Source tablebank_data
Destination databasemc_db
Destination tabletest_mc2SelectDB

Step 1: Create a MaxCompute catalog

Run the following statement to create a catalog that connects to your MaxCompute project:

CREATE CATALOG mc PROPERTIES (
  "type"               = "max_compute",
  "mc.region"          = "cn-beijing",
  "mc.default.project" = "your-project",
  "mc.access_key"      = "your-access-key-id",
  "mc.secret_key"      = "your-access-key-secret"
);

Replace the placeholder values as described in the following table:

ParameterRequiredDescription
mc.regionYesThe region where your MaxCompute project resides. Find the region from the MaxCompute endpoint. For details, see Endpoints.
mc.default.projectYesThe name of your MaxCompute project. For details, see Create a MaxCompute project.
mc.access_keyYesYour AccessKey ID.
mc.secret_keyYesYour AccessKey secret.
mc.public_accessNoSet to true to access MaxCompute over the Internet. In this case, risks may occur. We recommend that you disable Internet access in production environments.

Verify the catalog was created:

SHOW CATALOGS;

The output should include the new mc catalog with type max_compute:

CatalogId       CatalogName  Type         IsCurrent  CreateTime                   LastUpdateTime  Comment
0               internal     internal     Yes                                                      Doris internal catalog
175854218****   mc           max_compute  No         2025-09-24 11:26:27.552259510
Note

SelectDB supports only read operations on data in external catalogs. To query MaxCompute data directly without migrating it, switch to the mc catalog using SWITCH mc;. Switch back to the internal catalog using SWITCH internal;. For query syntax, see Query syntax.

Step 2: Create the destination database and table

Create the destination database and switch to it:

CREATE DATABASE mc_db;
USE mc_db;

Create the destination table. Column data types must correspond to their MaxCompute counterparts. For the mapping, see Column type mapping.

CREATE TABLE test_mc2SelectDB
(
    age             BIGINT COMMENT 'Age',
    job             VARCHAR(255) COMMENT 'Job type',
    marital         VARCHAR(255) COMMENT 'Marital status',
    education       VARCHAR(255) COMMENT 'Education level',
    credit          VARCHAR(255) COMMENT 'Has credit card',
    housing         VARCHAR(255) COMMENT 'Has housing loan',
    loan            VARCHAR(255) COMMENT 'Has personal loan',
    contact         VARCHAR(255) COMMENT 'Contact method',
    month           VARCHAR(255) COMMENT 'Month',
    day_of_week     VARCHAR(255) COMMENT 'Day of the week',
    duration        VARCHAR(255) COMMENT 'Duration',
    campaign        BIGINT COMMENT 'Number of contacts performed during this campaign',
    pdays           DOUBLE COMMENT 'Interval since the last contact',
    previous        DOUBLE COMMENT 'Number of contacts performed before this campaign',
    poutcome        VARCHAR(255) COMMENT 'Outcome of the previous marketing campaign',
    emp_var_rate    DOUBLE COMMENT 'Employment variation rate',
    cons_price_idx  DOUBLE COMMENT 'Consumer price index',
    cons_conf_idx   DOUBLE COMMENT 'Consumer confidence index',
    euribor3m       DOUBLE COMMENT 'Euribor 3 month rate',
    nr_employed     DOUBLE COMMENT 'Number of employees',
    fixed_deposit   BIGINT COMMENT 'Has time deposit'
)
DISTRIBUTED BY HASH(age) BUCKETS 10
PROPERTIES (
    "replication_num" = "1"
);

Step 3: Migrate the data and verify consistency

Insert all rows from the MaxCompute source table into the SelectDB destination table. Replace <yourProject> with your MaxCompute project name:

INSERT INTO test_mc2SelectDB SELECT *  FROM mc.<yourProject>.bank_data;

After the migration completes, run aggregate queries on both tables and compare the results to confirm data consistency.

Check the row count in the destination table:

SELECT COUNT(*) FROM test_mc2SelectDB;

Run additional checks such as SUM on numeric columns to verify that values match those in the source table.

What's next

  • To query MaxCompute data without migrating it, switch to the external catalog and run queries directly. See Query syntax.

  • To understand how MaxCompute and SelectDB column types map to each other, see Column type mapping.