Developing Apama Applications > Developing Apama Applications in EPL > Defining Queries > Format of query definitions
Format of query definitions
A query searches for an event pattern that you specify. You define a query in a file with the extension .qry. Each .qry file contains the definition of only one query. The following sample shows the definition of a simple query that will search for a Withdrawal event pattern:
query ImprobableWithdrawalLocations {
parameters {
float period;
}
inputs {
Withdrawal() key cardNumber within (period);
}
find
Withdrawal:w1 -> Withdrawal:w2
where w2.country != w1.country {
log "Suspicious withdrawal: " + w2.toString() at INFO;
}
}
The format for a query definition is as follows:
query name {
[ parameters { parameters_block } ]
inputs { inputs_block }
find pattern block
[ action_definition ... ]
}
 
query name
Specify the query keyword followed by a name for your query. Like monitors and event types, the identifier you specify as the name of a query must be unique within your application.
 
parameters
The parameters section is optional. If you specify a parameters section it must be the first section in the query. Parameters must be integer, float, string or boolean types. Specify one or more data_type  parameter_name pairs. Any parameters you specify are available in the inputs section and in the find statement. For more information about parameters and how parameters get their values, see Implementing parameterized queries.
 
inputs
The inputs section is required and it must follow the parameters section, if there is one, and precede the find statement. In the inputs section, you must define at least one input. If you specify more than one input each input must be a different event type.
The inputs section specifies the events that the query operates on. An input definition can include the keyword, key, followed by one or more fields in the specified event. This is the query key. The correlator uses the key to partition incoming events into separate windows. For example, the cardNumber key indicates that there is a separate window for the Withdrawal events for each card number. In other words, each window can contain Withdrawal events associated with only one account.
For details, see Defining query input.
 
find
statement
After the inputs section, you must specify a find statement. A find statement specifies the event pattern of interest and a block that contains procedural code. This code can define EPL actions you want to perform when there is a match. For more information, see Finding and acting on event patterns.
 
action_definition
After the find statement, you can optionally specify one or more actions in the same form as in EPL monitors. An expression in a find statement can reference an action defined in that query. See Defining actions in queries.
Copyright © 2013-2015 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.
Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG.