This article describes how to use the basic functions of the MaxCompute with the help of client command line tool. Before using the MaxCompute client, first install and configure the client.
- Do not perform the analysis operation based on the output format of the client. The output format of the client is not ensured for forward compatibility. Clients in different versions are different in their command formats and behaviors.
- For more information about basic commands of the client, see Basic commands.
After the client is installed and configured, you can use a command line to perform the following operations.
To view the help information of the client, the command format is as follows:
odps@ >./bin/odpscmd -h;
You can also enter
help; (case-insensitive) in an interactive mode.
The client also provides the
help [keyword]; command to get the command prompts related to the keyword. For example, enter
help table; to get command prompts related to the table operation as follows:
odps@ odps> help table;
Usage: alter table <tablename> merge smallfiles
Usage: show tables [in <projectname>]
list|ls tables [-p,-project <projectname>]
Usage: describe|desc [<projectname>.]<tablename> [partition(<spec>)]
Usage: read [<project_name>.]<table_name> [(<col_name>[,..])] [PARTITION (<partition_spec>)] [line_num]
When start the client, you can specify a series of parameters as follows:
Usage: odpscmd [OPTION]...
where options include:
--help (-h)for help
--project=<prj_name> use project
--endpoint=<http://host:port> set endpoint
-u <user_name> -p <password> user name and password
-k <n> will skip begining queries and start from specified position
-r <n> set retry times
-f <"file_path;"> execute command in file
-e <"command;[command;]..."> execute command, include sql command
-C will display job counters
Take the -f parameter as an example, the operation is as follows:
- Prepare the local script file script.txt. Suppose that the file is located in the disk D, and the content is shown as follows:
DROP TABLE IF EXISTS test_table_mj;
CREATE TABLE test_table_mj (id string, name string);
DROP TABLE test_table_mj;
- Run the following command:
odpscmd\bin>odpscmd -f ./script.sql;
Run the client to directly enter the interactive mode:
Aliyun ODPS Command Line Tool
@Copyright 2012 Alibaba Cloud Computing Co., Ltd. All rights reserved.
odps@ odps> INSERT OVERWRITE TABLE DUAL SELECT * FROM DUAL;
Enter the command at the cursor position (use a semicolon as a statement terminator), and press Enter to run.
- When using -e or -f option to run command, if there are multiple statements, and you want to start running from a middle statement, you can specify the parameter -k, indicating to ignore the previous statements and to start running from the specified position. When the parameter <= 0 is specified, the execution starts from the first statement.
- Each statement separated by a semicolon is considered as a valid statement. The statements which run successfully or fail to run are printed out at runtime.
For example, suppose there are three SQL statements in the file /tmp/dual.sql:
drop table dual;
create table dual (dummy string);
insert overwrite table dual select count(*) from dual;
To ignore the first two statements, and start running from the third statement, the command format is as follows:
odpscmd –k 3 –f dual.sql
To get current logon user, the command format is as follows:
Use the preceding command to get the current logon user Alibaba Cloud account, endpoint configuration, and project name.
To exit the client, the command format is as follows:
odps@ > quit;
You can also use the following command to exit the client:
odps@ > q;