This topic describes how to use the CLONE TABLE feature to migrate data between MaxCompute projects in the same region. This topic covers two scenarios: data migration between projects under the same Alibaba Cloud account and data migration between projects under different Alibaba Cloud accounts.
Feature introduction
The CLONE TABLE feature lets you efficiently copy data from a source table to a destination table. After you copy the data, perform data validation to ensure data accuracy. For example, you can run the select command to view the table data or run the desc command to view the table size.
Limits
Schema Compatibility: The schema of the destination table must be compatible with that of the source table.
Table Types: Supports partitioned tables, non-partitioned tables, and clustered tables.
Partition Limit:
If the destination table exists: Maximum 10,000 partitions per operation.
If the destination table does not exist: No partition limit (atomic operation).
Cross-Region/Cluster: Data replication between MaxCompute projects across different regions or clusters is not supported.
External Tables: Not supported.
Schema Evolution: Not supported for tables that have undergone schema evolution (such as adding or dropping columns).
Command format
clone table <[<src_project_name>.]<src_table_name>> [partition(<pt_spec>), ...] to <[<dest_project_name>.]<dest_table_name>> [if exists [overwrite | ignore]] ;For more information about the parameters and usage examples, see CLONE TABLE.
Data migration between different projects under the same Alibaba Cloud account in the same region
If you use an Alibaba Cloud account, you can run the clone command directly in the source project.
set odps.namespace.schema=false; --Clone the table from proejctA to projectB. clone TABLE projectA.<tablename> to projectB.<tablename> IF EXISTS OVERWRITE;If you use a Resource Access Management (RAM) user, confirm that the user has the
SELECTpermission on the source table in the source project and theCreateTableandCreateInstacnepermissions on the destination project. After the permissions are granted, you can run the clone command. For more information about authorization, see .
Data migration between projects under different Alibaba Cloud accounts in the same region
To migrate data between projects under different Alibaba Cloud accounts, add the Alibaba Cloud account of the destination project owner to the source project. Then, grant the CreateTable and CreateInstacne permissions on the source project to the account. Finally, you can use the CLONE TABLE feature to migrate data between the projects.
Add the Alibaba Cloud account of the destination project owner to the source project and grant permissions.
--Enter the source project projectA. use projectA; --Add the Alibaba Cloud account of the destination project (projectB) owner (projectB_owner@aliyunid.com) to the source project (projectA). add user ALIYUN$projectB_owner@aliyunid.com; --Grant the CreateTable and CreateInstacne permissions on the source project projectA to the user ALIYUN$projectB_owner@aliyunid.com. grant CreateTable,CreateInstance on project projectA to user ALIYUN$projectB_owner@aliyunid.com; --Grant the Select permission on the source table to the user ALIYUN$projectB_owner@aliyunid.com. grant Select on table <tablename> to user ALIYUN$projectB_owner@aliyunid.com;For more information about adding an Alibaba Cloud account, see Add an Alibaba Cloud account user (project level). For more information about authorization, see Grant permissions to a user.
Run the clone command in the destination project.
Because cross-account operations are always performed by an Alibaba Cloud account, the account has all data permissions in the destination project by default. No separate authorization is required.
use projectB; --Clone the table from proejctA to projectB. clone TABLE projectA.<tablename> to projectB.<tablename> IF EXISTS OVERWRITE;Confirm that the table data is migrated successfully in the destination project.
select * from <tablename> limit 2;ImportantAfter the data migration is complete, promptly remove the Alibaba Cloud account of the destination project owner from the source project to ensure data security. For more information about removing an account, see Delete an Alibaba Cloud account user (project level).