An incoming query, whether expressed in OQL, CPL, or some other query language, must be parsed and converted into K2's internal query representation. This representation is an abstract syntax tree (AST) which has nodes for base types like integers and strings, nodes for operators like addition and multiplication, and higher-level nodes for constructs like case statements and loops.
If pieces of a query refer to functions defined in the environment, it is the responsibility of the translator to incorporate those definitions into the query. As a very simple example, if the following OQL function definition had previously been issued:
define inc(x) as x + 1;
and the following query comes into the translator:
sum(select distinct inc(p.age) from People p);
the query translator would translate the query into (an AST representing):
sum(select distinct p.age + 1 from People p);
All these replacements make for a fairly large translated query. The K2 optimizer is responsible for minimizing the translated query before it is executed.
[K2 Front Page]