Package gavo :: Package adql :: Module postproc
[frames] | no frames]

Source Code for Module gavo.adql.postproc

 1  """ 
 2  Operations on annotated ADQL trees done by parseAnnotated. 
 3   
 4  These can be considered "bug fixes" for ADQL, where we try to 
 5  make the parse tree more suitable for later translation into 
 6  SQL. 
 7  """ 
 8   
 9  #c Copyright 2008-2019, the GAVO project 
10  #c 
11  #c This program is free software, covered by the GNU GPL.  See the 
12  #c COPYING file in the source distribution. 
13   
14   
15  from gavo.adql import morphhelpers 
16  from gavo.adql import nodes 
17   
18   
19  ############## INTERSECTS to CONTAINS 
20  # Unfortunately, the ADQL spec mandates that any INTERSECTS with a 
21  # POINT argument should be treated as if it were CONTAINs with 
22  # arguments swapped as required.  This morphing code tries to do  
23  # this before translation.  One major reason to do this within 
24  # the translation layer rather than relying on the SQL code 
25  # generation is that probably all generators profit from knowing 
26  # that there's a special case "point within <geometry>". 
27   
28 -def _intersectsWithPointToContains(node, state):
29 if node.funName!='INTERSECTS': 30 return node 31 ltype = getattr(node.args[0].fieldInfo, "type", None) 32 rtype = getattr(node.args[1].fieldInfo, "type", None) 33 if ltype=='spoint': 34 return nodes.PredicateGeometryFunction(funName="CONTAINS", 35 args=node.args) 36 elif rtype=='spoint': 37 return nodes.PredicateGeometryFunction(funName="CONTAINS", 38 args=[node.args[1], node.args[0]]) 39 return node
40 41 42 _builtinMorphs = { 43 'predicateGeometryFunction': _intersectsWithPointToContains, 44 } 45 46 _morpher = morphhelpers.Morpher(_builtinMorphs) 47 48 builtinMorph = _morpher.morph 49