Skip to content

Commit a226120

Browse files
committed
Update the query mapping section.
1 parent 25edb7a commit a226120

File tree

1 file changed

+36
-19
lines changed

1 file changed

+36
-19
lines changed

source/plugin-querymap.rst

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -146,40 +146,57 @@ For example, in the case of filtering by the prefix:
146146
Query mapping scenarios
147147
-------------------------
148148

149-
To obtain an Apache Cayenne Expression object, several mapping scenarios are provided, plus plugin developer
150-
is free to implement his own one.
149+
To perform queries on the actual database, the incoming VAMDC-TAP query
150+
needs to be adapted to the database structure. In the case of Apache Cayenne,
151+
*org.apache.cayenne.exp*.**Expression** object needs to be constructed,
152+
representing the query logic relative to the database primary table.
151153

152-
Mapping of logic tree
154+
In this chapter the way to construct the query expressions from the incoming query is described.
155+
156+
Mapping of the LogicTree
153157
+++++++++++++++++++++++++
154158

155-
Mapping of logic tree nodes is always trivial and is one-to-one with
156-
Cayenne Expression.andExp(), Expression.orExp(), Expression.notExp(), see the Cayenne Javadoc [CAYJAVADOC]_
159+
Mapping of the LogicTree nodes is simple with one-to-one mapping of **AND**, **OR** and **NOT** operators to
160+
Cayenne Expression.andExp(), Expression.orExp(), Expression.notExp(), see the Cayenne Javadoc [CAYJAVADOC]_.
157161

158162
Usable example of such mapper is provided in *org.vamdc.tapservice.query.QueryMapper* class (vamdctap-querymapper library),
159163
that is bundled both with the TAPValidator and the node software.
160164

161165
Mapping of RestrictExpression elements
162166
++++++++++++++++++++++++++++++++++++++++
163167

164-
Mapping of RestrictExpression elements may be a bit more tricky, since they contain lots of information:
168+
Mapping of the leaf nodes of the query tree, represented by the RestrictExpression elements,
169+
may be a bit more tricky. A lot of the information is contained in leaf nodes
170+
that should be mapped into the query logic:
165171

166-
* prefix
167-
* prefix index
168-
* VAMDC dictionary keyword
172+
* Keyword prefix
173+
* Prefix index
174+
* VAMDC dictionary Restrictable keyword
169175
* comparison operator
170-
* value/value set
176+
* value or a set of values
177+
178+
VAMDC Restrictable keyword may correspond to one or several database fields.
179+
For example, let us have a database where all the species:
180+
particles, atoms and molecules are stored in a single table,
181+
where the inchikeys are defined for atoms and molecules, and there is a field indicating the species type.
182+
In this case the **MoleculeInchiKey** keyword in a query will
183+
map to two internal **Expression** constraints:
184+
185+
a constraint on the inchikey field of the table,
186+
187+
and a constraint indicating that the species is actually a molecule.
171188

172-
VAMDC keyword itself may map to one or more database columns,
173-
for example, **MoleculeInchiKey** keyword, in case of a database that contains all species within one table,
174-
says that the field is **InchiKey** and that we must verify that species we are looking at are actually molecules.
175-
To correctly handle such a keyword we will need to AND two Cayenne Expressions and add them to the mapped tree.
189+
To correctly handle such a keyword we will need to join two Cayenne Expressions with the Expression.andExp
190+
operator, then add them to the mapped query tree.
176191

177-
Prefix and prefix index may also require a check for a certain field, like if element
178-
is a reactant or product in chemical reaction.
179-
In this case it may make sense to loop over all defined prefixes using **Query.getPrefixes()** method, then
180-
filter the incoming query tree by the prefix with the **Query.getPrefixedTree(...)**, map it as usual,
181-
add the desired logic to the resulting expression and finally AND the mapped filtered subtree to the resulting query.
192+
Prefix and prefix index may also impose a check for a certain field, like if element
193+
is a reactant or product in a chemical reaction.
182194

195+
To handle the prefixes, it is possible to loop through the prefixes present in the query
196+
by using **Query.getPrefixes()** method.
197+
The second step would be to filter the incoming query tree
198+
by the prefix using the **Query.getPrefixedTree(...)** method, than map it to Cayenne Expressions,
199+
and finally join the obtained expressions with the Expression.andExp() method.
183200

184201
Query Mapping Library
185202
--------------------------

0 commit comments

Comments
 (0)