body { margin:0px; background-color:#fff } a:visited { color:#8b0000; text-decoration:underline } .FWExtra { } .FWExtra a:link { text-decoration: none; } .FWExtra a:active { text-decoration: none; } .FWExtra a:visited { text-decoration: none; } .FWExtra a:hover { text-decoration: underline; } -->
Equi4 Softwareitem2

Jump to part:
1 - 2 - 3 - 4 - 5
API

an introduction to ratcl - Part 3

The relational algebra operation which has not been mentioned so far is selection. There are in fact three ways to select specific rows from a view:

 % [T pick {01. Pick returns all rows for which a non-zero value is supplied:

The argument of pick must be a list with as many integers as there are rows in the view.
 

 % [T maprow {12. Maprow was shown on the previous page:

It can be used to select specific rows. Maprow is quite a general operator, since it can also be used to slice, sort, replicate, or permute rows.
 

3. Filter is the most general way to select rows. It takes a conditional expression and returns all rows for which the condition is true:

 % [T filter {not

Filter offers basically the same flexibility as a SQL "where" clause on a single view.

Expression syntax

The operators supported in filter expressions consist of the usual mix:

  • * / %
  • + -
  • < <= > => = == <> !=
  • not !
  • and &&
  • or ||

The above list is from highest precedence operator to lowest. Note that "==", "!=", "!", "&&", and "||" are synonyms, matching - as a convenience - the C language.

Operands can be integers and column names. A few operations, such as comparisons, also support string operands (delimited by single quotes).

Parameters

Constant values can also be supplied in Tcl as parameters. Each question mark is replaced by an additional argument supplied to the filter operator:

 % [T filter {not

This can avoid the need to quote and escape special characters and can make it easier to parametrize conditions at run-time.

Note: parameter values are passed as integers if they look like one, else as strings. To force an explicit type: use "?S" for strings, and "?I" (uppercase-i) for integers.

calculated columns

Filtering is based on calculated columns (i.e. to decide whether rows are part of the selection). The general form of this is available through the addcol operator:

 % [view A,B:I {one

The "C:I" notation indicates that the new C column is of type integer. This example supplies the value "100" as parameter, just to demonstrate the mechanism.

Note that addcol is one of a few operators which do not return a new view but actually change a view. More about this on the next page.

clean concepts

These pages so far should illustrate how Ratcl does relational algebra, and explain the RA prefix of "Ratcl". A lot of effort is being invested in making operations work cleanly and without surprises. They can be applied to any view, produce clearly defined results, and have no side-effects (with a few exceptions such as addcol).

Speaking of side-effects. It's time to look at view management and lifetimes in a bit more detail.

Continued...