Port naming conventions

Ports provide a way to access a stream to place or extract information. In Streams Processing Language (SPL), the input and output ports of an operator can have an optional alias. This alias is only in scope within the stream operator body.

When an operator has multiple input streams connected to the same port, and the operator body uses incoming stream names as part of its logic, use port aliases. Assigning port aliases has the following benefits:
  • Makes the operator body code more readable by providing a local short name.
  • Provides a consistent manner to access the streams that feed an input port. This practice makes it explicit that tuples are processed in a per-port basis. There is no way to differentiate between tuples that come from different streams that are connected to the same input port.
  • Offers assistance with refactoring. You can change the operator input and output stream names without impacting the code in the operator body.

The standard naming convention for port aliases is camel case with the first character capitalized, but with a bias towards short names, such as the name InLHS.

This example application shows aliases that are assigned to the input ports of the Custom operator available in the SPL Standard Toolkit. In this example, the Custom operator receives SrcA and SrcB in its first input port (with alias InLHS (line 13)), and SrcC, and SrcD in its second input port (with alias InRHS (line 14)).

01: namespace example;
02:
03: composite Main {
04:
05:   graph
06:     stream <float32 x> SrcA = Beacon() {}
07:     stream <float32 x> SrcB = Beacon() {}
08:
09:     stream <float32 y> SrcC = Beacon() {}
10:     stream <float32 y> SrcD = Beacon() {}
11:
12:    (stream <uint32 count> OutA;
13:     stream <uint32 count> OutB) as Counters = Custom(SrcA, SrcB as InLHS;
14:                                                      SrcC, SrcD as InRHS) {
15:      logic
16:        state : { mutable uint32 countLHS = 0;
17:                  mutable uint32 countRHS = 0; }
18:        onTuple InLHS: submit({count = ++countLHS}, OutA);
19:        onTuple InRHS: submit({count = ++countRHS}, OutB);
20:    }
21:}