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

Module morphhelpers

source code

Helpers for morphing modules

Classes
  State
is a scratchpad for morphers to communicate state among themselves.
  Morpher
A class managing the process of morphing an ADQL expression.
Functions
 
addNotToBooleanized(expr, operator, operand)
prepends a NOT to expr if operator and operand suggest there should be one for ADQL integerized boolean expressions.
source code
 
registerBooleanizer(funcName, handler)
registers handler as a booleanizer for ADQL functions called funcName.
source code
 
booleanizeComparisons(node, state)
turns a comparison expression that's really a boolean expression into a boolean expression.
source code
Variables
  __package__ = 'gavo.adql'
Function Details

addNotToBooleanized(expr, operator, operand)

source code 

prepends a NOT to expr if operator and operand suggest there should be one for ADQL integerized boolean expressions.

The function will return None for unknown combinations of operator and operand, and it will simply hand through Nones for expr, so calling functions can just return addNotToBooleanized(...).

registerBooleanizer(funcName, handler)

source code 

registers handler as a booleanizer for ADQL functions called funcName.

funcName must be all-uppercase for this to work. handler(node, operand, operator) is a function that receives a function node and the operand and operator of the comparison and either returns None to say it can't handle it, or something else; that something else is what the entire comparison node is morphed into.

You can call multiple booleanizers for the same function; they will be tried in sequence. Hence, make sure you get your import sequences right if you do this.

booleanizeComparisons(node, state)

source code 

turns a comparison expression that's really a boolean expression into a boolean expression.

New-style: handler functions of children of this just set an OVERRIDE_RESULT attribute, and this just returns it. The DISTANCE MORPHER already does this.

Old-style functionality (should be moved to new-style at some point):

This is for things like the geometry predicates (CONTAINS, INTERSECTS) or stuff like ivo_hasword and such. Embedding these as booleans helps the query planner a lot (though it might change semantics slightly in the presence of NULLs).

The way this works is that morphing code can call registerBooleanizer with the function name and callable that receives the function node, the operator, and the operand. If that function returns non-None, that result is used instead of the current node.