7.1.1 Project Transformations
The project transformations include remove, rename, add, and move.
The project transformations operate on the labels and rows individually to
produce a new relation. The new relation replaces the old relation.
remove
- remove takes a single argument, which is the column name to remove, this
column must exist or remove fails.
epoch | thread | elapsed | cpu
|
1 | 1 | 10 | 4
|
2 | 1 | 12 | 5
|
3 | 1 | 11 | 4
|
4 | 1 | 9 | 3
|
5 | 1 | 10 | 4
|
Relation 7.1
If the current relation is Relation 7.1, and the transform remove("thread")
yields rel2.
epoch | elapsed | cpu
|
1 | 10 | 4
|
2 | 12 | 5
|
3 | 11 | 4
|
4 | 9 | 3
|
5 | 10 | 4
|
Relation 7.2
rename
- rename takes two arguments. The first is the old name of the column, and the
second is the new name of the column. The old name must exist, and the new
name must not exist. Using Relation 7.1 as a starting point, rename("epoch",
"Test Number") yields rel3.
Test Number | thread | elapsed | cpu
|
1 | 1 | 10 | 4
|
2 | 1 | 12 | 5
|
3 | 1 | 11 | 4
|
4 | 1 | 9 | 3
|
5 | 1 | 10 | 4
|
Relation 7.3
add
- add also takes two arguments, the first is the name of the new column and the
second argument is an expression that undergoes row replacement (to be
described later) and is then passed to Perl's eval function. For example, if
we wanted to add wait time (the amount of time a process spends not running) to
Relation 7.1, we could transform it using add("wait", "$elapsed - $cpu") and
yield rel4:
epoch | thread | elapsed | cpu | wait
|
1 | 1 | 10 | 4 | 6
|
2 | 1 | 12 | 5 | 7
|
3 | 1 | 11 | 4 | 7
|
4 | 1 | 9 | 3 | 6
|
5 | 1 | 10 | 4 | 6
|
Relation 7.4
move
- move reorders the fields of the tuples. Move takes two arguments, the first is
a column which must exist and the second is the index to move to starting from
zero. This is useful to provide a canonical ordering to important fields in
all of the relations when printing results.
If we use Relation 7.1 as our starting point, move(thread,0) yields rel5:
thread | epoch | elapsed | cpu
|
1 | 1 | 10 | 4
|
1 | 2 | 12 | 5
|
1 | 3 | 11 | 4
|
1 | 4 | 9 | 3
|
1 | 5 | 10 | 4
|
Relation 7.5
update
- The update transformation takes two arguments, the first is a column name to
update, and the second is an expression. update("foo", expression) is
semantically equivalent to:
add_col("temporary_name", expression)
remove("foo")
rename_col("temporary_name", "foo")
The update operation, however, does not reorder the columns and is done in a
single pass through the relation.