You can use the MaxCompute client to access MaxCompute projects and run commands. This topic describes how to install, configure, and run the MaxCompute client and provides related instructions.

Prerequisites

Before you install the MaxCompute client, make sure that the following conditions are met:
  • Java 8 or later is installed on the machine on which you want to install the MaxCompute client.
  • A MaxCompute project is created.

    For more information about how to create a MaxCompute project, see Create a MaxCompute project.

  • A RAM user as which you want to use the MaxCompute client is added to the DataWorks workspace to which the MaxCompute project that you created belongs.

    For more information about how to add members to a workspace, see Add a workspace member and configure roles.

Background information

After you install and configure the MaxCompute client, you can start the MaxCompute client by using the script file in the installation path or by running commands in the CLI of the system. The MaxCompute client allows you to perform the following operations:

Limits

MaxCompute client V0.28.0 and later support Java Development Kit (JDK) 1.8 and JDK 1.9. The MaxCompute client of a version that is earlier than V0.28.0 supports only JDK 1.8. You can view the client version in the CLI after you start the MaxCompute client. For more information about how to start the MaxCompute client, see Run the MaxCompute client.

Precautions

  • The output format of the MaxCompute client may not be forward compatible. The command syntax and execution rules of the client vary based on the client version. We recommend that you do not rely on the output format of the client to parse data. For more information about client versions, see aliyun-odps-console.
  • If you run the Tunnel Download command for the first time on the MaxCompute client, the MaxCompute client creates a folder named session in the client installation directory plugins/dship of your machine. The session folder is used to store logs. If multiple users run the Tunnel Download commands on the same machine, you can use one of the following methods to ensure data security:
    • Use the folder permission management feature provided by the machine to manage the permissions on the session folder.
    • Add the -sd <Name of a new session folder> or -session-dir <Name of a new session folder> parameter to the Tunnel Download command to download data to a different session folder. For more information about Tunnel Download commands, see Download.
  • Two consecutive minus signs (-) are used to comment out a command line on the MaxCompute client.

Install and configure the MaxCompute client

Note MaxCompute client V0.27.0 and later support the MaxCompute V2.0 data type edition. We recommend that you use the MaxCompute V2.0 data type edition. For more information about the data types that are supported by the MaxCompute V2.0 data type edition, see MaxCompute V2.0 data type edition.

To install and configure the MaxCompute client, perform the following steps:

  1. Download the MaxCompute client installation package (GitHub).
    Note If you cannot download the package after you click the preceding link, click MaxCompute client installation package (OSS) to download the package. For more information about how to solve the download failure, we recommend that you search for related solutions by using search engines.
  2. Decompress the downloaded package to obtain the bin, conf, lib, and plugins folders.
  3. Open the conf folder and configure the odps_config.ini file.
    The following code shows the content in the odps_config.ini file.
    project_name=
    access_id=
    access_key=
    end_point=
    log_view_host=
    https_check=
    # confirm threshold for query input size(unit: GB)
    data_size_confirm=
    # this url is for odpscmd update
    update_url=
    # download sql results by instance tunnel
    use_instance_tunnel=
    # the max records when download sql results by instance tunnel
    instance_tunnel_max_record=
    # IMPORTANT:
    #   If leaving tunnel_endpoint untouched, console will try to automatically get one from odps service, which might charge networking fees in some cases.
    #   Please refer to Endpoints
    # tunnel_endpoint=
    
    # use set.<key>=
    # e.g. set.odps.sql.select.output.format=

    In the odps_config.ini file, lines that start with a number sign (#) are comments. The following table describes the parameters in the odps_config.ini file.

    Parameter Required Description Example
    project_name Yes The name of the MaxCompute project that you want to access.

    If you create a workspace in standard mode, pay attention to the differences in the project names between the production environment and development environment when you configure the project_name parameter. The name of the project for the development environment ends with _dev. For more information, see Basic mode and standard mode.

    You can log on to the MaxCompute console and view the MaxCompute project names on the Project Management tab.

    doc_test_dev
    access_id Yes The AccessKey ID of your Alibaba Cloud account or a RAM user within the Alibaba Cloud account.

    You can obtain the AccessKey ID from the AccessKey Pair page.

    None
    access_key Yes The AccessKey secret that corresponds to the AccessKey ID.

    You can obtain the AccessKey secret from the AccessKey Pair page.

    None
    end_point Yes The endpoint of MaxCompute.

    You must configure this parameter based on the region and network connection method that you selected when you create the MaxCompute project. For more information about the endpoints that correspond to each region and network, see Endpoints.

    Notice If you specify an invalid endpoint, an error occurs when you access MaxCompute.
    http://service.cn-hangzhou.maxcompute.aliyun.com/api
    log_view_host No The Logview Uniform Resource Locator (URL). You can view the detailed runtime information of a job by using this URL. This information helps you troubleshoot job errors. Set the value to http://logview.odps.aliyun.com.
    Note We recommend that you configure this parameter. If you do not configure this parameter, you cannot identify the cause of job errors.
    http://logview.odps.aliyun.com
    https_check No Specifies whether to enable HTTPS access. If HTTPS access is enabled, requests to access MaxCompute projects are encrypted. Valid values:
    • True: HTTPS access is enabled.
    • False: HTTP access is enabled.

    Default value: False.

    True
    data_size_confirm No The maximum size of input data. Unit: GB. The value range is unlimited. We recommend that you set this parameter to 100. 100
    update_url No A reserved parameter. None
    use_instance_tunnel No Specifies whether to use InstanceTunnel to download execution results of SQL statements. Valid values:
    • True: InstanceTunnel is used to download execution results of SQL statements.
    • False: InstanceTunnel is not used to download execution results of SQL statements.

    Default value: False.

    True
    instance_tunnel_max_record No The maximum number of SQL execution results that can be returned by the client. If the use_instance_tunnel parameter is set to True, you must configure this parameter. Maximum value: 10000. 10000
    tunnel_endpoint No The public endpoint of MaxCompute Tunnel. If you do not configure this parameter, traffic is automatically routed to the Tunnel endpoint that corresponds to the network in which MaxCompute resides. If you configure this parameter, traffic is routed to the specified endpoint and automatic routing is not performed.

    For more information about the Tunnel endpoints that correspond to each region and network, see Endpoints.

    http://dt.cn-hangzhou.maxcompute.aliyun.com
    set.<key> No The properties of the MaxCompute project.

    For more information about the properties of MaxCompute projects, see Properties.

    set.odps.sql.decimal.odps2=true

Run the MaxCompute client

You can start the MaxCompute client by using one of the following methods:
  • Method 1: In the bin folder in the installation path of the MaxCompute client, double-click the odpscmd.bat file to start the MaxCompute client. This method is used for the Windows operating system. If the information shown in the following figure is returned, the MaxCompute project is connected. Connected
  • Method 2: In the CLI of the system, go to the bin folder in the installation path of the MaxCompute client and run the odpscmd command for the Windows operating system or run the sh odpscmd command for the macOS or Linux operating system to start the MaxCompute client. If the information shown in the following figure is returned, the MaxCompute project is connected. Connected
    Note An error is returned when you run the sh odpscmd command in Ubuntu. You can run the ./odpscmd command to start the MaxCompute client.
You can enter a command at the cursor shown in the preceding figure and press Enter to run the command. The following figure shows a sample command and the returned results. Returned results
Note For more information about the command syntax supported by the MaxCompute client, see Common commands or SQL commands and functions.

Obtain information about the current logon user

You can run the following command in the CLI to obtain the information about the current logon user:
odps@project_name>whoami;
The following figure shows the returned results. Current logon user
  • Name: the account of the current logon user.
  • Source IP: the IP address of the machine in which the MaxCompute client resides.
  • End_Point: the endpoint of MaxCompute.
  • Project: the name of the MaxCompute project.

Exit the MaxCompute client

You can run the following command in the CLI to exit the MaxCompute client:
odps@project_name>quit;
-- The preceding command is equivalent to the following command: 
odps@project_name>q;

Obtain help information about commands

You can obtain help information about the commands of the MaxCompute client by using one of the following methods:
  • Method 1: View the help information about commands on the MaxCompute client.
    • View the help information about all commands.
      odps@project_name>help;
      -- The preceding command is equivalent to the following command: 
      odps@project_name>h;
    • Specify a keyword to view the help information about the related commands.
      Example: Obtain the help information about the commands that are related to table operations.
      odps@project_name>help table;
      -- Returned results: 
      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]
  • Method 2: In the CLI of the system, go to the bin folder in the installation path of the MaxCompute client, and run the following command to view the help information about all commands. If you start the MaxCompute client by running commands in the CLI, you can specify a series of parameters in the commands. For more information about these parameters, see Specify startup parameters.
    ...\odpscmd\bin>odpscmd -h

Specify startup parameters

In the CLI of the system, you can specify a series of parameters to run a command. The following code shows the usage of these 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 Sample command
--help or -h Obtains the help information about all commands of the MaxCompute client. odpscmd --help
--config Specifies the directory in which the configuration file odps_config.ini is stored. The default directory is odpscmd_public/conf. odpscmd --config=D:/odpscmd/conf/odps_config.ini
--project Specifies the name of the MaxCompute project that you want to access. odpscmd --project=doc_test
--endpoint Specifies the endpoint of MaxCompute. For more information about the endpoints of MaxCompute, see Endpoints. odpscmd --endpoint=http://service.cn-shanghai.maxcompute.aliyun.com/api
-k Executes statements from a specific location. If n is set to a value that is less than or equal to 0, the execution starts from the first statement. Multiple statements are separated by semicolons (;). Run the following command to ignore the first two statements and start from the third statement: odpscmd -k 3 -e "drop table table_name;create table table_name (dummy string);insert overwrite table table_name select count(*) from table_name;"
-r Specifies the number of retries that are allowed after a job fails to run. odpscmd -r 2 -e "select * from sale_detail;select * from table_test;"
-f Specifies the file to read.
  1. Prepare a script file named script.txt. In this example, the file is stored in drive D and contains the following data:
    drop table if exists test_table_mj;
    create table test_table_mj (id string, name string);
    drop table test_table_mj;
  2. In the CLI, go to the bin folder in the installation path of the MaxCompute client and run the following command:
    ..\odpscmd\bin>odpscmd -f D:/script.txt;
-e Specifies the command that you want to run. odpscmd -e "select * from sale_detail;"

The dynamic return value of an odpscmd -e SQL statement command may be called by a shell script that is run in a shell window or the Command Prompt in Windows. A shell variable may obtain the return value and use it in subsequent jobs. In this scenario, only field values are required. Other information, such as runtime information and headers, cannot be returned. To facilitate shell calls, you must set the use_instance_tunnel parameter in the odps_config.ini file to false to disable InstanceTunnel. You can run the set odps.sql.select.output.format={""needHeader"":false,""fieldDelim"":""""}; command to disable header display.

For example, a table named noheader contains one column and three rows of data. The field values are 1, 2, and 3. After you run the following command to redirect the standard output of the query result to the destination handle, the output contains only field values.
-- Run the following command in the Command Prompt in Windows: 
...\odpscmd\bin>odpscmd -e "set odps.sql.select.output.format={""needHeader"":false,""fieldDelim"":""""};select * from noheader;" >D:\test.txt
-- The returned results are stored in the test.txt file in drive D. 

-- 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 returned results are stored in the test.txt file in the /Users/A/temp directory. 
-- Returned results: 
1
2
3

Version updates

The following table describes the latest version updates of the MaxCompute client. For more information, click the URL of a specific version.

Version Change type Description
v0.37.4-public Enhanced feature
  • The help information about commands is optimized.
  • The desc extended partition command returns more information about the properties of partitions.
v0.36.0-public New feature An external project can be created to connect to Data Lake Formation (DLF). This implements the data lakehouse feature.
Fixed issue The issue that caused the nanosecond part of data of the TIMESTAMP type to be incorrectly processed is fixed.