更新时间:2022-12-07 GMT+08:00

SQL语法约束与定义

语法约束

  • 当前Flink SQL只支持SELECT,FROM,WHERE,UNION,聚合,窗口,流表JOIN以及流流JOIN。
  • 数据不能对Source流做insert into操作。
  • Sink流不能用来做查询操作。

语法支持范围

  • 基础类型: VARCHAR,STRING,BOOLEAN,TINYINT,SMALLINT,INTEGER/INT,BIGINT,REAL/FLOAT,DOUBLE,DECIMAL,DATE,TIME,TIMESTAMP
  • Array:使用[]进行引用。例如:
    1
    insert into temp select CARDINALITY(ARRAY[1,2,3]) FROM OrderA;
    

语法定义

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
INSERT INTO stream_name query;
query:
  values
  | {
      select
      | selectWithoutFrom
      | query UNION [ ALL ] query
    }

orderItem:
  expression [ ASC | DESC ]

select:
  SELECT 
  { * | projectItem [, projectItem ]* }
  FROM tableExpression [ JOIN tableExpression ]
  [ WHERE booleanExpression ]
  [ GROUP BY { groupItem [, groupItem ]* } ]
  [ HAVING booleanExpression ]

selectWithoutFrom:
  SELECT [ ALL | DISTINCT ]
  { * | projectItem [, projectItem ]* }

projectItem:
  expression [ [ AS ] columnAlias ]
  | tableAlias . *

tableExpression:
  tableReference 

tableReference:
  tablePrimary
  [ [ AS ] alias [ '(' columnAlias [, columnAlias ]* ')' ] ]

tablePrimary:
  [ TABLE ] [ [ catalogName . ] schemaName . ] tableName
  | LATERAL TABLE '(' functionName '(' expression [, expression ]* ')' ')'
  | UNNEST '(' expression ')'

values:
  VALUES expression [, expression ]*

groupItem:
  expression
  | '(' ')'
  | '(' expression [, expression ]* ')'
  | CUBE '(' expression [, expression ]* ')'
  | ROLLUP '(' expression [, expression ]* ')'
  | GROUPING SETS '(' groupItem [, groupItem ]* ')'