odps sql: consistent with the hive sql syntax
odpscmd.bat
SQL statements are not case sensitive, use "-" annotation, use a semicolon as a statement terminator symbol
Data Definition Language (DDL), data manipulation language (DML), Data Control Language (DCL) and Transaction Control Language (TCL); ODPS used in the main with the DML DDL
Display Space: 1: show tables; 2: ls tables; 3: list tables;
View Table: desc biaoming;
Ceku: use the library name;
Exit: 1: quit; 2: q;
Txt upload text to the corresponding partition table: tunnel upload -h true -fd '\ t' C: \ Users \ Desktop \ stg_police_situation_nature_ps.txt odps_prod.stg_police_situation_nature_ps / dt = '20180724', adcode = '330100';
Download Data: tunnel download odps_prod.ods_tfc_area_range_znkk / dt = '20180701' C: \ Users \ Desktop \ daduixiaqu.txt;
View recent history of operation: tunnel show history -n 5;
Modify table: alter table aaa_ps rename to aaa_znkk;
Review Notes to Table: alter table table_name set comment 'table_new_name';
Table modified life cycle: alter table table_name set lifecycle days; (where day is a positive integer days)
View Zoning: show partitions table;
Delete Partition: alter table table name drop partition (dt = '20180601');
To delete data: TRUNCATE TABLE table_name;
创建分区;alter table odps_prod.dwd_tfc_rltn_wide_custinter_inter add partition(adcode='330100',data_version='20180724');
Clear table data: truncate table temp_a;
Resources (.py, .jar, etc.) on the download item: get resource judgelocation.jar C: \ Users \ Desktop \;
DDL statements
1. Create a table
(1) create a new custom table: create table if not exists A (field name field type);
(2) create a new table, field table consistent with the existing, but the data is not copied: create table if not exists A like B;
2. Delete table
drop table A;
3. Rename the table
alter table A rename to B;
Table 4. Life Cycle
alter table A set lifecycles 30;
5. Add Field
alter table A add columns (field name field type);
6. Review the information table
desc A
7 changes to the table or comment fields:
alter table tablename change column col_old_name col_new_name column_type comment'';
eg:
DML statements
1. The data in the table update (insert statements)
(1) insert overwrite table A select * from B: shows a copy data of Table A to Table B, provided that the same field;
PS: SQL ODPS platform only supports the above statement to update the database; which represents a key overwrite overwritten, can be replaced into the rear-end express written;
Reading the data in Table 2 (select statement)
(1) select * from A: All fields read
(2) select uid from A: read all the data of a field
(3) select distinct uid from A: reading a data field will not be repeated
(4) select * from A where uid = 'a': reading a data field value equal to the specified value
(5) select * from (select * from A) a: nested statements
(6) select sum (uid) from A group by uid: Query packet
(7) select * from A order by uid limit 4: global ordering, must be used with limit
(8) select row_number () over (partition by item order by score) as row_num from A: Field of the local item sorted field values given number score
3. Table of merger (union all statements)
select * from(
select * from t1 where uid=’a’
union all
select * from t2 where uid=’a’)t;
Table 4. connection (join statements and left outer join statement)
(1)join
select * from A a join B b on a.item = b.item: Returns A, B are the same field in the table item data values
(2)left outer join
select * from A a left outer join B b on a.item = b.item: Returns all data in Table A
(D) built-in function
See attached document
MaxCompute-sql:https://help.aliyun.com/document_detail/27860.html
User and rights management -------------
Adding to the project space user: add user username; eg: add user [email protected]
View User: list users;
Delete User: remove user username;
Grant limit: Grant createTable called user_project_name of the project is to create a table user_name permissions
grant CreateTable on project $user_project_name to user user_name;
Get Permissions table information
grant Describe to table $user_table_name to user user_name;
Function execute permissions
grant Execute on function $user_function_name to user user_name;
Create a role: create role role_name;
Adding a user to a role: grant role_name to user_name;
The user removes the role: remove role_name from user_name;
Remove Role: drop role role_name;
Operating Table
Create a partition table with the life cycle: create table test3 (key boolean) partitioned by (pt string, ds
string) lifecycle 100;
Get table information: desc table_name;
Delete tables: drop table table_name;
UDF
CREATE FUNCTION test_lower AS org.alidata.odps.udf.examples.Lower
USING my_lower.jar;
Use this function in the sql:
select test_lower('A') from my_test_table;
Data Manipulation
Precautions
mapjoin, the most support mapjoin 6 Zhang table;
ODPS SQL currently supports up to 128 concurrent union operations;
It supports up to 128 concurrent insert overwrite / into operation;