The MaxCompute local client (odpscmd) is designed for command-line operations. You can run it on your local machine to efficiently execute commands and manage projects. This topic describes how to download, install, configure, run, and use the client.
Scope
Java 8 or a later version is installed on the device where you want to install the MaxCompute client.
Version compatibility
MaxCompute client V0.28.0 and later support Java Development Kit (JDK) 1.9. Versions earlier than V0.28.0 support only JDK 1.8. After you start the MaxCompute client, you can view the client version number in the command-line interface.
The output format of the MaxCompute client is not forward-compatible. The command format and behavior may vary between different versions. Do not rely on the client's output format for any parsing tasks.
For more information about client versions, see aliyun-odps-console.
Encoding format
The client uses UTF-8 encoding by default. If your local environment does not use UTF-8 encoding, garbled characters may appear when you query a MaxCompute table and the returned values contain Chinese characters. Garbled characters may also appear when you use the client to run a Tunnel command to upload a local data file to MaxCompute.
Billing
You are not charged for connecting to a project using the MaxCompute client. However, operations that you perform through the client may incur MaxCompute fees. For example, if you use the client to submit an SQL query and a write command, the SQL command consumes computing resources when it runs on MaxCompute, and the written data occupies storage space. This generates computing and storage fees. For more information about MaxCompute billing, see Billable items and billing methods.
Install and configure the MaxCompute client
The client supports the MaxCompute V2.0 data type edition starting from V0.27.0. We recommend that you use the new data types. For a list of supported data types, see Data type editions.
Follow these steps:
Download the MaxCompute client installation package (GitHub).
NoteClick the link to go to the client release page and download the latest version of the MaxCompute client installation package (odpscmd_public.zip).
If you cannot download the package from the preceding link, try to click MaxCompute client installation package (OSS) to download it. If the GitHub link fails, we recommend that you search for a solution on a search engine.
Decompress the downloaded installation package to get the bin, conf, lib, and plugins folders.
Go to the conf folder and configure the odps_config.ini file.
In the odps_config.ini file, lines that start with a number sign (#) are comments. The following table describes the parameters.
Parameter
Required
Description
Example
project_name
Yes
The name of the target MaxCompute project that you want to access.
If you create a workspace in standard mode, note the difference between the project names for the production environment and the development environment (_dev) when you configure the project_name parameter. For more information, see Differences between workspace modes.
Log on to the MaxCompute console and select a region in the top-left corner.
In the navigation pane on the left, choose .
On the Projects page, you can find the name of your MaxCompute project.
doc_test_dev
access_id
Yes
The AccessKey ID of your Alibaba Cloud account or RAM user. You can go to the AccessKey Management page to obtain the AccessKey ID.
None
access_key
Yes
The AccessKey secret that corresponds to the AccessKey ID.
None
end_point
Yes
The endpoint of the MaxCompute service.
Configure the endpoint based on the region and network connection type that you selected when you created the MaxCompute project. For information about the endpoints for different regions and networks, see Endpoints.
ImportantThe endpoint is for the MaxCompute service, and the Tunnel endpoint is for the MaxCompute Tunnel service. Enter the endpoint for the MaxCompute service here.
If the endpoint is configured incorrectly, an access error occurs. Make sure that the endpoint is correct.
http://service.cn-hangzhou.maxcompute.aliyun.com/api
log_view_host
No
The Logview address. We recommend that you configure this parameter. If you do not configure this parameter, you cannot quickly locate the problem when a job fails.
You can use this address to view the detailed runtime information of a job, which provides a basis for troubleshooting. The value is fixed at http://logview.odps.aliyun.com.
http://logview.odps.aliyun.com
https_check
No
Specifies whether to enable HTTPS access to encrypt requests to access MaxCompute projects. Valid values:
True: HTTPS is used.
False: HTTP is used.
Default value: False.
True
data_size_confirm
No
The maximum size of input data in GB. This parameter has no value range limit. We recommend that you set this parameter to 100 GB.
100
update_url
No
A reserved parameter that you can ignore.
None
use_instance_tunnel
No
Specifies whether to use InstanceTunnel to download the execution results of SQL statements. Valid values:
True: Use InstanceTunnel to download the execution results of SQL statements.
False: Do not use InstanceTunnel to download the execution results of SQL statements.
Default value: False.
True
instance_tunnel_max_record
No
The maximum number of records that the client can return for an SQL execution result. If you set use_instance_tunnel to True, you must configure this parameter. The maximum value is 10000.
10000
tunnel_endpoint
No
The public endpoint of the Tunnel service.
If you do not configure a Tunnel endpoint, Tunnel automatically routes traffic to the Tunnel endpoint that corresponds to the network where the MaxCompute service resides.
If you configure a Tunnel endpoint, the configured endpoint is used, and automatic routing is not performed.
For information about the Tunnel endpoints for different regions and networks, see Endpoints.
http://dt.cn-hangzhou.maxcompute.aliyun.com
set.<key>
No
Sets the properties of the MaxCompute project.
For more information about properties, see Properties.
set.odps.sql.decimal.odps2=true
Make sure that the preceding information is correctly configured. Incorrect configuration will cause the project connection to fail.
Run the MaxCompute client
If you use a RAM user to run the MaxCompute client, use your Alibaba Cloud account to add the RAM user to the target MaxCompute project. For more information about adding workspace members, see Grant permissions to other users.
Start the MaxCompute client using one of the following methods:
Method 1: Use the script file in the installation package
In the bin folder of the MaxCompute client installation directory, double-click the
odpscmd.batfile for Windows or theodpscmdfile for macOS to start the MaxCompute client. If the following information is returned, you have successfully connected to the MaxCompute project.
Method 2: Use the command-line window of your operating system
In the command-line window of your operating system, go to the bin directory of the MaxCompute client installation path. Run the
odpscmdcommand for Windows orsh odpscmdfor Linux or macOS to start the MaxCompute client. If the following information is returned, you have successfully connected to the MaxCompute project.NoteIf you run
sh odpscmdin Ubuntu, an error is reported. Try to run the./odpscmdcommand to start the client.
If you start the MaxCompute client from the command-line window of your operating system, you can specify parameters to run commands. For more information about the parameters, see Startup parameters.
Related operations on the MaxCompute client
Get help for all commands
You can quickly get help for MaxCompute client commands using one of the following methods:
View command help information in the MaxCompute client
View help information for all commands.
odps@project_name>help; -- This command is equivalent to the following command. odps@project_name>h;Specify a keyword to view help information for related commands.
For example, get help for commands related to table operations.
odps@project_name>help table; -- The following result is returned. Usage: alter table <tablename> merge smallfiles Usage: export table <tablename> Usage: show tables [in <project_name>] [like '<prefix>'] list|ls tables [-p,-project <project_name>] Usage: describe|desc [<projectname>.]<tablename> [partition(<spec>)] Usage: read [<project_name>.]<table_name> [(<col_name>[,..])] [PARTITION (<partition_spec>)] [line_num]ImportantThe
readcommand uses SQL syntax. For more information about billing, see SQL billing.
View command help information in the command-line window of your operating system
In the command-line window of your operating system, switch to the bin directory of the MaxCompute client installation path. Run the following command to view help information for all commands. When you start the MaxCompute client in a command-line window, you can specify a series of parameters. For more information about the parameters, see Startup parameters.
...\odpscmd\bin>odpscmd -hGet information about the current logon user
After you run the MaxCompute client, run the following command to get information about the current logon user.
odps@project_name>whoami;The following describes the response.
Name: The account information of the current logon user.
Source IP: The IP address of the device where the MaxCompute client is located.
End_Point: The endpoint of the MaxCompute service.
Project: The name of the MaxCompute project.
Schema: The schema in the MaxCompute project.
Exit the MaxCompute client
Run the following command to exit the running MaxCompute client.
odps@project_name>quit;
-- This command is equivalent to the following command.
odps@project_name>q;Run the tunnel download command
When you run the
tunnel downloadcommand for the first time, the MaxCompute client creates a session folder in theplugins/dshipdirectory of the client installation to store logs.If multiple users run the
tunnel downloadcommand on the same device, use one of the following methods to ensure data security:Use the folder permission management feature of the device to manage the permissions on the session folder.
Add the
-sd <new session folder name>or-session-dir <new session folder name>parameter to thetunnel downloadcommand to download data to a different session folder. For more information about thetunnel downloadcommand, see Download.
References
After you log on to the MaxCompute client, you can run SQL commands in the MaxCompute project. For more information, see Use the MaxCompute client.
For more information about the command syntax that the MaxCompute client supports, see Common commands or SQL commands and functions.
FAQ
After you configure the odps_config.ini file, the following common errors may occur when you start the MaxCompute client:
Error: no java found
Cause
Java is not installed on the machine where you run the MaxCompute client.
Solution
Install Java on the machine where you run the MaxCompute client and configure environment variables. MaxCompute client V0.28.0 and later support JDK 1.9. Earlier versions support only JDK 1.8.
Error: Cannot find or load the main class com.aliyun.openservices.odps.console.ODPSConsole
Cause
You may have downloaded the client installation package twice. The second time, the directory was automatically renamed to
odpscmd_public (1). The directory name contains characters such as spaces, which causes a path recognition error.Solution
Remove characters such as spaces from the directory name.
Error: Accessing project '<projectname>' failed: ODPS-0420111: Project not found - '<projectname>'.
Cause
The project name in the odps_config.ini configuration file is incorrect.
Solution
Log on to the MaxCompute console and select a region in the top-left corner.
In the navigation pane on the left, choose .
On the Projects page, get the correct name of the created MaxCompute project and modify the odps_config.ini configuration file.
Error: Accessing project '<projectname>' failed: ODPS-0420095: Access Denied - Authorization Failed [4002], You don't exist in project <projectname>.
Cause
The Alibaba Cloud account or RAM user that corresponds to the AccessKey is not added to the target project, or the project name is incorrect.
Solution
Contact the project owner to add the corresponding Alibaba Cloud account or RAM user to the target project. For more information, see Add an Alibaba Cloud account user (project-level) or Add a RAM user (project-level).
Error: Accessing project '<projectname>' failed: { "Code": "InvalidProjectTable", "Message": "The specified project or table name is not valid or missing."} or Accessing project '<projectname>' failed: connect timed out
Cause
The value of the
end_pointparameter is incorrect. For example, you use the MaxCompute client on your local computer to connect to a project, but you use the endpoint for the Alibaba Cloud classic network (an internal network endpoint in a public network environment) or enter a Tunnel endpoint.Solution
See the Endpoints document and select the endpoint that matches the region and network environment of the project you want to connect to.
The endpoint is for the MaxCompute service, and the Tunnel endpoint is for the MaxCompute Tunnel service. The
end_pointparameter should be set to the endpoint for the MaxCompute service, not the Tunnel endpoint.
Error: Accessing project '<projectname>' failed: <endpoint>
Cause
The value of the
end_pointparameter is incorrect. For example, you enteredhttp://service.ch-hangzhou.maxcompute.aliyun.com/apiinstead of the public endpoint for the China (Hangzhou) region, which ishttp://service.cn-hangzhou.maxcompute.aliyun.com/api.Solution
See the Endpoints document and copy the endpoint that matches the region and network environment of the project you want to connect to. We recommend that you do not enter the endpoint manually.
Startup parameters
In the command-line window of your operating system, you can specify a series of parameters to quickly run commands. The usage is as follows.
Usage: odpscmd [OPTION]...
where options include the following:
--help (-h)for help
--config=<config_file> specify another config file
--project=<prj_name> use project
--endpoint=<http://host:port> set endpoint
-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 commandThe following table describes the startup parameters.
Command | Description | Sample command |
| Gets help information for all commands of the MaxCompute client. |
|
| Specifies the path of the odps_config.ini configuration file. The default path is |
|
| Specifies the name of the MaxCompute project to access. |
|
| Specifies the endpoint of the MaxCompute service. For more information about endpoints, see Endpoints. |
|
| Runs statements starting from a specified position. If | Ignore the first two statements and start from the third statement. |
| Sets the number of retries if a job fails. |
|
| Specifies the file to read. |
|
| Specifies the command to run. |
|
In a Shell window or Windows Command Prompt, you may need to use the dynamic return value from an odpscmd -e <SQL_statement> command. A Shell variable gets this dynamic return value and then uses it in subsequent jobs in the Shell. In this scenario, the return value must not contain extra information such as runtime information or table headers. To facilitate Shell calls, set the use_instance_tunnel parameter in the odps_config.ini file to false to disable the Instance Tunnel service. Then, run the set odps.sql.select.output.format={"needHeader":false,"fieldDelim":" "}; command to hide the table header.
For example, a table named noheader has one column and three rows of data: 1, 2, and 3. Run the following command to redirect the calculation result to stdout to the target handle. The result contains only the specific data, without any other extra information:
--Run the following command in the Windows Command Prompt.
...\odpscmd\bin>odpscmd -e "set odps.sql.select.output.format={""needHeader"":false,""fieldDelim"":"" ""};select * from noheader;" >D:\test.txt
--The result is saved in D:\test.txt.
--Run the following command in a Shell window.
/Users/.../odpscmd/bin/odpscmd -e "set odps.sql.select.output.format={\"needHeader\":false,\"fieldDelim\":\"\"};select * from noheader;" >/Users/A/temp/test.txt
--The result is saved in /Users/A/temp/test.txt.
--The following result is returned.
1
2
3Version update history
The following table describes the recent version updates of the MaxCompute client. For more information, click the link for the corresponding version.
For more information about MaxCompute client versions and related feature updates, see GitHub.
Version | Change type | Description |
New feature | Supports using Security Token Service (STS) tokens as temporary security credentials. | |
Bug fix | Upgraded the Apache Arrow library version to fix compatibility issues with Arrow library dependencies. | |
New feature | Added an option to skip progress reports. You can add the | |
Feature enhancement |
| |
Bug fix | Upgraded dependencies to clear Common Vulnerabilities and Exposures (CVE) vulnerabilities. | |
New feature | Enhanced acceleration for external volume creation: Added an acceleration option for external volume downloads. | |
Feature enhancement | Refactored the | |
New feature |
| |
Feature enhancement |
| |
New feature |
| |
New feature |
| |
Bug fix | The MCQA mode can more accurately identify fallback behavior to prevent the Logview from being repeatedly displayed. | |
New feature |
| |
Feature enhancement |
| |
New feature | Tunnel-related operations support the JSON data type. | |
New feature |
| |
Feature enhancement | Enhanced table description storage tier information: Extended the | |
New feature |
| |
New feature |
| |
Feature enhancement |
| |
New feature |
| |
Bug fix | Removed the Log4j dependency. | |
New feature | Supports storing project data by schema. For more information, see Schema operations. | |
New feature | Supports uploading and downloading complex data types through Tunnel. | |
Feature enhancement |
| |
New feature | Supports creating an External Project to connect to Data Lake Formation (DLF) and implement the data lakehouse feature. | |
Bug fix | Fixed an issue where the nanosecond part of TIMESTAMP data was processed incorrectly during download. |