The MaxCompute client (odpscmd) is a command-line interface that lets you run commands and manage projects from your local machine. This topic explains how to download, install, configure, and use odpscmd.
Prerequisites
-
The MaxCompute client requires Java 8 or later.
-
Version compatibility
-
MaxCompute client v0.28.0 and later supports JDK 1.9 and later. Versions earlier than v0.28.0 support only JDK 1.8. After you start the MaxCompute client, you can view the client version in the command-line interface.
-
The output format of the MaxCompute client is not backward-compatible. Command formats and behavior may differ between client versions. Do not rely on the client output format for parsing.
-
For other client versions, see aliyun-odps-console.
-
-
Character encoding
The client uses UTF-8 by default. If your local environment's character encoding is not UTF-8, garbled characters may appear when you query data containing Chinese characters from a MaxCompute table or use a Tunnel command to upload local files containing them.
Billing
Using the MaxCompute client to connect to a project is free of charge, but operations performed through the client are subject to MaxCompute billing. For example, submitting an SQL query consumes compute resources, and writing data uses storage space. This results in compute and storage costs. For more information about MaxCompute billing, see Billable items and billing methods.
Install and configure odpscmd
odpscmd v0.27.0 and later support the MaxCompute 2.0 data types. We recommend that you use these data types. For a list of supported data types, see Data Types (V2.0).
Procedure
-
Download the odpscmd installation package (GitHub).
Note-
Follow the link to the release page and download the latest version of the odpscmd installation package (odpscmd_public.zip).
-
If you cannot download the package from the GitHub link, try downloading the odpscmd installation package (OSS). If you have issues accessing GitHub, we recommend that you search for solutions online.
-
-
Unzip the downloaded package. The extracted directory contains 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, the number sign (#) indicates a comment. The following table describes the parameters.
Parameter
Required
Description
Example
project_name
Yes
The name of the destination MaxCompute project.
If you created a workspace in standard mode, distinguish 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 in to the MaxCompute console and select a region in the upper-left corner.
-
In the left-side navigation pane, choose .
-
On the Projects page, view your MaxCompute project name.
doc_test_dev
access_id
Yes
The AccessKey ID of your Alibaba Cloud account or RAM user. Obtain the AccessKey ID from the AccessKey Management page.
N/A
access_key
Yes
The AccessKey Secret that corresponds to the AccessKey ID.
N/A
end_point
Yes
The endpoint of the MaxCompute service.
You must configure the endpoint based on the region where your MaxCompute project is located and the network connection type. For a list of endpoints for different regions and network types, see Endpoints.
Important-
An endpoint connects to the MaxCompute service, while a tunnel endpoint connects to the MaxCompute Tunnel service. Specify the endpoint for the MaxCompute service here.
-
An incorrect endpoint configuration causes an access error.
http://service.cn-hangzhou.maxcompute.aliyun.com/api
log_view_host
No
The LogView URL. We recommend that you configure this parameter. If you do not configure this parameter, you cannot quickly identify the cause of a job failure.
Use this URL to view detailed job runtime information and troubleshoot errors. The fixed value is http://logview.odps.aliyun.com.
http://logview.odps.aliyun.com
https_check
No
Specifies whether to enable HTTPS to encrypt requests for accessing the MaxCompute project. Valid values:
-
True: Enables HTTPS.
-
False: Uses HTTP.
The default value is False.
True
data_size_confirm
No
The maximum input data size in GB. This value has no upper limit. Recommended value: 100.
100
update_url
No
This parameter is reserved for future use.
N/A
use_instance_tunnel
No
Specifies whether to use InstanceTunnel to download SQL execution results. Valid values:
-
True: Use InstanceTunnel to download SQL execution results.
-
False: Do not use InstanceTunnel to download SQL execution results.
The default value is False.
True
instance_tunnel_max_record
No
The maximum number of records in an SQL execution result. If use_instance_tunnel is set to True, you must configure this parameter. The maximum value is 10,000.
10000
tunnel_endpoint
No
The public endpoint for the Tunnel service.
-
If you do not configure this parameter, Tunnel automatically routes requests to the tunnel endpoint that corresponds to the network of the MaxCompute service.
-
If you configure a tunnel endpoint, Tunnel uses that value and does not perform automatic routing.
For a list of tunnel endpoints for different regions and network types, see Endpoints.
http://dt.cn-hangzhou.maxcompute.aliyun.com
set.<key>
No
Sets a property for the MaxCompute project.
For more information about properties, see property list.
set.odps.sql.decimal.odps2=true
Ensure the preceding information is configured correctly. Misconfigurations can cause project connection failures.
-
Start the MaxCompute client
-
If you use the MaxCompute client as a RAM user, use your Alibaba Cloud account to add the RAM user to the target MaxCompute project. For more information about adding users, see Grant permissions to other users.
-
Use one of the following methods to start the MaxCompute client:
Script file
In the bin directory of your MaxCompute client installation, double-click
odpscmd.bat(on Windows) orodpscmd(on macOS) to start the MaxCompute client. The following output indicates a successful connection to the MaxCompute project.odpscmd Aliyun ODPS Command Line Tool Version 0.4xxx @Copyright 2020 Alibaba Cloud Computing Co., Ltd. All rights reserved. Connecting to http://service.xxx.maxcompute.aliyun.com/api, project: xxx Executing predefined SET command: SET odps.sql.hive.compatible=true OK Endpoint: http://service.xxx.maxcompute.aliyun.com/api Project: xxx Schema: default Quota: default in region N/A Timezone: Asia/Shanghai Connected!Command-line window
In a command-line window, navigate to the bin directory of your MaxCompute client installation. Run
odpscmdon Windows orsh odpscmdon Linux or macOS to start the MaxCompute client. A success message indicates that the client has connected to the MaxCompute project.NoteOn Ubuntu,
sh odpscmdreturns an error. Use./odpscmdinstead.When you start the MaxCompute client from a command-line window, you can specify startup parameters to run commands. For more information, see Startup parameters.
MaxCompute client operations
Command help
You can get help with MaxCompute client commands in one of the following ways:
In the MaxCompute client
-
View help for all commands.
odps@project_name>help; -- The following command is equivalent. odps@project_name>h; -
View help for commands related to a specific keyword.
For example, to get help with table-related commands, run the following command.
odps@project_name>help table; -- The following output 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 and is subject to SQL pricing.
From the system CLI
In your system's command-line window, navigate to the bin directory of your MaxCompute client installation. Then, run the following command to view help for all commands. You can specify a series of parameters when you start the MaxCompute client from a command-line window. For more information about the parameters, see Parameters.
...\odpscmd\bin>odpscmd -h
Current user information
Run the following command to get current user information.
odps@project_name>whoami;
The output contains the following fields:
-
Name: The current account.
-
Source IP: The IP address of the device running the MaxCompute client.
-
End_Point: The endpoint of the MaxCompute service.
-
Project: The project name.
-
Schema: The schema in the project.
Exiting the MaxCompute client
Run the following command to exit the MaxCompute client.
odps@project_name>quit;
-- The following command is equivalent.
odps@project_name>q;
The tunnel download command
-
The first time you run the
tunnel downloadcommand, the MaxCompute client creates a session folder for logs in theplugins/dshipdirectory of its installation. -
If multiple users run the
tunnel downloadcommand on the same device, use the following methods to ensure data security:-
Use your operating system's permission settings to control access to 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.
-
Related documents
After you log in to the MaxCompute client, you can execute SQL commands in a MaxCompute project. For more information, see Use the MaxCompute client.
For details about the command syntax of the MaxCompute client, see Command reference or SQL commands and functions.
FAQ
After configuring the odps_config.ini file and starting the MaxCompute client, you may encounter the following common errors:
Error: no java found
-
Cause
Java is not installed on the machine running the MaxCompute client.
-
Solution
Install Java on the machine and configure the environment variable. The MaxCompute client v0.28.0 and later supports JDK 1.9 or higher. Earlier versions support only JDK 1.8.
Error: Could not find or load main class com.aliyun.openservices.odps.console.ODPSConsole
-
Cause
You may have downloaded the client package twice, causing the directory to be automatically renamed to
odpscmd_public (1). A directory name that contains special characters, such as spaces, can cause path resolution to fail. -
Solution
Remove spaces and other special characters from the directory name.
Error: Accessing project '<projectname>' failed: ODPS-0420111: Project not found - '<projectname>'.
-
Cause
The project name in the odps_config.ini file may be incorrect.
-
Solution
-
Log in to the MaxCompute console and select a region in the upper-left corner.
-
In the left-side navigation pane, choose .
-
On the Projects page, find the correct name of your MaxCompute project, and then modify the odps_config.ini 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 associated with the current AccessKey has not been added to the target project, or the project name is incorrect.
-
Solution
Contact the project owner to add the 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 are trying to connect from your local computer but have configured an endpoint for an internal network (such as the classic network) or a tunnel endpoint. -
Solution
Refer to the Endpoints documentation and select the correct endpoint for your project's region and network environment.
Ensure you use the MaxCompute service endpoint, not the tunnel endpoint, for the
end_pointparameter. Tunnel endpoints are for the MaxCompute Tunnel service.
Error: Accessing project '<projectname>' failed: <endpoint>
-
Cause
The value of the
end_pointparameter is incorrect. For example, you may have enteredhttp://service.ch-hangzhou.maxcompute.aliyun.com/api. The correct public network endpoint for the China (Hangzhou) region ishttp://service.cn-hangzhou.maxcompute.aliyun.com/api. -
Solution
Refer to the Endpoints documentation and copy the correct endpoint for your project's region and network environment. We recommend copying the endpoint instead of typing it manually.
Startup parameters
You can run commands quickly from the system command line by specifying startup parameters.
Usage: odpscmd [OPTION]...
where options include:
--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 command
The following table describes the startup parameters.
|
Parameter |
Description |
Example |
|
|
Displays help information for all MaxCompute client commands. |
|
|
|
Specifies the path to the odps_config.ini file. The default path is |
|
|
|
Specifies the name of the MaxCompute project to access. |
|
|
|
Specifies the endpoint for connecting to the MaxCompute service. For more information, see Endpoints. |
|
|
|
Skips the first n-1 statements and starts execution from the nth statement. If |
Skips the first two statements and starts execution from the third statement. |
|
|
Sets the number of times to retry a failed job. |
|
|
|
Specifies a file that contains commands to execute. |
|
|
|
Specifies a command to execute. |
|
On the shell or Windows command line, use odpscmd -e <SQL_statement> to capture dynamic return values in a shell variable for subsequent jobs. In this scenario, the return value must not contain extra information, such as runtime details or a header. To facilitate shell scripting, set the use_instance_tunnel parameter in the odps_config.ini file to false to disable Instance Tunnel. Then, run the set odps.sql.select.output.format={"needHeader":false,"fieldDelim":" "}; command to suppress the header.
For example, consider a table named noheader with one column and three rows of data: 1, 2, and 3. Run the following command to redirect the standard output to a file. The output contains only the data and no extra information:
--Windows command line:
...\odpscmd\bin>odpscmd -e "set odps.sql.select.output.format={""needHeader"":false,""fieldDelim"":"" ""};select * from noheader;" >D:\test.txt
--The result is saved to D:\test.txt.
--Shell:
/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 to /Users/A/temp/test.txt.
--Output:
1
2
3
Version history
The following table describes recent updates to odpscmd. For more details, click the link for a specific version.
For a complete list of odpscmd versions and release notes, see GitHub.
|
Version |
Type |
Description |
|
new feature |
Added support for using an STS token as temporary security credentials. |
|
|
bug fix |
Updated the Apache Arrow library to resolve dependency compatibility issues. |
|
|
new feature |
Added the |
|
|
enhancement |
|
|
|
bug fix |
Upgraded dependencies to resolve CVE vulnerabilities. |
|
|
new feature |
Added an acceleration option for downloading an external volume. |
|
|
enhancement |
Refactored the |
|
|
new feature |
|
|
|
enhancement |
|
|
|
new feature |
|
|
|
new feature |
|
|
|
bug fix |
Improved the MCQA mode to more accurately detect fallback behavior and prevent duplicate logview displays. |
|
|
new feature |
|
|
|
enhancement |
|
|
|
new feature |
Added support for the JSON data type in Tunnel operations. |
|
|
new feature |
|
|
|
enhancement |
Extended the |
|
|
new feature |
|
|
|
new feature |
|
|
|
enhancement |
|
|
|
new feature |
|
|
|
bug fix |
Removed the Log4j dependency. |
|
|
new feature |
Added support for schema-based data organization within a project. For more information, see Schema operations. |
|
|
new feature |
Added support for uploading and downloading complex data types through Tunnel. |
|
|
enhancement |
|
|
|
new feature |
Added support for creating an external project to connect to Data Lake Formation (DLF), which enables lakehouse capabilities. |
|
|
bug fix |
Fixed an issue where the nanosecond part of TIMESTAMP data was handled incorrectly during downloads. |