Last (query directive)
From WandoraWiki
(Difference between revisions)
(→Examples) |
|||
(One intermediate revision by one user not shown) | |||
Line 11: | Line 11: | ||
== Examples == | == 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. | + | 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. Note that it is easier to do the same thing using [[Sum (query directive) |Sum]] directive. |
importPackage(org.wandora.query2); | importPackage(org.wandora.query2); | ||
new Last( | new Last( | ||
new Eval( | new Eval( | ||
− | " | + | "param.sum+=parseInt(val);"+ |
− | + | "param.sum;" | |
− | + | ,{sum:0}).as("#sum") | |
− | " | + | |
− | ).as("#sum") | + | |
.from( | .from( | ||
new Count( | new Count( | ||
Line 27: | Line 25: | ||
) | ) | ||
) | ) | ||
+ | |||
[[Category: Query directives]] | [[Category: Query directives]] |
Latest revision as of 13:02, 25 August 2009
[edit] 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.
[edit] Constructor
Last(Directive directive) - Returns the last row of directive.
Last(int count, Directive directive) - Returns the last count rows of directive
[edit] 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. Note that it is easier to do the same thing using Sum directive.
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()) ) )