Next: , Previous: Project Transformations, Up: Basic Transformations

7.1.2 Select Transformations

The select transformations pick items that meet a given condition from a relation. Once the items are selected, further processing may be done. There are three types of select transformations: basic, warning, and aggregate.

The first select transformation is, aptly, named "select". It takes a single argument, which is the expression to evaluate over each row of the relation. This expression undergoes row replacement (to be described later) and is then passed to Perl's eval function. If the evaluation returns true, then the row is included in the output relation, otherwise it is not. The output relation replaces the current relation.

Often, the first run of a test is faster than the other runs because it warms the cache (e.g., it uses a compiler on the root partition). To throw out this test, you could select("$epoch > 1"). Performed on Relation 7.1, this yields rel6.

epoch thread elapsed cpu
2 1 12 5
3 1 11 4
4 1 9 3
5 1 10 4

Relation 7.6

Often a particular test will have something go awry, and that fact is lost in the summary statistics. The "warn" transformation is used to produce warnings if something is suspicious about the data.

"warn" operates much like select, except it takes two arguments. The first is a predicate that raises the warning, and the second is an error message. If a warning is raised, then the global variable "wraised" is incremented.

The first argument undergoes replacement, and then is passed to Perl's eval function. If it evaluates to true, then the second argument undergoes replacement and is printed on standard error. "warn" is most useful when combined with "foreachrow" or "foreachcol" (See Control Transformations). There are three library functions that make use of warn in this way: "warnrow", "warncol", and "warnval."

Aggregate selects all rows of a transformation, and replaces them with a single row. Aggregate takes a single argument which is a perl hash that describes how to do the aggregate operation for each column. The hash contains keys which are the field names, and then an expression on which column replacement is done. The special hash key "_" describes what is done to unknown columns. The special hash value "explode" says to replace a single column with four new columns. One for the minimum, maximum, mean and sum of the values in that column.

Aggregate becomes much more useful when combined with the "group" control transformation (See Control Transformations).