Apama 10.3 | Apama Documentation | 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 {
metadata {
"author":"Apama",
"version":"1"
}
parameters {
float period;
}
inputs {
Withdrawal() key cardNumber within (period);
}
find
Withdrawal as w1 -> Withdrawal as w2
where w2.country != w1.country {
log "Suspicious withdrawal: " + w2.toString() at INFO;
}
}
The format for a query definition is as follows:
query name {
[ metadata { metadata_block } ]
[ parameters { parameters_block } ]
inputs { inputs_block }
find pattern block
[ action_definition ... ]
}
Syntax Element
Description
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.
metadata
The metadata section is optional. If you specify a metadata section, it must be the first section in the query. Metadata are specified as a list of key-value pairs. Both key and value must be string literals. For more information, see Defining metadata in a query.
parameters
The parameters section is optional. If you specify a parameters section, it must follow the metadata section, if there is one, and precede the inputs section. Parameters must be of the following types:
*integer
*decimal
*float
*string
*boolean
Specify one or more data_type parameter_name pairs. The parameter name can use any of the characters allowed for EPL identifiers (see Identifiers). Any parameters you specify are available throughout the rest of the query. 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-2018 | 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.