feat(flink): support NOT NULL syntax (#103)

* feat(flink): support NOT NULL syntax

* feat(flinksql): support NULL
This commit is contained in:
野迂迂 2023-05-23 10:12:05 +08:00 committed by GitHub
parent 40c911597b
commit 4b824fb500
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 2086 additions and 1956 deletions

View File

@ -180,7 +180,7 @@ rowTypeDimension
; ;
columnConstraint columnConstraint
:(KW_CONSTRAINT constraintName)? KW_PRIMARY KW_KEY KW_NOT KW_ENFORCED :(KW_CONSTRAINT constraintName)? KW_PRIMARY KW_KEY (KW_NOT KW_ENFORCED)? | KW_NOT? KW_NULL
; ;
commentSpec commentSpec

View File

@ -1,4 +1,4 @@
// Generated from /Users/hayden/Desktop/dt-works/dt-sql-parser/src/grammar/flinksql/FlinkSqlLexer.g4 by ANTLR 4.12.0 // Generated from /Users/mortalYoung/Projects/dt-sql-parser/src/grammar/flinksql/FlinkSqlLexer.g4 by ANTLR 4.12.0
// noinspection ES6UnusedImports,JSUnusedGlobalSymbols,JSUnusedLocalSymbols // noinspection ES6UnusedImports,JSUnusedGlobalSymbols,JSUnusedLocalSymbols
import { import {
ATN, ATN,

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
// Generated from /Users/hayden/Desktop/dt-works/dt-sql-parser/src/grammar/flinksql/FlinkSqlParser.g4 by ANTLR 4.12.0 // Generated from /Users/mortalYoung/Projects/dt-sql-parser/src/grammar/flinksql/FlinkSqlParser.g4 by ANTLR 4.12.0
import {ParseTreeListener} from "antlr4"; import {ParseTreeListener} from "antlr4";

View File

@ -1,4 +1,4 @@
// Generated from /Users/hayden/Desktop/dt-works/dt-sql-parser/src/grammar/flinksql/FlinkSqlParser.g4 by ANTLR 4.12.0 // Generated from /Users/mortalYoung/Projects/dt-sql-parser/src/grammar/flinksql/FlinkSqlParser.g4 by ANTLR 4.12.0
import {ParseTreeVisitor} from 'antlr4'; import {ParseTreeVisitor} from 'antlr4';

View File

@ -2,6 +2,15 @@ CREATE TABLE MyTable ('user_id' BIGINT, 'name' STRING) WITH ('connector' = 'orac
CREATE TABLE MyTable WITH ('connector' = 'oracle-x'); CREATE TABLE MyTable WITH ('connector' = 'oracle-x');
CREATE TEMPORARY TABLE client_errors (
log_time TIMESTAMP(3),
request_line STRING,
status_code STRING,
size INT
) WITH (
'connector' = 'stream-x'
);
-- 尽管官方文档的 BNF 里没有支持创建临时表,但实际上是支持的 -- 尽管官方文档的 BNF 里没有支持创建临时表,但实际上是支持的
CREATE TEMPORARY TABLE MyTable ('user_id' BIGINT, 'name' STRING) WITH ('connector' = 'oracle-x'); CREATE TEMPORARY TABLE MyTable ('user_id' BIGINT, 'name' STRING) WITH ('connector' = 'oracle-x');
@ -231,4 +240,65 @@ CREATE TABLE tbl1 (
) LIKE Orders ( ) LIKE Orders (
OVERWRITING OPTIONS OVERWRITING OPTIONS
EXCLUDING CONSTRAINTS EXCLUDING CONSTRAINTS
);
CREATE TEMPORARY TABLE server_logs (
client_ip STRING,
client_identity STRING,
userid STRING,
user_agent STRING,
log_time TIMESTAMP(3),
request_line STRING,
status_code STRING,
size INT
) WITH (
'connector' = 'faker'
);
CREATE TEMPORARY TABLE aggregations1 (
`browser` STRING,
`status_code` STRING,
`end_time` TIMESTAMP(3),
`requests` BIGINT NOT NULL
) WITH (
'connector' = 'blackhole'
);
CREATE TABLE dt_catalog.dt_db.doctor_sightings (
doctor STRING,
sighting_time TIMESTAMP(3),
WATERMARK FOR sighting_time AS sighting_time - INTERVAL '15' SECONDS
) WITH (
'connector' = 'faker'
);
CREATE TABLE dt_catalog.dt_db.bids (
bid_id STRING,
currency_code STRING,
bid_price DOUBLE,
transaction_time TIMESTAMP(3),
WATERMARK FOR transaction_time AS transaction_time - INTERVAL '5' SECONDS -- 定义事件时间允许的最大窗口延迟为5s
) WITH (
'connector' = 'faker'
);
CREATE TABLE dt_catalog.dt_db.currency_rates (
`currency_code` STRING,
`eur_rate` DECIMAL(6,4),
`rate_time` TIMESTAMP(3),
WATERMARK FOR `rate_time` AS rate_time - INTERVAL '15' SECONDS, -- 定义事件时间
PRIMARY KEY (currency_code) NOT ENFORCED -- 定义主键
) WITH (
'connector' = 'faker'
);
CREATE TABLE dt_catalog.dt_db.users (
-- That was weird, NOT ENFORCED should have been necessary but we got a demo like the following and it could work!
user_id INT PRIMARY KEY,
user_name VARCHAR(255) NOT NULL,
age INT NULL
) WITH (
'connector' = 'faker'
); );

View File

@ -34,4 +34,23 @@ CREATE TEMPORARY VIEW IF NOT EXISTS v AS
SELECT SELECT
col1 col1
FROM FROM
tbl; tbl;
CREATE TEMPORARY VIEW browsers AS
SELECT
REGEXP_EXTRACT(user_agent,'[^\/]+') AS browser,
status_code,
log_time
FROM
server_logs;
CREATE VIEW server_logs_window_1m AS
SELECT
TUMBLE_START(log_time, INTERVAL '1' MINUTE) AS window_start,
TUMBLE_ROWTIME(log_time, INTERVAL '1' MINUTE) AS window_end,
SUM(size) AS total_size,
COUNT(*) AS num_requests
FROM
server_logs
GROUP BY
TUMBLE(log_time, INTERVAL '1' MINUTE);