In big data application scenarios, data tables in Hive usually need to be migrated to another cluster. You can run the Hive import and export commands to migrate data in tables. That is, you can run the export command to export Hive tables from the source cluster to the HDFS of the target cluster, run the import command in the target cluster to import the exported data to the corresponding Hive table.
This section applies to MRS 3.2.0 or later.
The Hive table import and export function does not support importing or exporting encrypted tables, HBase external tables, transaction tables, Hudi tables, view tables, and materialized view tables.
Log in to FusionInsight Manager of the source cluster, click Cluster, choose Services > Hive, and click Configuration. On the displayed page, search for hdfs.site.customized.configs, add custom parameter dfs.namenode.rpc-address.haclusterX, and set its value to Service IP address of the active NameNode instance node in the destination cluster:RPC port. Add custom parameter dfs.namenode.rpc-address.haclusterX1 and set its value to Service IP address of the standby NameNode instance node in the destination cluster:RPC port. The RPC port of NameNode is 25000 by default. After saving the configuration, roll-restart the Hive service.
cd /opt/client
source bigdata_env
kinit Hive service user
beeline
create table export_test(id int) ;
insert into export_test values(123);
dfs -mkdir /tmp/export
beeline
The Hive import and export commands can be used to migrate table data in the following modes. Select a proper data migration mode as required.
export table export_test to 'hdfs://haclusterX/tmp/export';
import from '/tmp/export';
export table export_test to 'hdfs://haclusterX/tmp/export';
import table import_test from '/tmp/export';
export table export_test partition (pt1="in", pt2="ka") to 'hdfs://haclusterX/tmp/export';
import from '/tmp/export';
export table export_test to 'hdfs://haclusterX/tmp/export';
import table import_test partition (pt1="us", pt2="tn") from '/tmp/export';
export table export_test to 'hdfs://haclusterX/tmp/export';
import table import_test from '/tmp' location '/tmp/export';
export table export_test to 'hdfs://haclusterX/tmp/export';
import external table import_test from '/tmp/export';
Before exporting table or partition data, ensure that the HDFS path for storage has been created and is empty. Otherwise, the export fails.
When partitions are exported or imported, the exported or imported table must be a partitioned table, and data of multiple partition values of the same partition field cannot be exported.
hacluster X is the value of haclusterX in new custom parameterdfs.namenode.rpc-address.haclusterX.