Refactoring

Refactoring is a feature in Eclipse that propagates your changes to other affected areas of your application. For example, if you rename a stream in your SPL application, all references to it will automatically be renamed. Refactoring is a powerful feature and needs to be performed with care. As with most automated code updates, some errors can inadvertently be introduced.

Here are some useful refactoring use cases:

In the SPL Editor, the Rename Element action is a refactoring action which updates all references to the renamed element. You can rename a composite operator, a stream, an alias, a type, an attribute and so on by right clicking on the element and running the Rename Element action. You can also rename the same set of elements in the Graphical Editor and the refactoring support will update the references.

The Graphical Editor provides additional refactoring support when the connection between operators is changed or deleted. For example, when you insert an operator between two operators, the name of the stream feeding the downstream operator is changed. The refactoring support updates all references to the stream in the downstream operator. Similarly, if you delete a connection or change the source or target of a connection, the downstream operator is updated accordingly. In most cases, an alias is introduced for the incoming stream and all references within the downstream operator code are updated to use the alias so that further changes to the connection (e.g. stream name is changed, new connection made, etc) do not require any updates to the downstream operator code.

For example, here is the code of two connected operators:

stream<TradeFilterT> TradeFilter = Functor(TradeQuote)
{
     param
          filter : isTrade(ttype) &&(ticker in $monitoredTickers) ;
     output
          TradeFilter : ts = timeStringToTimestamp(date, time, false) ;
}
 
stream<VwapT, tuple<decimal64 sumvolume>> PreVwap = Aggregate(TradeFilter)
{
     window
          TradeFilter : sliding, count(4), count(1), partitioned ;
     param
          partitionBy : ticker ;
     output
          PreVwap : ticker = Any(ticker), vwap = Sum(price * volume), 
                    minprice = Min(price), maxprice = Max(price), 
                    avgprice = Average(price), sumvolume = Sum(volume) ;
}

When I use the Graphical Editor to insert a Throttle operator in between the two operators, the code of the downstream PreVwap operator is updated to use the new stream from the Throttle operator. An alias is introduced for the input port so that further changes to the connection into the PreVwap operator will not require further code updates.

Join The Discussion