Define a stream type

Rather than separately define the schema (stream type) in the declaration of each stream, create a type first so that each stream can simply refer to that type. Keeping the type definition in one place eliminates code duplication, and improves consistency and maintainability.

Create a type named LocationType for the vehicle location data that will be the main kind of tuple flowing through the application.

Use the following information to create the stream type:

Name Type Comments
id rstring Vehicle ID (an rstring uses “raw” 8-bit characters)
time int64 Observation timestamp
(milliseconds since 00:00:00 on January 1, 1970)
latitude float64 Latitude (degrees)
longitude float64 Longitude (degrees)
speed float64 Vehicle speed (km/h)
heading float64 Direction of travel (degrees, clockwise from north)

 

To define a stream type:

  1. In the graphical editor, right-click anywhere on the canvas outside the main composite (MyMainComposite), and click Edit.
    You see a Properties view, which floats above all the other views. Be sure that it looks the same as the following screen capture with the three tabs for General, Uses, and Types. If your Properties view does not look the same as the screen capture, dismiss the view and right-click again in the graphical editor outside the main composite.
  2. In the Properties view, click Types.
  3. Click Add New Type in the Name column.
  4. Enter LocationType, and then press Enter.
  5. Click Add Attribute below LocationType in the Name column, and enter id.
  6. Press the Tab key to go to the Type column, and enter rstring.
    Tip for content assist: In the Type column, press Ctrl+Space to get a list of available types. Begin typing (for example, “r” for rstring) to narrow down the list. When the type you want is selected, press Enter to assign it to the field. This reduces keyboard effort and typing errors.
  7. Press the Tab key to go to the next Name field.
  8. Enter the attribute names and types listed in the table above.
  9. Leave the Properties view open.
    Tip for obscured views: The floating Properties view might obscure other views. An alternative is to use the Properties tab in the view at the bottom of the perspective.
  10. Check your results. The fields should look like the following screen capture:
    The tuple type LocationType is now available for you to use as a stream type in any main composite within the namespace my.name.space.