This topic describes how to use MaxCompute to analyze data concerning house buyers with bank loans. After you purchase a MaxCompute project with your Alibaba Cloud account, you are added to the project and authorized to create a table. Afterwards, you can complete client configurations on your local PC and operate MaxCompute.

Note If you are using MaxCompute for the first time, be sure to complete all preparations before you get started.

The MaxCompute quick start guide describes how to use the MaxCompute client and MaxCompute Studio to create tables and how to upload, process, and export data. Alternatively, you can use DataWorks to perform these operations. For more information, see DataWorks quick start.

In MaxCompute, the basic operations (input and output) objects are tables, so you need to create tables and partitions before processing data. You can use any of the following methods to create, view, and delete tables:
The following describes how to use the MaxCompute client to create and view a table.

Create a table

Log on to the MaxCompute client, and then create a table by running the following command:
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]
                    CREATE TABLE [IF NOT EXISTS] table_name 
                    LIKE existing_table_name
Note For more information, see Table operations.

After logging on to the MaxCompute client, you need to confirm that you are in the correct project. In this example, the project name is MaxCompute_DOC, so you can run use MaxCompute_DOC; to switch to the project.

In this example, the bank_data table is used to store service data, and the result_table table is used to store data processing results.

Create the bank_data table by running the following command:
CREATE TABLE IF NOT EXISTS bank_data
                (
                age             BIGINT COMMENT 'age',
                job             STRING COMMENT 'job type',
                marital         STRING COMMENT 'marital status',
                education       STRING COMMENT 'educational level',
                default         STRING COMMENT 'credit card ownship',
                housing         STRING COMMENT 'mortgate',
                loan            STRING COMMENT 'loan',
                contact         STRING COMMENT 'contact information',
                month           STRING COMMENT 'month',
                day_of_week     STRING COMMENT 'day of the week',
                duration        STRING COMMENT 'Duration',
                campaign        BIGINT COMMENT 'contact times during the campaign',
                pdays           DOUBLE COMMENT 'time interval from the last contact',
                previous        DOUBLE COMMENT 'previous contact times before this activity',
                poutcome        STRING COMMENT 'market activity results before this activity',
                emp_var_rate    DOUBLE COMMENT 'employment change 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 'whether a fixed deposit holder'
                );
The command output OK is displayed, as shown in the following figure.

Create the result_table table by running the following command:
CREATE TABLE IF NOT EXISTS result_table
                (  
                education   STRING COMMENT 'education level',
                num         BIGINT COMMENT 'number of people'
                );

View a table

Run desc <table_name>; to view information related to a table.

For example, you can run desc bank_data; to view information related to the bank_data table that was created in the previous step.

The following figure shows the command output.

For more information, see Table operations.

(Optional) Create a partition

The table used in this example is a non-partition table.

If you want to run the Tunnel command to import data of different partitions to a partition table, you must create a partition by running the following commands:
alter table table_name add [if not exists] partition partition(partition_col1 = partition_col_value1, partition_col2 = partiton_col_value2, ...);
You do not need to create an independent partition for different operations, such as data integration and insert operations.

(Optional) Delete a partition

Delete a partition by running the following command:
alter table table_name drop [if exists] partition(partition_col1 = partition_col_value1, partition_col2 = partiton_col_value2, ...);
For example, if you want to delete a partition with the date of 20180923 and region of hangzhou, run the following command:
alter table user drop if exists partition(region='hangzhou',dt='20180923');

(Optional) Delete a table

Create a table by running the following command:
DROP TABLE [IF EXISTS] table_name;

For more information, see Table operations.

What to do next

You can refer to Import data for data processing.