This topic describes how to use the MaxCompute client to use MaxCompute features.
Download and install the client
Before you use the client, download, install, and configure the client. For more information, see Install and configure the MaxCompute client.
Note
- Do not rely on the output format of the client in the parsing processes. The output format of the client may not be forward compatible. The command syntax and execution rules vary based on the client versions. For more information about client versions, see aliyun-odps-console.
- The MaxCompute client 0.28.0 and later support JDK 1.9. The earlier versions of the client support only JDK 1.8.
- The MaxCompute client 0.27.0 and later support the MaxCompute V2.0 data type edition. For more information, see New data types.
After the client is installed and configured, you can use command lines to perform the following operations. For more information about client commands, see the Commonly used commands.
Run the MaxCompute client
- Run
.bat
in the bin directory of the installation path to run the client. The following information is returned:[admin: ~]$odpscmd Aliyun ODPS Command Line Tool Version 1.0 @Copyright 2012 Alibaba Cloud Computing Co., Ltd. All rights reserved.
Enter the command at the cursor and press Enter to run it. The command ends with a semicolon (;).odps@ odps> insert overwrite table table_name select * from table_name;
- Run the client by using the Command Prompt in Windows.
In the Command Prompt, enter the required command to go to the bin directory and run
odpscmd
. If the following information is returned, the operation succeeded. For more commands, see Specify startup parameters.D:\maxcompute\bin>odpscmd Aliyun ODPS Command Line Tool Version 0.30.2 @Copyright 2018 Alibaba Cloud Computing Co., Ltd. All rights reserved.
Query help information
- Use the Command Prompt in Windows.
In the Command Prompt, enter the required command to go to the bin directory and run the following command:
odpscmd -h
- Use the MaxCompute client.
- Run the following command on the client to query all the help information:
help; -- The preceding command is equivalent to the following command: h;
- Run the following command on the client to query the help information about a specific
keyword.
help [keyword];
For example, run the following command to query the help information about table operations:odps@ odps> help table; Usage: alter table merge smallfiles Usage: show tables [in ] list|ls tables [-p,-project ] Usage: describe|desc [.] [partition()] Usage: read [.] [([,..])] [PARTITION ()] [line_num]
- Run the following command on the client to query all the help information:
Specify startup parameters
If you use the Command Prompt in Windows to run the client, you can specify a series
of parameters. Example:
Usage: odpscmd [OPTION]...
where options include:
--help (-h)for help
--project= use project
--endpoint= set endpoint
-u -p user name and password
-k will skip begining queries and start from specified position
-r set retry times
-f <"file_path;"> execute command in file
-e <"command;[command;]..."> execute command, include sql command
-C will display job counters
The following table describes the parameters.
Parameter | Description |
---|---|
-help (-h) | Queries the help information about the client. |
--project= use project | Specifies the name of the project that you want to access. |
--endpoint= set endpoint | Specifies the endpoint in use. For more information, see Configure endpoints. |
-u | Specifies the name of the user who uses the client. |
-p | Specifies the password of the user who uses the client. |
-k | Indicates that the previous statement is ignored and the execution starts from the
statement at the specified position.
Note
|
-r | Specifies the number of retry attempts. |
-f | Specifies the file that you want to read. |
-e | Specifies the command to execute. |
-C | Shows the job counter. |
Examples
- Use the
-f
option to specify the files that you want to read.- Prepare a local script file named script.txt. The file is stored in drive D and contains the following data in this example:
DROP TABLE IF EXISTS test_table_mj; CREATE TABLE test_table_mj (id string, name string); DROP TABLE test_table_mj;
- In the Command Prompt of your system, enter the required command to go to the path
where the client is located and run the following command:
odpscmd\bin>odpscmd -f D:/script.txt;
- Prepare a local script file named script.txt. The file is stored in drive D and contains the following data in this example:
- Use the
-k
option to read data from the specified position.- Assume that /tmp/test.sql contains the following three SQL statements:
drop table table_name; create table table_name (dummy string); insert overwrite table table_name select count(*) from table_name;
- Run the following command to ignore the first two statements and start from the third
statement:
odpscmd -k 3 -f test.sql
- Assume that /tmp/test.sql contains the following three SQL statements:
Query information about the current logon user
Run the following command to query the Alibaba Cloud account, endpoint, and project
name of the current logon user:
whoami;
Examples
odps@ hiveut>whoami;
Name: odpstest@aliyun.com
End_Point: http://service.odps.aliyun.com/api
Project: lijunsecuritytest
Exit the client
Run the following command to exit the client:
odps@ > quit;
-- The preceding command is equivalent to the following command:
odps@ > q;