As (query directive)

From WandoraWiki
Jump to: navigation, search

Contents

Description

Changes the role name of the active column or the specified column.

Constructor

As(String newRole) - Change the role name of the active column.

As(String original, String newRole) - Change the role name of the specified column.

Notes

Generally you have to feed rows to As directive from some other directive through a From directive. All this is best done using the as method present in every directive. Calling A.as("role") will change the active column role name of the results of A. This will resolve to new As("role").from(A) which resolves to new From(new As("role"),A). The as method can also be given two parameters corresponding to the As directive constructor with two parameters.

Exmaples

importPackage(org.wandora.query2);
new Instances().as("#instance")

Above example changes the default column role of Instances directive to "#instances". Note that using the as method is much more readable than creating same query using constructors only. Above example would be equal to

importPackage(org.wandora.query2);
new From(new As("#instance"),new Instances())

Below is a slightly more complex example demonstrating both changing active column role with as and then later referring to them with of (see also Of directive).

1 importPackage(org.wandora.query2);
2 new Join(
3   new BaseName().of("#input").as("#inputbn"),
4   new BaseName().of("#instance").as("#instancebn")
5 ).from(
6   new Instances().as("#instance").from(
7     new As("#input"))
8 )

The as method call on line 6 changes the role of instances so we can refer to it later. Line 7 uses As constructor directly. Input to this directive is actually the initial input to the entire query. Thus the As directive on line 7 changes the actual input topic role name to "#input". Normally the input topic uses the default role and so will get overwritten almost immediately. This is one of few cases where you may need to construct As directive directly. This can also be done using the to method which is inverse of from.

1 importPackage(org.wandora.query2);
2 new As("#input").to(
3   new Join(
4     new BaseName().of("#input").as("#inputbn"),
5     new BaseName().of("#instance").as("#instancebn")
6   ).from(
7     new Instances().as("#instance")
8   )
9 )
Personal tools