odps SQL记录
1.增加分区
alter table tableName add if not exists partition(ds='20200623')
2.数据类型转换
cast(col as bigint)
3.动态插入
insert overwrite table tableA partition(ds) select A.其他非分区字端,20200713 as ds from tableA where ds=20200712;
4.正则替换
select REGEXP_REPLACE ('XXX','( )|\\)|\\(|(|)| {1,}','')
注意:转义字符是\\
5.查看扩展信息
desc extended table_name;
6.查看所有的分区
show partitions table_name;
7.Hash Clustering表
Hash Clustering表的优势在于可以实现Bucket Pruning(裁剪)优化、Aggregation优化以及存储优化。在创建表时,使用Clustered By指定Hash Key后,MaxCompute将对指定列进行Hash运算,按照Hash值分散到各个Bucket里。Hash Key值请选择重复键值少的列。
转化为Hash Clustering表的方法如下。
ALTER TABLE table_name [CLUSTERED BY (col_name [, col_name, ...])
[SORTED BY (col_name [ASC | DESC] [, col_name [ASC | DESC] ...])]
INTO number_of_buckets BUCKETS]
alter table
语句适用于存量表,在增加了新的聚集属性之后,新的分区将做Hash Clustering存储。
创建完Hash Clustering表后,您可以使用
insert overwrite
语句将源表转化为Hash Clustering表。
注意 Hash Clustering表存在以下限制:
- 不支持
insert into
语句,只能通过insert overwrite
来添加数据。 - 由于Tunnel方式上传的数据是无序的,因此不支持直接使用Tunnel上传数据到range
We only live once, and time just goes by.