Identity (query directive)

From WandoraWiki
(Difference between revisions)
Jump to: navigation, search
Line 8: Line 8:
  
 
[[Category:Query directives]]
 
[[Category:Query directives]]
 +
 +
== 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 Exists(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.
 +
 +
importPackage(org.wandora.query2);
 +
new If(
 +
  new Identity().as("#compare").join(
 +
    new Null().as("#null")
 +
  ).where("#compare","!=","#null"),
 +
  new Identity(),
 +
  new Literals("empty")
 +
).from(new BaseName())

Revision as of 13:45, 20 August 2009

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 Exists(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.

importPackage(org.wandora.query2); new If(

 new Identity().as("#compare").join(
   new Null().as("#null")
 ).where("#compare","!=","#null"),
 new Identity(),
 new Literals("empty")

).from(new BaseName())

Personal tools