You can define schemas as named objects at the application level. Named schemas and their fields can be referenced in any component that takes a schema, and in expressions throughout the application. By contrast, private or unnamed schemas are accessible only to connected downstream components in the application flow.
In EventFlows, you can create and view named schemas in the Named Schemas tab of the EventFlow Editor. To create and share a named schema:
-
Open the Named Schemas tab.
-
Click the Add button.
-
In the Edit Saved Schema dialog, enter a schema name.
-
Populate the schema fields using one of these methods:
-
To define the fields manually, use the
button at the top of the
tab to add a row for each schema field. Enter values for the Field Name
and Type, and if necessary, the Size. The Description is optional. For
example:
Field Name Type Size Description symbol string 10 Stock symbol quantity int 4 Number of shares The name must begin with an alphabetic character or an underscore, can contain only alphabetic characters, numbers, and underscores, and cannot contain hyphens or other special characters.
The type must be one of the supported StreamBase Data Types. The editor fills in the size for data types with fixed sizes, but you must enter a valid size for strings and blobs, which are variable-length.
-
You can reuse an existing schema whose fields are appropriate for this component and your application. It can be a schema that you previously saved, one that you imported from your file system (as described in Importing and Exporting Resources), or one that exists in another application. To do so, click the
button. If prompted to save the
application at this point, click to
continue.
In the Copy Schema dialog, identify the schema you want. See Copying Schemas for details.
The schema fields are loaded in your Fields table.
Tip
Alternatively, you can drag a saved schema from the Saved Schemas view and drop it onto the schema table in the Edit Schema tab. If you already have entries in the table, StreamBase prompts for permission to replace them with the contents of the schema you are copying.
In addition to the button, you can use the , , and buttons to edit and order your schema fields. If you have copied a schema, remember that this is a local copy: Any changes you make here do not affect the original schema that you copied.
-
-
Click to add the schema to your Named Schemas tab.
The new schema is added to the tree list of named schemas in the tab. You can manage items in the list using either the buttons or the context menu commands.
After you have created a named schema, you can use it in any component that requires a schema. To learn how, see the Edit Schema Tab section of the help topic for any of these components:
Please see the CREATE SCHEMA Statement topic to learn how to declare named schemas in StreamSQL applications. After creating a named schema, you can use it in the schema declarations of::
You can reference named schemas and their fields in the same StreamSQL constructs that reference anonymous schemas, as described in SELECT Statement.
After a named schema is created, you can refer to it in other parts of your application. In general, any statement that can reference an anonymous schema can reference a named schema. For example, suppose we define a named schema and an input stream that references it, as in these StreamSQL statements:
CREATE SCHEMA point(x double, y double); CREATE INPUT STREAM in (tag string(12), p point);
In the anonymous schema of the input stream, the p field is a tuple whose schema is
(x double, y double).
-
You can reference fields within named schemas using a dotted notation, like this:
SELECT x + point.y FROM in INTO out
-
You can use the identifier of a named schema to invoke the
tuple()function to create a tuple, as described in tuple( e [,...]). This example creates a tuple with two values corresponding to the fields of the named schema,point.SELECT point(1,2) as p FROM in INTO out
In this case, the integers provided in the argument are converted to doubles, as specified in the schema. The resulting tuple contains the value
(1.0,2.0). -
In StreamSQL, you can rename references to schemas and their fields using the AS method:
SELECT point(1,2) AS p FROM in INTO out SELECT tuple(x, point.y AS z) FROM in INTO out
The first statement above results in a tuple named p whose schema is the same as
point. The second statement results in a tuple with the schema(x double, z.double).
See tuple for details about using tuple data in expressions.
-
StreamSQL: CREATE SCHEMA Statement for information about defining named schemas.
-
StreamSQL: SELECT Statement for information about using named schemas.
