This sample illustrates how certain numeric data types can "coerce"; that is, how same-named field values with certain compatible types can all appear to be carried by a new field with a type compatible with all original values. It consists of a Studio project containing a single application file (Coercions.sbapp).
The application illustrates some of the basic types that are coercible:
int and double coerce to double
int and long coerce to long
As the sample application shows, coercion also takes place when the fields are lists-of each type, or are individual fields within a field of type tuple.
Rearrange the arcs and try connecting the unconnected input streams to explore which types do not coerce: double will not coerce to long (loss of data from long type) no types coerce to string, timestamp or blobs
For details on type coercion, see Data Type Coercion and Conversion in the StreamBase Reference documentation.
The Type Coercion sample consists of the files shown in the following table.
||An EventFlow application illustrates which data types are compatible and in what ways.|
||The file describing how the application is laid out in StreamBase Studio.|
In the EventFlow editor, you can explore which data types can be coerced together and which may not. Follow these steps to explore this sample in the EventFlow editor:
In the Project Explorer, double-click to open the
Coercions.sbappapplication. Make sure the application is the currently active tab in the EventFlow Editor.
Notice that there are two groups of input streams, union operators, and output streams, called Lists and Tuples. The only difference between them is their schemas.
In the Lists group, hover the mouse pointer over the arc exiting the intmeetslong Union operator (bottom right).
Notice that its schema is list(long). This is because it is coercing its inputs, one of which is list(int) and the other of which is list(long), to data type long.
Click on the arc exiting the input stream ListOfDouble near its arrowhead.
Notice that its schema is list(double).
Drag the arc away from the intmeetsdouble Union operator and instead connect it to the intmeetslong Union operator.
A new input port on the intmeetslong Union operator appears to receive the arc.
Again, hover the mouse pointer over the arc exiting the intmeetslong Union operator.
Notice that the schema of that arc has changed from list(long) to list(double) as the result of type coercion.
Try connecting the input streams ListOfTimestamp and ListOfString to either Union operator in its group. What happens? Hover over the Union operator to see.
If you want to undo any change you have made to the diagram, click→ or type
Repeat any of the above steps on the components in the Tuples group. Observe how it behave similarly to the Lists group.
If the application has no typecheck errrors, you can click the Run button to send lists and tuples to it. (You may be asked to save the application first, which you should do.)
The SB Test/Debug perspective opens and the application starts.
In the Manual Input view, select.
Click the green mylist to add a list element.button to the right of
Enter an integer in the mylist(0) field
Optionally repeat steps 9 and 10 to add more list elements and enter their values.
In the application output view, observe the values in the OutListOfLong and OutListOfDouble streams and notice where type coercion has occurred.
Select a different input stream and repeat steps 10–13 to observe when coercion takes place.
When done, press F9 or click the Stop Running Application button.
In StreamBase Studio, import this sample with the following steps:
From the top menu, click→ .
Select this application from the Applications list.
StreamBase Studio creates a project for each sample.
When you load the sample into StreamBase Studio, Studio copies the sample project's files to your Studio workspace, which is normally part of your home directory, with full access rights.
Load this sample in StreamBase Studio, and thereafter use the Studio workspace copy of the sample to run and test it, even when running from the command prompt.
Using the workspace copy of the sample avoids permission problems. The default workspace location for this sample is:
See Default Installation Directories for the location of
studio-workspace on your system.
In the default TIBCO StreamBase installation, this sample's files are initially installed in:
See Default Installation Directories for the default location of
studio-workspace on your system.