When a USING HYGIENIC statement appears in a StreamSQL module, the schemas of all Module References to the module must be strictly compatible with the number and data types of the module's input streams, or the data types must be compatibly coercible to the module's data types.
The USING HYGIENIC statement must appear before the first CREATE INPUT STREAM in the module in order to be effective. Modules with input streams created without a preceding USING HYGIENIC statement are called non-hygienic, because they are able to override input schemas as long as the schemas satisfy their processing requirements.
You declare a module as non-hygienic by not declaring it hygienic. That is, there is no USING NON-HYGIENIC statement.
The following example shows the difference between declaring a module as hygienic or non-hygienic.
The file HygienicModule.ssql
defines the hygienic
module:
USING HYGIENIC; CREATE SCHEMA InSchema (a int, b long, c string); CREATE INPUT STREAM In InSchema; CREATE OUTPUT STREAM Out AS select * from In;
The file FlexibleModule.ssql
defines the non-hygienic
module:
CREATE SCHEMA InSchema (a int, b long, c string); CREATE INPUT STREAM In InSchema; CREATE OUTPUT STREAM Out AS select * from In;
The file OuterModule.ssql
incorporates both modules,
using the first one hygienically and the second one flexibly:
CREATE INPUT STREAM In ( a int, b long, c string, d boolean ); CREATE OUTPUT STREAM HygienicOut; CREATE OUTPUT STREAM FlexibleOut; APPLY MODULE "HygienicModule.ssql" AS HygienicModuleBRef1 FROM In = In INTO Out = HygienicOut; APPLY MODULE "FlexibleModule.ssql" AS FlexibleModuleBRef1 FROM In = In INTO Out = FlexibleOut;
When OuterModule.ssql
runs, it sends four fields to
each submodule. The FlexibleOut output stream includes all four fields. The
HygienicOut output stream includes fields a, b, and c, but not d, because it is not
allowed to have its input schema overridden by a caller.