CLI

    There are two kinds of commands:

    1. SQL statements end with ;

    To Quit current cli session:

    1. > :q

    To print out help info over view:

    1. > :h

    To show specific usage of some sql statement:

    1. > :help CREATE
    2. CREATE STREAM <stream_name> [IF EXIST] [AS <select_query>] [ WITH ( {stream_options} ) ];
    3. CREATE {SOURCE|SINK} CONNECTOR <stream_name> [IF NOT EXIST] WITH ( {connector_options} );
    4. CREATE VIEW <stream_name> AS <select_query>;

    Available sql operations includes: CREATE, DROP, SELECT, SHOW, INSERT, TERMINATE.

    SQL Statements

    All the processing and storage operations are done via SQL statements.

    There are two ways to create a new data stream.

    1. Create an ordinary stream:

    This will create a stream with no special function. You can SELECT data from the stream and INSERT to via corresponding SQL statement.

    Adding an Select statement after Create with a keyword AS can create a stream will create a stream which processing data from another stream.

    For example:

    After Creating the stream, we can insert values into the stream.

    1. INSERT INTO stream_name (field1, field2) VALUES (1, 2);

    There is no restriction on the number of fields a query can insert. Also, the type of value are not restricted. However, you do need to make sure that the number of fields and the number of values are aligned.

    Select data from a stream

    When we have a stream, we can select data from the stream in real-time. All the data inserted after the select query is created will be print out when the insert operation happens. Select supports real-time processing on the data inserted to the stream.

    For example, we can choose the field and filter the data selected from the stream.

    1. SELECT a FROM demo EMIT CHANGES;

    This will only select field a from stream demo.

    Terminate a query

    A query can be terminated if the we know the query id:

    1. TERMINATE QUERY <id>;

    We can get all the query information by command SHOW:

    1. SHOW QUERIES;

    output just for demonstration :

    Find the query to terminate, make sure is id not already terminated, and pass the query id to TERMINATE QUERY

    Or under some circumstances, you can choose to TERMINATE ALL ;.

    Delete a stream

    For example:

    1. SELECT * FROM demo EMIT CHANGES;

    will be terminated if the stream demo is deleted;

    1. DROP STREAM demo;

    If you try to delete a stream that does not exist, an error message will be returned. To turn it off, you can use add IF EXISTS after the stream_name:

    1. DROP STREAM demo IF EXISTS;

    Show all streams

    You can also show all streams by using the SHOW STREAMS command.

    View

    View is a projection of specified data from streams. For example,

    1. CREATE VIEW v_demo AS SELECT SUM(a) FROM demo GROUP BY a EMIT CHANGES;

    the above command will create a view which keep track of the sum of a (which have the same values,because of group by) and have the same value from the point this query is executed.

    The operations on view are very similar to those on streams.

    Except we can not use SELECT ... EMIT CHANGES performed on streams, because a view is static and there are no changes to emit. Instead, for example we select from view with:

    This will print the sum of a when a = 1.

    1. CREATE STREAM demo2 AS SELECT a, 1 AS b FROM demo EMIT CHANGES;
    2. CREATE VIEW v_demo2 AS SELECT SUM(a) FROM demo2 GROUP BY b EMIT CHANGES;