- Index

< Previous |  | Next >

# Referencing a Module

This topic explains how to reference one application module from another module. The procedure is either graphical or text-based, depending on whether the reference is in an EventFlow or in a StreamSQL application.

## Before You Begin

Both procedures in this topic assume that you have performed the prerequisite tasks outlined in Using Modules:

- You have created an application module (or will use an existing module) that is compatible with the main application you will reference it from.

- The schema field names and types must be the same; the order of fields can be different.

- The referencing module must be able to locate the referenced module in its module search path.

## Referencing a Module in an EventFlow Application

In an EventFlow, a module reference is represented as a single component that you insert onto the canvas. Just like any other component, it can be connected to other components and has properties that can be edited and typechecked.

1. In the StreamBase Studio SB Authoring perspective, open the EventFlow module that will contain the module reference.

2. In the Editor tab, insert an application module in the EventFlow Editor canvas by using one of these methods:

   - Open the Module Explorer view, which shows all EventFlow and StreamSQL modules in the current module search path. Select the module of interest and drag it to the canvas. This creates a new Module Reference for the selected module, with input and output ports already in place, based on the input and output streams of the selected module. The new Module Reference has a yellow background to indicate that its ports are not yet connected.

   - Drag an unconfigured Module Reference icon from the Palette view to the canvas. This opens a File Chooser dialog showing all EventFlow and StreamSQL files in the module search path (essentially duplicating the Module Search Path view in the dialog). Select a module file, and an module reference is placed on the canvas.

     This method creates an unconfigured Module Reference on the canvas, that is associated with the selected module, but does not yet have input and output ports. You must edit its properties and address those problems in the next steps.

3. Open the Properties view for the new Module Reference, as described in Using the Module Reference Component. (Changing Module Reference properties does not change the module being referenced; changes are local and only affect the referencing module.)

   If you dragged an icon from the Palette view, you must configure input and output port associations in the Input Ports and Output Ports tabs of the new Module Reference's Properties view.

4. If the referenced application contains parameters, you may need to set or modify the parameter values, as described in Using Module Parameters.

5. Draw arcs connecting the Module Reference's input and output ports to the appropriate components of the containing module.

6. Save the module.

## Referencing a Module in a StreamSQL Application

In a StreamSQL application, module references are made using text StreamSQL statements, not the graphical "drag and drop" method.

1. Identify the application module in the Project Explorer that you want to reuse. The module must be in either the current project; another, referenced project; or an external directory that is configured in your project's `sbd.sbconf` file.

2. Open the application module, and identify the names of its input and output streams.

   - For an EventFlow module, you can see the input and output streams on the canvas.

   - In a StreamSQL module, port names are specified in the CREATE INPUT STREAM and CREATE INPUT STREAM statements. Consider the following StreamSQL application example, `lock.ssql`:

         CREATE LOCKSET l (i int, s string);
         CREATE INPUT STREAM input_stream (number int, symbol string, price double);
         CREATE INPUT STREAM unlock_stream (num int, sym string);
         CREATE STREAM do_work;
         CREATE OUTPUT STREAM unlock_key;

         LOCK l ON number, symbol FROM input_stream INTO do_work;
         CREATE OUTPUT STREAM work_done AS
             SELECT * FROM do_work;
         UNLOCK l ON num, sym FROM unlock_stream INTO unlock_key;

3. In the Studio SB Authoring perspective, open the StreamSQL application that will reference the application module. At the appropriate place, insert an APPLY MODULE statement that references the module identified in the previous step. In the APPLY MODULE statement, include:

   - A FROM statement that maps each of the referenced module's input streams to the appropriate stream in the application.

   - An INTO statement that maps each of the referenced module's output streams to the appropriate stream in the application.

   For example, the following application (let's call it `referencing.ssql`) references the `lock.ssql` application:

       CREATE INPUT STREAM submitter (number int, symbol string, price double);
       CREATE INPUT STREAM unlocker (num int, sym string);
       CREATE OUTPUT STREAM completed;
       CREATE OUTPUT STREAM unlock_key;

       APPLY MODULE "lock.ssql"
           FROM input_stream=submitter, unlock_stream=unlocker
           INTO work_done=completed, unlock_key=unlock_key;

4. If the referenced application contains parameters, you may need to set or modify the parameter values, as described in Using Module Parameters.

## Viewing or Editing a Referenced Module

It is sometimes useful to look at a referenced module to see what it contains. You can view or modify the properties of an application module in two ways:

- In the referencing module, select the Module Reference and press F3, or right-click and select Open Declaration from the context menu.

- Find the module in the Project Explorer view and open it.

## Related Topics

- Using Modules

- Using the Module Reference Component

- StreamSQL: APPLY Statement, CREATE PARAMETERS Statement

Back to Top ^