Updated on 2022-09-14 GMT+08:00

Example Codes

Function Description

Random data is generated by following the rule that one piece of data is generated per second, and the data is sent to other operators for processing. All data whose ID is greater than 5 is filtered out, data is grouped by field type, the number of types is calculated every 20 seconds, and results are recorded in application log files.

Code Sample

The following provides CQL statement examples. Such CQL statements are in the example.cql file in the src/main/resources directory of the sample project.

/*
 * CQL sample project, used for generating random data in the operator for generating random data.
 * Record processed data on a console (in log files). 
 */

--Generate one piece of random data per second. 
CREATE INPUT STREAM s
(id INT, name STRING, type INT)
 SOURCE randomgen
           PROPERTIES
           ( "timeUnit" = "SECONDS", "period" = "1",
           "eventNumPerPeriod" = "1", "isSchedule" = "true");

--Record calculation results on a console (in log files). 
CREATE OUTPUT STREAM rs
(type INT, cc INT)
 SINK ConsoleOutput;

--Calculate the data whose ID is greater than 5 every 20 seconds and group the data by field type.
--Time jump window, generating calculation results every 20 seconds.
INSERT INTO STREAM rs SELECT type, count(id) as cc 
 FROM s[RANGE 20 SECONDS BATCH] WHERE id > 5 GROUP BY type;
--Submit an application.
SUBMIT APPLICATION example;

Precautions

If the security service is enabled for a cluster, verify that you have logged in in security mode before submitting an application.

If the CQL statement contains Chinese characters, change the encoding format of the Linux SSH client to UTF-8.