创建 DEPLOYMENT#

Syntax#

CreateDeploymentStmt
						::= 'DEPLOY' [DeployOptions] DeploymentName SelectStmt

DeployOptions(可选)
						::= 'OPTIONS' '(' DeployOptionItem (',' DeployOptionItem)* ')'

DeploymentName
						::= identifier

DeployOptions的定义详见DEPLOYMENT属性DeployOptions(可选).

DEPLOY语句可以将SQL部署到线上。OpenMLDB仅支持部署Select查询语句,并且需要满足OpenMLDB SQL上线规范和要求

DEPLOY deployment_name SELECT clause

Example: 部署一个SQL到online serving#

CREATE DATABASE db1;
-- SUCCEED: Create database successfully

USE db1;
-- SUCCEED: Database changed

CREATE TABLE t1(col0 STRING);
-- SUCCEED: Create successfully

DEPLOY demo_deploy select col0 from t1;
-- SUCCEED: deploy successfully

查看部署详情:

SHOW DEPLOYMENT demo_deploy;
 ----- ------------- 
  DB    Deployment   
 ----- ------------- 
  db1   demo_deploy  
 ----- ------------- 
 1 row in set
 
 ---------------------------------------------------------------------------------- 
  SQL                                                                               
 ---------------------------------------------------------------------------------- 
  CREATE PROCEDURE deme_deploy (col0 varchar) BEGIN SELECT
  col0
FROM
  t1
; END;  
 ---------------------------------------------------------------------------------- 
1 row in set

# Input Schema
 --- ------- ---------- ------------ 
  #   Field   Type       IsConstant  
 --- ------- ---------- ------------ 
  1   col0    kVarchar   NO          
 --- ------- ---------- ------------ 

# Output Schema
 --- ------- ---------- ------------ 
  #   Field   Type       IsConstant  
 --- ------- ---------- ------------ 
  1   col0    kVarchar   NO          
 --- ------- ---------- ------------ 

DEPLOYMENT属性DeployOptions(可选)#

DeployOptions
						::= 'OPTIONS' '(' DeployOptionItem (',' DeployOptionItem)* ')'

DeployOptionItem
						::= LongWindowOption

LongWindowOption
						::= 'LONG_WINDOWS' '=' LongWindowDefinitions

目前只支持长窗口LONG_WINDOWS的优化选项。

长窗口优化#

长窗口优化选项格式#
LongWindowDefinitions
						::= 'LongWindowDefinition (, LongWindowDefinition)*'

LongWindowDefinition
						::= 'WindowName[:BucketSize]'

WindowName
						::= string_literal

BucketSize(可选,默认为)
						::= int_literal | interval_literal

interval_literal ::= int_literal 's'|'m'|'h'|'d'(分别代表秒、分、时、天)

其中BucketSize为性能优化选项,会以BucketSize为粒度,对表中数据进行预聚合,默认为1d

示例如下:

DEPLOY demo_deploy OPTIONS(long_windows="w1:1d") SELECT col0, sum(col1) OVER w1 FROM t1
    WINDOW w1 AS (PARTITION BY col0 ORDER BY col2 ROWS_RANGE BETWEEN 5d PRECEDING AND CURRENT ROW);
-- SUCCEED: deploy successfully
限制条件#

目前长窗口优化有以下几点限制:

  • 仅支持SelectStmt只涉及到一个物理表的情况,即不支持包含joinunionSelectStmt

  • 支持的聚合运算仅限:sum, avg, count, min, max

  • 执行deploy命令的时候不允许表中有数据

相关SQL#

USE DATABASE

SHOW DEPLOYMENT

DROP DEPLOYMENT