The following are simple examples of CQL queries in XML format which highlight the features and syntax of CQL.
Table of Contents
The simplest CQL query defines only one Object. The data service will return all objects in its underlying data source of the given type.
This query will return all Gene objects in the data source:
A variant of the same simple CQL query defines only the target object and a query modifier to count the number of results. Such a query may be useful in situations where the returned result set is potentially very large, and knowing the size of this set may determine handling ahead of actually retrieving results.
This query will return the number of all Gene objects in the data source:
A simple extension to the above query is to ask for all Objects with a single Attribute restriction. Here, a LIKE restriction is used. Note that the syntax for LIKE queries mimics that of SQL.
This query will return all Genes with a symbol starting with 'BRCA':
The following query will return only distinct symbol names from all genes with symbol names starting with 'BRCA'.
This query will return distinct symbol values for all Genes with a symbol starting with 'BRCA':
The final query modification which can be used is one where multiple attributes of a target object are returned.
This query will both id and symbol values for all Genes with a symbol starting with 'BRCA':
A more involved CQL query defines an Object and an Association to another Object. The data service will return all objects of the requested data type and meeting the restriction on their association.
This query will return all Genes with an associated Taxon whose id is equal to 6:
Groups are required when more than one restriction on an Object is needed. In this example, a group is made with an AND logical operator, meaning that all conditions defined within the Group must be met.
This query will return all Genes with a symbol beginning with 'BRCA' and have an associated Taxon with an id equal to 6:
Nested groups can be used to build up sophisticated compound queries. The groups may have differing logical relations to express restrictions on various portions of the object.
This query will return all Genes with an associated Taxon that has a scientificName attribute of 'Mus musculus' and have either a symbol like 'BRCA' or like 'ICR':