Identity (query directive)
Description
Returns the input row as is.
Constructor
Identity()
Examples
It might seem at first that there is little use for Identity directive. There are however a few cases where it is needed. You may want to join the input with results of some other directive that does not do this internally. Most common case is Literals directive. Following example returns one row with a text label indicating if the input has instances or not and the actual input. If we didn't join results of the Literals directives with Identity we would only get the text label without the input topic.
importPackage(org.wandora.query2); new If( new Instances(), new Literals("has instances").as("#text").join(new Identity()), new Literals("no instances").as("#text").join(new Identity()) )
Identity can also be useful with If directive. You may want to modify the input if some condition is met and otherwise return the row as is. Next example returns the base names of the input topic but changes an null value to "empty" literal.
importPackage(org.wandora.query2); new If( new Compare("#DEFAULT","!=",null), new Identity(), new Literals("empty") ).from(new BaseName()) .from(new Instances())