This migration guides you to migrate the CarbonData table data of Spark 1.5 to that of Spark2x.
Before performing this operation, you need to stop the data import service of the CarbonData table in Spark 1.5 and migrate data to the CarbonData table of Spark2x at a time. After the migration is complete, use Spark2x to perform service operations.
Migration roadmap:
Migrating Historical Data
show segments for table dbname.tablename;
Create an ORC table.
CREATE TABLE dbname.mid_tablename_orc STORED AS ORC as select * from dbname.tablename;
Create a Parquet table.
CREATE TABLE dbname.mid_tablename_parq STORED AS PARQUET as select * from dbname.tablename;
In the preceding command, dbname indicates the database name and tablename indicates the name of the original CarbonData table.
In the statement for creating a new table, the field sequence and type must be the same as those of the old table. In this way, the index column structure of the old table can be retained, which helps avoid errors caused by the use of select * statement during data insertion.
Run the spark-beeline command of Spark 1.5 to view the table creation statement of the old table: SHOW CREATE TABLE dbname.tablename;
Create a CarbonData table named dbname.new_tablename.
insert into dbname.new_tablename select *
from dbname. mid_tablename_orc;
ALTER TABLE dbname.tablename RENAME TO dbname.old_tablename;
ALTER TABLE dbname.new_tablename RENAME TO dbname.tablename;