The latest ODPS service provides a new version of the client, compared with the old version, the new client has the following improvements:
- You do not need to enter a command shell to execute a specified command. For example, you can enter the client and run SQL comamnds and security commands directly in new version. You do not need to enter SQL/Security shell at first and run corresponding commands.
- The commands of new version is more closed to Hive commands. Most of comnands are compatible with Hive.
Besides, you must note:
- This document is a part of User Manual for the client in ODPS. It describes how to use basic functions of ODPS by using the command lines of 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.
- ODPS client is a java program and can run only in the JRE environment. Therefore, it is required to download and install JRE 1.6 version.
- If you need to learn about the use method of the client, refer to Quick Start.
To downloa ODPS client, please click on Here.
Depress the downloaded file and you can find the following four folders:
bin/ conf/ lib/ plugins/
There is a file named odps_conf.ini in ‘conf’. Edit this file and enter related information:
- Replace the access_id and access_key with the access_id and access_key applied from www.aliyun.com.
- If you often use a project, you can add the name of this project behind of “project_name=”, which can avoid executing “use project_name;” command when entering the client.
- end_point. The access URL differs for different regions. For more information, see Access domains and data centers.
After the configuration file has been modified, run ‘odpscmd’ in bin directory. (If the OS is Linux, run ‘./bin/odpscmd’; if the OS is Windows, run ‘./bin/odpscmd.bat’.)Now you can run ODPS commands:
odps@ test_project> whoami;
View the information about help. Commnd Format:
odps@ >./bin/odpscmd -h;
Or you can type “h” or “help” in an interactive mode. (Case insensitive)
When starting the client, you can specify a series of parameters:
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
Example: (take ‘-f’ as an example)
- 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;
- Running Command:
odpscmd\bin>odpscmd -f d:/script.txt;
- Display the execution result:
ID = 20150528122432906gux77io3
ID = 20150528122439318gcmkk6u1
ID = 20150528122440389g98cmlmf
Directly running the client will 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;
Input the command at the cursor position (take a semicolon as a statement end mark) and press Enter to run.
- When you use ‘-e’ or ‘-f’ option to run command, you can specify the parameter ‘-k’ if there are multiple statements and you want to start running from a middle statement, which indicates ignoring the previous statements and running from the specified position. If the specified parameter <= 0, start running from the first statement.
- Each statement seperated by a semicolon is considered as a valid statement. The statements which runs successfully or fail to run will be printed at running time.
- For example, 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:
odpscmd –k 3 –f dual.sql
Use: get the Alibaba Cloud account and endpoint configuration of current log user.
odps@ > quit;