CREATE STREAM Statement

Create either an input stream that receives events from external sources, or a derived stream of events that is the result of a continuous query applied to one or more inputs.

Syntax

CREATE INPUT STREAM name schema_clause
filter-expression-clause
;

CREATE [ LOCAL | OUTPUT ] STREAM name [ schema_clause ]
 [ local-declare-block ]
as_clause
;

Components

schema_clause Specifies the schema. The schema clause is required for input streams, but is optional for local and output streams. If the schema is not specified for local and output streams, it is deduced automatically by the compiler based on the query specification.
filter-expression-clause Can be specified on an input stream. This clause filters the events before accepting them from the adapter or an outside publisher.

Specify columns in the format node name.column name. For an input stream, use the stream name for the node name. For local or output streams, use the name or its alias from the FROM clause.

local-declare-block Allows variable and function declarations that can be accessed in expressions in the query. You cannot define a local-declare-block on an input stream.
as_clause Introduces a query to a statement.

Usage

The CREATE STREAM statement explicitly creates a stateless element known as a stream, which can be designated as input, output, or local. Input streams include a mandatory schema, and may include an optional filter expression that can remove unneeded data before further processing. Each incoming event is processed, any output is published, and then the stream is ready to process the next event.

Output and local streams have an optional schema. They can contain a local declare block to define variables and functions that can be used in the SELECT clause of the query.

Example

This creates an input stream with a filter:

CREATE INPUT STREAM InStr
SCHEMA (Col1 INTEGER, Col2 STRING)
WHERE InStr.Col2='abcd';

This creates an output stream where the schema is implicitly determined by the SELECT clause:

CREATE OUTPUT STREAM OutStr as
SELECT InStr.Col1, InStr.Col2 
FROM InStr 
WHERE InStr.Col1 > 1000;
Related reference
SCHEMA Clause
WHERE Clause
DECLARE Statement
SELECT Clause
FROM Clause: ANSI Syntax
FROM Clause: Comma-Separated Syntax
AS Clause