阿里云ODPS常用命令总结

Create Table

命令格式如下:

CREATE TABLE [IF NOT EXISTS] table_name          //表名与列名均无所谓大小写
 [(col_name data_type [COMMENT col_comment], ...)] 
 [COMMENT table_comment]
 [PARTITIONED BY (col_name data_type [COMMENT col_comment], ...)]  //分区表:根据各分区的LastDataModifiedTime判断该分区是否该被回收。
                                                                               不同于非分区表,分区表的最后一个分区被回收后,该表不会被删除。
                                                                               生命周期只能设定到表级别,不能在分区级设置生命周期。
 [LIFECYCLE days]                                //[LIFECYCLE days] days参数为生命周期时间,只接受正整数。单位:天。
 [AS select_statement]
CREATE TABLE [IF NOT EXISTS] table_name
 LIKE existing_table_name

示例如下:

CREATE TABLE IF NOT EXISTS sale_detail(
 shop_name     STRING,
 customer_id   STRING,
 total_price   DOUBLE)
PARTITIONED BY (sale_date STRING,region STRING);

Drop Table

命令格式如下:

DROP TABLE [IF EXISTS] table_name; -- table_name:要删除的表名。

示例如下:

DROP TABLE sale_detail;        -- 若表存在,成功返回;
DROP TABLE IF EXISTS sale_detail;           -- 无论是否存在sale_detail表,均成功返回;

Describe Table

命令格式如下:

DESC <table_name>;      -- table_name:表名或视图名称
DESC extended <table_name>;--查看外部表信息

示例如下:

odps@ project_name>DESC sale_detail;               -- 描述一张分区表                  
+------------------------------------------------------------------------------------+
| Owner: [email protected] | Project: test_project                          |
| TableComment:                                                                      |
+------------------------------------------------------------------------------------+
| CreateTime:               2014-01-01 17:32:13                                      |
| LastDDLTime:              2014-01-01 17:57:38                                      |
| LastModifiedTime:         1970-01-01 08:00:00                                      |
+------------------------------------------------------------------------------------+
| InternalTable: YES      | Size: 0                                                  |
+------------------------------------------------------------------------------------+
| Native Columns:                                                                    |
+------------------------------------------------------------------------------------+
| Field           | Type       | Comment                                             |
+------------------------------------------------------------------------------------+
| shop_name       | string     |                                                     |
| customer_id     | string     |                                                     |
| total_price     | double     |                                                     |
+------------------------------------------------------------------------------------+
| Partition Columns:                                                                 |
+------------------------------------------------------------------------------------+
| sale_date       | string     |                                                     |
| region          | string     |                                                     |
+------------------------------------------------------------------------------------+

其中,各字段代表含义如下:
• Owner(表的属主)。
• Project:表所属的项目空间。
• CreateTime:创建时间。
• LastDDLTime:最后一次DDL操作时间。
• LastModifiedTime:表中的数据最后一次被改动的时间。
• InternalTable:表示被描述的对象是表,总是显示YES。
• Size:表数据所占存储容量压缩后的大小,压缩比一般为5倍,单位Byte。
• Native Columns:非分区列的信息,包括列名、类型和备注。
• Partition Columns:分区列信息,包括分区名、类型和备注。
• Extended Info:外部表StorageHandler 、Location等信息。

查看分区信息

命令格式如下:

desc table_name partition(pt_spec)

示例如下:

odps@ project_name>desc meta.m_security_users partition (ds='20151010');              
+------------------------------------------------------------------------------------+
| PartitionSize: 2109112                                                             |
+------------------------------------------------------------------------------------+
| CreateTime:               2015-10-10 08:48:48                                      |
| LastDDLTime:              2015-10-10 08:48:48                                      |
| LastModifiedTime:         2015-10-11 01:33:35                                      |
+------------------------------------------------------------------------------------+
OK                                                                                    

查看分区中的所有信息

命令格式如下:

SHOW PARTITIONS ; --table_name:指定查询的表名称(表不存在或非分区表报错)

示例如下:

odps@ project_name>SHOW PARTITIONS table_name;
partition_col1=col1_value1/partition_col2=col2_value1
partition_col1=col1_value2/partition_col2=col2_value2
…

其他相关函数详见:https://blog.csdn.net/qq_16234613/article/details/78151110

和R相关的链接:https://www.jianshu.com/p/f5386c4f5153

猜你喜欢

转载自blog.csdn.net/OYY_90/article/details/88740677