160 likes | 299 Views
CQL 2 and DCQL 2. Building from CQL. CQL is often too simple Only allows returning targeted data types No populated associations Retrieving associated data types requires multiple queries Impossible without bi-directional associations in models Queries against attributes can be confusing
E N D
Building from CQL • CQL is often too simple • Only allows returning targeted data types • No populated associations • Retrieving associated data types requires multiple queries • Impossible without bi-directional associations in models • Queries against attributes can be confusing • Value queries lack data types • “Should dates conform to xs:date or some database specific format?” • Binary and Unary attributes hard to distinguish • Optional value field • Query modifiers not powerful enough • Lack of aggregations such as minimum and maximum value
New Features in CQL 2 • Aggregations • Min, Max, and Count have been added as aggregation operations when returning a distinct attribute value. • Strongly typed attribute values • Queries are unambiguous when using attribute value restrictions. • Data types prevent type mismatches (i.e. querying integer fields using strings).
New Features in CQL 2 (cont) • Differentiation from Unary to Binary attribute restrictions • Reduces processing to determine the nature of an attribute. • Improves clarity of query language schema. • Retrieval of associated objects • Associations can be populated by the data service before returning object instances. • Retrieval based on role names or depth of association • Name-based retrieval is recursively defined, allowing population of specific associations of associations.
New Features in CQL 2 (cont) • Extensions • Data Service developers can add custom query capabilities. • Several points at which the language may be extended with custom query components. • Support for extensions is advertised by data services which support CQL 2 as a resource property.
CQL 2 Examples • Retrieve all instances of a datatype <ns1:CQLQuery xmlns:ns1="http://CQL.caBIG/2/gov.nih.nci.cagrid.cql.Components"> <ns1:CQLTargetObject className= "gov.nih.nci.cacoresdk.domain.inheritance.childwithassociation.Payment"/> </ns1:CQLQuery>
CQL 2 Examples • Retrieve instances restricted by an association <ns1:CQLQuery xmlns:ns1="http://CQL.caBIG/2/gov.nih.nci.cagrid.cql.Components"> <ns1:CQLTargetObject className= "gov.nih.nci.cacoresdk.domain.onetomany.bidirectional.Computer"> <ns1:CQLAssociatedObject className= "gov.nih.nci.cacoresdk.domain.onetomany.bidirectional.HardDrive" sourceRoleName="hardDriveCollection"/> </ns1:CQLTargetObject> </ns1:CQLQuery>
CQL 2 Examples • Retrieve instances restricted by an association and a binary attribute <ns1:CQLQuery xmlns:ns1="http://CQL.caBIG/2/gov.nih.nci.cagrid.cql.Components"> <ns1:CQLTargetObject className= "gov.nih.nci.cacoresdk.domain.inheritance.childwithassociation.Payment"> <ns2:BinaryCQLAttribute xmlns:ns2=http://CQL.caBIG/2/gov.nih.nci.cagrid.cql.Attribute name="amount" > <ns2:Predicate>EQUAL_TO</ns2:Predicate> <ns2:AttributeValue> <ns2:IntegerValue>1</ns2:IntegerValue> </ns2:AttributeValue> </ns2:BinaryCQLAttribute> </ns1:CQLTargetObject> </ns1:CQLQuery>
CQL 2 Examples • Retrieve the maximum ID value <ns1:CQLQuery xmlns:ns1="http://CQL.caBIG/2/org.cagrid.cql2"> <ns1:CQLTargetObject className= "gov.nih.nci.cacoresdk.domain.inheritance.onechild.Human"/> <ns1:CQLQueryModifier> <ns1:DistinctAttribute attributeName="id" aggregation="MAX"/> </ns1:CQLQueryModifier> </ns1:CQLQuery>
CQL 2 Examples • Retrieve the target and one associated object by its role name <ns1:CQLQuery xmlns:ns1="http://CQL.caBIG/2/gov.nih.nci.cagrid.cql.Components"> <ns1:CQLTargetObject className= "gov.nih.nci.cacoresdk.domain.onetoone.multipleassociation.Child"/> <ns2:AssociationPopulationSpecification xmlns:ns2= "http://CQL.caBIG/2/gov.nih.nci.cagrid.cql.AssociationPopulationSpec"> <ns2:NamedAssociationList> <ns2:NamedAssociation roleName="father"/> </ns2:NamedAssociationList> </ns2:AssociationPopulationSpecification> </ns1:CQLQuery>
CQL 2 Utilities • Converting CQL 1 to 2 • The CQL1toCQL2Converter class • Convert a CQL 1 query into its CQL 2 counterpart • Single constructor takes the domain model which the CQL 1 query targets. • Converting CQL 2 to 1 • The CQL2toCQL1Converter class • Convert a CQL 2 query into its CQL 1 equivalent • CQL 2 contains features that do not map into CQL 1. Use of these features in the input CQL 2 query will cause a QueryConversionException to be thrown
CQL 2 Utilities • Serialization Tools • CQL 2 beans serialized by Castor • Serialize and deserialize CQL 2 queries. The CQL2SerializationUtil class contains several static methods that perform this functionality • Result Iterators • Similar to iterators for CQL 1 • Iterate over results as XML or deserialized objects
DCQL 2 • Builds on CQL 2 • Inherits the new features • New Features • Data Transformations • Attribute values may be manipulated during processing of Foreign Associations • Possible to ask questions which have phrases like "30 minutes ago", or "subtract N from", or "prepended with"
DCQL 2 Examples • New, cleaner foreign join syntax <ns1:DCQLQuery xmlns:ns1="http://DCQL.caBIG/2/org.cagrid.data.dcql"> <ns1:TargetObject name="gov.nih.nci.cacoresdk.domain.onetoone.unidirectional.Address"> <ns1:ForeignAssociatedObject name= "gov.nih.nci.cacoresdk.domain.onetoone.unidirectional.Person" targetServiceURL="DATA_SERVICE_2"> <ns1:JoinCondition localAttributeName="id" foreignAttributeName="id" predicate="EQUAL_TO"/> </ns1:ForeignAssociatedObject> </ns1:TargetObject> <ns1:TargetServiceURL>DATA_SERVICE_1</ns1:TargetServiceURL> </ns1:DCQLQuery>
DCQL 2 Examples • Data Transformation in a Foreign Join <dcql2:DCQLQuery xmlns:dcql2=http://DCQL.caBIG/2/org.cagrid.data.dcql> <dcql2:TargetObject name= "gov.nih.nci.cacoresdk.domain.onetoone.unidirectional.Address"> <dcql2:ForeignAssociatedObject name= "gov.nih.nci.cacoresdk.domain.onetoone.unidirectional.Address“ targetServiceURL="DATA_SERVICE_2"> <dcql2:JoinCondition localAttributeName="zip" foreignAttributeName="id" predicate="EQUAL_TO"/> <dcql2:DataTransformation> <dcql2:Operation value="Zip" operator="PREPEND"/> </dcql2:DataTransformation> </dcql2:ForeignAssociatedObject> </dcql2:TargetObject> <dcql2:TargetServiceURL>DATA_SERVICE_1</dcql2:TargetServiceURL> </dcql2:DCQLQuery>
References • CQL 2: http://cagrid.org/display/dataservices/CQL+2 • DCQL 2: http://cagrid.org/display/fqp/DCQL+2