Quick Start shows you the complete process of using MaxCompute to analyze data of mortgagors. You can refer to the sample statements in each step to perform the related operations.
- Run common commands on the MaxCompute client.
- Use MaxCompute Studio. For more information, see Create, modify, and delete tables in a visualized manner.
- Use DataWorks. For more information, see Manage tables.
This topic describes how to create and view a table by using the MaxCompute client. For more information about how to install and configure the MaxCompute client, see Install and configure the MaxCompute client.
- An Alibaba Cloud account is created.
- MaxCompute is purchased.
- A project that you want to use is created. For more information, see Create a project. If the project that you want to use exists, make sure that your account has been added to the project and is granted the permission to create tables.
- The MaxCompute client is installed and configured.
- If you use MaxCompute for the first time, you must complete all the preparations before you get started.
- Quick Start describes how to create a table and upload, process, and export data by using the MaxCompute client and MaxCompute Studio. For more information about how to install and configure the MaxCompute client, see Install and configure the MaxCompute client. You can also use DataWorks to complete the preceding process. For more information, see DataWorks quick start.
Create a table
- Log on to the MaxCompute client.
Run ./bin/odpscmd in a Linux operating system or ./bin/odpscmd.bat in a Windows operating system. Check whether the name of the project that you access is correct. In this example, the project name is MaxCompute_DOC. If the name of the project that you access is not MaxCompute_DOC, run the following command to switch to this project:
If the information shown in the following figure is returned, the project is switched.
- Execute the following statement to create a table. For more information, see Table operations.
CREATE TABLE [IF NOT EXISTS] table_name [(col_name data_type [COMMENT col_comment], ...)] [COMMENT table_comment] [PARTITIONED BY (col_name data_type [COMMENT col_comment], ...)] [LIFECYCLE days] [AS select_statement]In this topic, the bank_data and result_table tables need to be created. The bank_data table stores business data, and the result_table table stores the results of data analytics.
- Statement for creating the bank_data table:
You can execute the preceding table creation statement. After you create the table, OK is displayed.
CREATE TABLE IF NOT EXISTS bank_data ( age BIGINT COMMENT 'Age', job STRING COMMENT 'Job type', marital STRING COMMENT 'Marital status', education STRING COMMENT 'Education level', default STRING COMMENT 'Credit card', housing STRING COMMENT 'Mortgage', loan STRING COMMENT 'Loan', contact STRING COMMENT 'Contact', month STRING COMMENT 'Month', day_of_week STRING COMMENT 'Day of the week', duration STRING COMMENT 'Duration', campaign BIGINT COMMENT 'Number of contacts during the campaign', pdays DOUBLE COMMENT 'Interval from the last contact', previous DOUBLE COMMENT 'Number of contacts with the customer', poutcome STRING COMMENT 'Result of the previous marketing campaign', emp_var_rate DOUBLE COMMENT 'Employment variance rate', cons_price_idx DOUBLE COMMENT 'Consumer price index', cons_conf_idx DOUBLE COMMENT 'Consumer confidence index', euribor3m DOUBLE COMMENT 'Euro deposit rate', nr_employed DOUBLE COMMENT 'Number of employees', y BIGINT COMMENT 'Time deposit available or not' );Note If an error is reported on the MaxCompute client, we recommend that you manually enter the SQL statement to execute it, or use the ad hoc query feature of DataWorks to execute the SQL statement. For more information, see (Optional) Use an ad-hoc query to run SQL statements.
- Statement for creating the result_table table:
CREATE TABLE IF NOT EXISTS result_table ( education STRING COMMENT 'Education level', num BIGINT COMMENT 'Number of persons' );
- Statement for creating the bank_data table:
View a table
table_name indicates the name of the table that you want to view. For example, you can run the
DESC bank_data;command to view the information of the bank_data table in the preceding example. The following figure shows the table information.
For more information about how to view the table information, see Table operations.
Other table operations
- Delete a table
Statement for deleting a table:
DROP TABLE [IF EXISTS] table_name;
- Create partitions
The tables in the preceding example are non-partitioned tables. If you want to use a partitioned table, execute the following statement to create partitions in the existing tables:
alter table table_name add [if not exists] partition(partition_col1 = partition_col_value1, partition_col2 = partiton_col_value2, ...) ;Note
- If you run Tunnel commands to import data into different partitions, you must create partitions first.
- If you use methods such as Data Integration of DataWorks or the INSERT statement to import partition data, you do not need to separately create partitions.
- Delete partitions
Statement for deleting partitions:
alter table table_name drop [if exists] partition(partition_col1 = partition_col_value1, partition_col2 = partiton_col_value2, ...) ;If you want to delete the partition in which the value of the region column is hangzhou and the value of the date column is 20180923, execute the following statement:
alter table user drop if exists partition(region='hangzhou',dt='20180923');
What to do next
After you create a table, you can import data to MaxCompute for further data processing. For more information about data import, see Import data.