Reference¶
Part of Streaming Transformations. See all pages in this section.
This page shows the complete CREATE PIPE syntax with every in-flight transformation enabled, and a full example that combines them with an insert-triggered materialized view. For a first pipe, start with Pipe Creation.
Full syntax¶
(1) <select_list> may call scalar UDFs — SQL, JavaScript, SECURE, IMMUTABLE, and MEMOIZABLE — including a UDF that returns an ARRAY, which (2) or (4) can then flatten. When the derived table in (2) is present, <select_list> can reference only the columns that the inner SELECT projects, addressed through <source_alias>.
(2) Optional derived table, used to expand a streamed record into multiple rows before the dimension join. The bracketed lines form a single unit: either include all of them — the opening ( SELECT <inner_select_list> FROM, the LATERAL FLATTEN line, and the closing ) <source_alias> — or omit all of them and select directly from TABLE(DATA_SOURCE(TYPE => 'STREAMING')) <stream_alias>.
(3) The LEFT OUTER JOIN clause may be repeated once for each dimension table. A maximum of 4 dimension tables per PIPE are supported. Dimension tables are initially limited to approximately 1 GB per table, ramping to approximately 10 GB per table.
(4) LATERAL FLATTEN after the dimension join, typically over an array column of a dimension table.
(5) Records that don’t satisfy the predicate are silently discarded before they land. The predicate can reference stream columns (positional $n notation), columns of the joined dimension tables, flattened values, and scalar UDFs. It can’t contain subqueries, Python, Java, and Scala language handlers, along with UDAFs, UDTFs, external functions, and Cortex AI functions, window functions, or FLATTEN. See Stream filtering.
Parameters:
<target_table>— Required name of the destination table. Interactive tables, standard Snowflake tables, and managed Iceberg tables are currently supported.ERROR_LOGGINGmust not be enabled on the target table of aPIPEthat usesLATERAL FLATTEN. See Limitations.<select_list>— Expressions written to the target columns, in the same order as the column list. May call scalar UDFs, including a UDF returning anARRAYthat is then flattened. See footnote (1).<inner_select_list>— Expressions projected out of the derived table when flattening before a dimension join. Must include every column referenced outside it, including the column used in<join_condition>.<stream_alias>— Required alias for the streaming source when dimension joins orLATERAL FLATTENare present. Used to qualify stream column references inONandSELECTclauses (for example,s.$1:user_id::INT).<array_expr>— Expression yielding the array to expand, read from the streamed record. A path such ass.$1:items, or a UDF returning anARRAY.<flat_alias>— Alias for theFLATTENresult. Used to qualify its columns (VALUE,INDEX,KEY,PATH,THIS,SEQ), for examplef.value::INT. Inside a derived table it is not visible outside it.<source_alias>— Required alias for the derived table when flattening before a dimension join. Qualifies the expanded rows in theON,SELECT, andWHEREclauses.<dim_table>— Fully qualified name of the dimension (lookup) table. See Dimension table requirements.<join_condition>— Pure (fully qualified) equi-join on the dimension table primary key. See ON clause requirements.<dim_array_expr>— Expression yielding the array to expand after the join, typically an array column of the dimension table.<flat_alias2>— Alias for theFLATTENresult after the join.<filter_predicate>— Boolean expression applied to stream records before enrichment, or to the expanded rows when it references flattened values. See WHERE clause syntax.
Note
An explicit column list is required in both the COPY INTO target and the SELECT subquery. MATCH_BY_COLUMN_NAME is not supported when dimension joins are present.
Full example¶
The following example combines multiple features on one stream of batched device messages:
- A SQL scalar UDF (
site_timezone) in theSELECTlist. LATERAL FLATTENof thereadingsarray in a derived table, before the dimension join.- A
LEFT OUTER JOINwith a dimension table (dim_tags) to add a readable name and unit. - A
WHEREclause on a stream column and on a dimension key. - An insert-triggered materialized view (
readings_per_tag) on the target table, created before the pipe.
Each streamed record carries an array of readings:
The pipe lands one row per known tag with its name, unit, and local time, and the view keeps the totals per tag up to date. The reading for the unknown tag T999 is filtered out.
See also¶
See Stream filtering, Stream enrichment, Custom scalar logic, Lateral Flatten, and Insert-triggered materialized views for more information on the individual transformations. The Scenarios show real-world use cases that combine multiple transformations.
Previous: Insert-triggered materialized views · Next: Scenarios