Apama 10.3.1 | Apama Documentation | Developing Apama Applications | Developing Apama Applications in EPL | Defining Queries | Partitioning queries | Defining actions as query keys
 
Defining actions as query keys
A query may also use the result of an action call on the event as the key for a query. To use an action as a query input key, you must provide the action name, parameters and an alias. The action call must always return a value (chunk, listener and action are invalid return types).
The following example calls the getName() action within the A event to generate the input key:
query Q {
inputs {
A() key getName() as name retain 1;
}
find A as a ...
}
The parameters passed to an input key action can include query parameters or literals, or can be blank in which case empty parenthesis must still be supplied. Passing a query parameter allows for specializing the partitions depending on the query parameter, which can reduce duplicating query code when only the input keys differ.
The following example calls the getName() action within the B event, supplying the query parameter nameToPartition into the action. The action can then return a different field (firstname or surname) depending on the parameters of this query instance:
query Q {
parameters {
string nameToPartition;
}
inputs {
B() key getName(nameToPartition) as name retain 1;
}
find B as b ...
}
An alias must always be supplied and can be used to identify the returned value of the action call in the find block. For example, the alias name will identify the value returned from the call to getName() and can be used in the find block:
find B as b {
print name;
}
If using multiple input events, the action return type must match the type for the key in all other inputs, and the alias must match between inputs. The following example uses both action and field input keys; the surname field and the return from getName() must be the same type, and they are both mapped to the alias name:
query Q {
inputs {
A() key surname as name retain 1;
B() key getName("Surname") as name retain 1;
}
find A as a -> B as b ...
}
We suggest that query parameters that are passed into action keys are not updated. Updating them can cause unexpected partitioning as the returned value from the action call may not be as expected.

Copyright © 2013-2019 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.