在flink table sql中还有涉及到的alter函数,这里的alter主要是涉及到对原有的对象进行修改,目前在flink中支持的alter对象有:
#修改表 alter table #修改视图 alter view #修改数据库 alter database #修改function alter function
下面我们分别介绍下对应的语法
修改表
对于表的修改涉及到的内容比较多,例如:add、modify、drop、rename、set、reset等下面挨个格式下
1)添加某个字段
ALTER TABLE table ADD desc STRING COMMENT '描述';
Flink table sql中alter支持一次性添加多个,示例sql如下:
ALTER TABLE table ADD ( des STRING COMMENT 描述 FIRST, #添加描述 ts AS TO_TIMESTAMP(cts) AFTER des, #添加时间 PRIMARY KEY (id) NOT ENFORCED, #添加主键 WATERMARK FOR ts AS ts - INTERVAL '3' SECOND #添加水印 );
2)修改某个字段
ALTER TABLE table MODIFY price DECIMAL(10, 2) COMMENT '价格' AFTER `name`;
Flink table sql中modify也支持一次性更新多个,实力sql如下:
ALTER TABLE table MODIFY ( price DECIMAL(10, 2) COMMENT '价格' AFTER `name` #修改价格 ts AS TO_TIMESTAMP(cts) AFTER cts, #修改时间 PRIMARY KEY (id) NOT ENFORCED, #修改主键 WATERMARK FOR ts AS ts -- modify watermark strategy #修改水印 );
3)drop某个字段
ALTER TABLE table DROP price; #删除某个字段 ALTER TABLE table DROP (col1, col2, col3); #删除多个字段 ALTER TABLE table DROP PRIMARY KEY; #删除主键 ALTER TABLE table ble DROP WATERMARK; #删除水印
4)rename
这个rename函数一般用于重命名表明或者列名,例如:
ALTER TABLE table RENAME price TO prices; ALTER TABLE table RENAME TO table2;
5)set
为表设置1个或多个属性值
ALTER TABLE table SET ('rows-per-second' = '10');
6)reset
这里是吧某些属性值设置回默认值,例如:
ALTER TABLE table RESET ('rows-per-second');
alter view
这里主要是修改视图,一般我们会涉及到的主要是重命名视图和重新修改整个视图sql。
重命名视图:
ALTER VIEW [catalog_name.][db_name.]view_name RENAME TO new_view_name
重新修改整个视图的查询sql
ALTER VIEW [catalog_name.][db_name.]view_name AS select ...
alter database
修改数据库,对于数据库来说我们常用的主要是设置的数据库的属性值,例如:
ALTER DATABASE [catalog_name.]db_name SET (key1=val1, key2=val2, ...)
alter function
修改函数方法,整个语法结构如下:
ALTER [TEMPORARY|TEMPORARY SYSTEM] FUNCTION [IF EXISTS] [catalog_name.][db_name.]function_name AS identifier [LANGUAGE JAVA|SCALA|PYTHON]
对于这里面的用法字段说明如下:
TEMPORARY 修改一个有 catalog 和数据库命名空间的临时 catalog function ,并覆盖原有的 catalog function 。 TEMPORARY SYSTEM 修改一个没有数据库命名空间的临时系统 catalog function ,并覆盖系统内置的函数。 IF EXISTS 若函数不存在,则不进行任何操作。 LANGUAGE JAVA|SCALA|PYTHON Language tag 用于指定 Flink runtime 如何执行这个函数。目前,只支持 JAVA,SCALA 和 PYTHON,且函数的默认语言为 JAVA。
还没有评论,来说两句吧...