DDL

create table if not exists sale_detail(
 shop_name     string,
 customer_id   string,
 total_price   double)
 partitioned by (sale_date string,region string);
desc sale_detail;
 drop table if exists sale_detail;
ALTER TABLE table_name RENAME TO new_table_name;
TRUNCATE TABLE table_name;
 ALTER TABLE table_name ADD COLUMNS (col_name1 type1, col_name2 type2...)
ALTER TABLE table_name CHANGE COLUMN old_col_name new_col_name column_type COMMENT column_comment;

不支持删除列。

可以通过创建新表,导入数据,删除原表, 重命名新表完成。

DML

insert overwrite table sale_detail_insert partition (sale_date='2013', region='china')
select shop_name, customer_id, total_price from sale_detail;

注意:在进行Insert更新数据操作时,源表与目标表的对应关系依赖于在select子句中列的顺序,而不是表与表之间列名的对应关系。

    insert overwrite table total_revenues partition(region)
        select total_price as revenue, region
            from sale_detail;

当使用Select语句屏显时,目前最多只能显示10000行结果。当Select作为子句时,无此限制,Select子句会将全部结果返回给上层查询

对分区表全表扫描的SQL语句前加一个set语句set/setproject odps.sql.allow.fullscan=true;

只有MAPJOIN可以使用不等值连接或者使用or连接多个条件

select /*+ mapjoin(a) */
        a.total_price,
        b.total_price
    from shop a join sale_detail b
    on a.total_price < b.total_price or a.total_price + b.total_price < 500;

其他

show p from 2015-5-20 to 2015-5-22 2000

小于10000条可以直接导出,超过需要使用Tunnel工具

tunnel download  project.table/pt=20180606  /Users/dinozhang/Downloads/20180606.csv  -c "gbk" -cn column1,column2,column3,column4, column5;