Last (query directive)

From WandoraWiki
(Difference between revisions)
Jump to: navigation, search
 
(Examples)
Line 16: Line 16:
 
  new Last(
 
  new Last(
 
   new Eval(
 
   new Eval(
     "vars=dir.get(\"vars\");"+
+
     "param.sum+=parseInt(val);"+
    "if(vars==null){vars={sum:0};dir.set(\"vars\",vars);}"+
+
     "param.sum;"
    "vars.sum+=parseInt(val);"+
+
   ,{sum:0}).as("#sum")
     "vars.sum;"
+
   ).as("#sum")
+
 
   .from(
 
   .from(
 
     new Count(
 
     new Count(
Line 27: Line 25:
 
   )
 
   )
 
  )
 
  )
 +
  
 
[[Category: Query directives]]
 
[[Category: Query directives]]

Revision as of 11:20, 25 August 2009

Description

Returns the last or the last N rows of specified directive. May return less than specified number of rows if the inner directive does not return that many rows.

Constructor

Last(Directive directive) - Returns the last row of directive.

Last(int count, Directive directive) - Returns the last count rows of directive

Examples

Following example gets the sum of number of instances of instances in the input topic. The Count selects the number of instances of each instance topic. The Eval calculates the sum. It always returns sum up to the current row. Then the Last directive selects only the last row which contains the final sum.

importPackage(org.wandora.query2);
new Last(
  new Eval(
    "param.sum+=parseInt(val);"+
    "param.sum;"
  ,{sum:0}).as("#sum")
  .from(
    new Count(
      new Instances()
    ).from(new Instances())
  )
)
Personal tools