This topic describes how to create a data view in Realtime Compute for Apache Flink to simplify the development process.
Background information
If your business logic is complex, you must write nested statements in a DML statement,
which makes it difficult to locate a problem. To simplify the development process,
you can define a data view and write nested statements to the data view.
Note A data view displays a logical table that describes the computing logic. It does not
physically store data.
Syntax
CREATE VIEW viewName[ (columnName[ , columnName]* ) ] AS queryStatement;
- viewName: the name of the view.
- columnName: the name of the field.
- queryStatement: the alias of the nested statement.
Example 1
CREATE VIEW LargeOrders (r, t, c, u) AS
SELECT
rowtime,
productId,
c,
units
FROM
orders;
INSERT INTO
rds_output
SELECT
r,
t,
c,
u
FROM
LargeOrders;
Example 2
- Test data
a (VARCHAR) b (BIGINT) c (TIMESTAMP) test1 1 1506823820000 test2 1 1506823850000 test1 1 1506823810000 test2 1 1506823840000 test2 1 1506823870000 test1 1 1506823830000 test2 1 1506823860000 - Test statements
CREATE TABLE datahub_stream ( a VARCHAR, b BIGINT, c TIMESTAMP, d AS PROCTIME() ) WITH ( TYPE='datahub', ... ); CREATE TABLE rds_output ( a VARCHAR, b TIMESTAMP, cnt BIGINT, PRIMARY KEY(a) )WITH( TYPE = 'rds', ... ); CREATE VIEW rds_view AS SELECT a, CAST( HOP_START(d, INTERVAL '5' SECOND, INTERVAL '30' SECOND) AS TIMESTAMP ) AS cc, SUM(b) AS cnt FROM datahub_stream GROUP BY HOP(d, INTERVAL '5' SECOND, INTERVAL '30' SECOND),a; INSERT INTO rds_output SELECT a, cc, cnt FROM rds_view WHERE cnt=4;
- Test results
a(VARCHAR) b (TIMESTAMP) cnt (BIGINT) test2 2017-11-06 16:54:10
4