This topic describes how to use the MaxCompute client and the Tunnel Upload command to import data from a local data file into an existing table.
Prerequisites
Confirm that the following prerequisites are met:- A table has been created.
For more information, see Create a table.
- A CSV or TXT data file has been downloaded to your local computer.The following sample data files are used in this topic:
- Data file for a non-partitioned table: banking.txt.
- Data files for a partitioned table: banking_nocreditcard.csv, banking_uncreditcard.csv, and banking_yescreditcard.csv.
Step 1: Import data
You can use the Tunnel Upload command to import data from a local file into a MaxCompute table. For more information about Tunnel operations, see Tunnel commands. The import process is as follows:
- Confirm the path of the data file.
There are two options for the data file path. If you save the file in the
binfolder of the MaxCompute client, the upload path isfilename.extension. If you save the file to another path, such as the test folder on drive D, the upload path isD:\test\filename.extension.In this topic, the
banking.txtsample data file is saved in thebinfolder of the MaxCompute client. Thebanking_yescreditcard.csv,banking_uncreditcard.csv, andbanking_nocreditcard.csvfiles are saved in the test folder on drive D. - On the MaxCompute client, run the Tunnel Upload command to import the data.
The following commands are examples.
The import is complete when OK is displayed.tunnel upload banking.txt bank_data; tunnel upload D:\test\banking_yescreditcard.csv bank_data_pt/credit="yes"; tunnel upload D:\test\banking_uncreditcard.csv bank_data_pt/credit="unknown"; tunnel upload D:\test\banking_nocreditcard.csv bank_data_pt/credit="no";odps@ doc_test_dev>tunnel upload D:\test\banking_yescreditcard.csv bank_data_pt/credit="yes", Upload session: 202105171550120131f60b242a2417 Start upload:D:\test\banking_yescreditcard.csv Using \r\n to split records Upload in strict schema mode: true Total bytes:351 Split input to 1 blocks 2021-05-17 15:47:58 scan block: '1' 2021-05-17 15:47:58 scan block complete, block id: 1 2021-05-17 15:47:58 upload block: '1' 2021-05-17 15:47:59 upload block complete, block id: 1 upload complete, average speed is 351 bytes/s OK
Step 2: Confirm the import result
After the data is imported, verify that the number of records in the destination table matches the number of records in the data file. This confirms that all data was imported successfully.
In this topic, the sample data file banking.txt contains 41,188 records. The banking_yescreditcard.csv, banking_uncreditcard.csv, and banking_nocreditcard.csv files contain 3, 8,597, and 32,588 records, respectively. The following command provides an example.
select count(*) as num1 from bank_data;
select count(*) as num2 from bank_data_pt where credit="yes";
select count(*) as num3 from bank_data_pt where credit="unknown";
select count(*) as num4 from bank_data_pt where credit="no";
The following results are returned.
--The number of records in bank_data.
+------------+
| num1 |
+------------+
| 41188 |
+------------+
--The number of records in bank_data_pt where credit is "yes".
+------------+
| num2 |
+------------+
| 3 |
+------------+
--The number of records in bank_data_pt where credit is "unknown".
+------------+
| num3 |
+------------+
| 8597 |
+------------+
--The number of records in bank_data_pt where credit is "no".
+------------+
| num4 |
+------------+
| 32588 |
+------------+
If the results returned by the preceding commands match the number of records in the sample data files, the import is successful.
What to do next
After data is imported into a MaxCompute table, you can run SQL commands on the MaxCompute client to process the data and export the results. For more information, see Run SQL commands and export the result data.