This topic explains how to use the FROM
clause in queries in VMware Tanzu GemFire.
Use the FROM
clause to bring the data you need into scope for the rest of your query. The FROM
clause also includes object typing and iterator variables.
The query engine resolves names and path expressions according to the name space that is currently in scope in the query.
The initial name space for any query is composed of:
/exampleRegion.keySet
returns the Set of entry keys in the region/exampleRegion.entryset
returns the Set of Region.Entry objects/exampleRegion.values
returns the Collection of entry values/exampleRegion
returns the Collection of entry valuesNew name spaces are brought into scope based on the FROM
clause in the SELECT
statement.
Examples:
Query a region for all distinct values. Return a collection of unique entry values from the region:
SELECT DISTINCT * FROM /exampleRegion
Query the top level region data using entrySet. Return the keys and positions of Region.Entry objects whose mktValue attribute is greater than 25.00:
SELECT key, positions FROM /exampleRegion.entrySet, value.positions.values positions WHERE positions.mktValue >= 25.00
Query the region for its entry values. Return a set of unique values from Region.Entry objects that have the key equal to 1:
SELECT DISTINCT entry.value FROM /exampleRegion.entries entry WHERE entry.key = '1'
Query the region for its entry values. Return the set of all entry values in which the ID
field is greater than 1000:
SELECT * FROM /exampleRegion.entries entry WHERE entry.value.ID > 1000
Query entry keys in the region. Return a set of entry keys in the region that have the key equal to ‘1’:
SELECT * FROM /exampleRegion.keySet key WHERE key = '1'
Query values in the region. Return a collection of entry values in the region that have the status attribute value of ‘active’:
SELECT * FROM /exampleRegion.values portfolio WHERE portfolio.status = 'active'
In query strings, you can use aliases in path expressions (region and its objects) so that you can refer to the region or objects in other places in the query.
You can also use the AS keyword to provide a label for joined path expressions.
Examples:
SELECT DISTINCT * FROM /exampleRegion p WHERE p.status = 'active'
SELECT * FROM /exampleRegion p, p.positions.values AS pos WHERE pos.secId != '1'
Specifying object type in the FROM
clause helps the query engine to process the query at optimal speed. Apart from specifying the object types during configuration (using key-constraint and value-constraint), type can be explicitly specified in the query string.
Example:
SELECT DISTINCT * FROM /exampleRegion, positions.values positions TYPE Position WHERE positions.mktValue >= 25.00