Table is the unit for storing data in MaxCompute. You must process data in MaxCompute based on tables. This topic describes how to create tables in MaxCompute.
Prerequisites
- The MaxCompute client is started.
For more information about how to start the MaxCompute client, see Start the MaxCompute client.
- A CSV or TXT file that contains the data you want to import is prepared.
The following sample files are used in this topic:
- The file that is used to create a non-partitioned table: banking.txt.
- The files that are used to create a partitioned table: banking_nocreditcard.csv, banking_uncreditcard.csv, and banking_yescreditcard.csv.
- The RAM user that you want to use to create tables is granted the CREATE TABLE permission.
If you want to use your Alibaba Cloud account to create tables, ignore this requirement.
For more information about how to check the permissions of a RAM user, see View permissions of a specified user.
For more information about how to grant permissions to a RAM user, see Authorize users.
Usage notes
The data types of the columns in the table that you want to create must be consistent with the data types of the columns in the data files. If they are inconsistent, data cannot be imported to the table.
Step 1: Design tables
Determine the table type, table structure, and data type of each column based on the content of the data that you want to import and the expected result data.
The sample files used in this topic contain the following data of mortgagors:
-- Data that is used to create a non-partitioned table.
44,blue-collar,married,basic.4y,unknown,yes,no,cellular,aug,thu,210,1,999,0,nonexistent,1.4,93.444,-36.1,4.963,5228.1,0
53,technician,married,unknown,no,no,no,cellular,nov,fri,138,1,999,0,nonexistent,-0.1,93.2,-42,4.021,5195.8,0
28,management,single,university.degree,no,yes,no,cellular,jun,thu,339,3,6,2,success,-1.7,94.055,-39.8,0.729,4991.6,1
-- Data that is used to create a partitioned table.
53,technician,married,unknown,no,no,cellular,nov,fri,138,1,999,0,nonexistent,-0.1,93.2,-42,4.021,5195.8,0
28,management,single,university.degree,yes,no,cellular,jun,thu,339,3,6,2,success,-1.7,94.055,-39.8,0.729,4991.6,1
39,services,married,high.school,no,no,cellular,apr,fri,185,2,999,0,nonexistent,-1.8,93.075,-47.1,1.405,5099.1,0
You can count the number of columns, identify the data type of each column, and name each column based on the meaning of each column of data. The following table describes the information that you can obtain from the sample files.
Item | Description |
---|---|
Number of columns | Count the number of columns in each sample file and determine the number of columns
in the table that you want to create:
|
Fields of the table | Identify the fields in each sample file and determine the fields in the table that
you want to create:
|
Data types | Identify the data type of each column in the sample files:
|
Step 2: Create tables
Create a non-partitioned table named bank_data and a partitioned table named bank_data_pt based on the sample files to store business data. Create non-partitioned tables named result_table1 and result_table2 to store result data. For more information about operations on tables and partitions, see Table operations and Partition and column operations. Perform the following operations to create the tables:
Step 3: Check the table creation results
Perform the following operations to check whether the tables are created and whether the table schemas are correct:
What to do next
After you create the tables and confirm that the table schemas are correct, you can import data in the sample files to the tables. For more information about how to import data, see Import data to tables.