gavo.utils.typeconversions module

Conversions between type systems.

The DC software has to deal with a quite a few type systems (see base.typesystems). In general, we keep metadata in the SQL type system; in particular, column’s and param’s type attribute takes values in that.

In fact, we use a couple of extensions:

  • file – this corresponds to a file upload from the web (i.e., a pair

    (filename, file object)). It would be conceivable to turn this into blobs at some point, but right now we simply don’t touch it.

  • vexpr-float, -text, -date, -mjd – vizier-like expressions coming in from

    the web. These are always strings.

  • raw – handed right through, whatever it is. For target formats that

    can’t do this, usually strings are used.

  • unicode – this is TEXT in the database, but while normal text will be rendered as byte strings in VOTables (with non-ASCII-characters replaced by ?), unicode will become an array of unicodeChars.

This module contains a base class and the VOTable type system conversion, as the VOTable module (that should not depend on base) depends on it. The remaining actual converters are in base.typesystems, as they may depend on details of base. Even the SQL converters should be taken from there when code can rely on gavo.base; this module should be considered an implementation detail.

exception gavo.utils.typeconversions.ConversionError(msg: str = '', hint: Optional[str] = None)[source]

Bases: Error

class gavo.utils.typeconversions.FromSQLConverter[source]

Bases: object

is an abstract base class for type converters from the SQL type system.

Implementing classes have to provide a dict simpleMap mapping sql type strings to target types, and a method mapComplex that receives a type and a length (both strings, derived from SQL array types) and either returns None (no matching type) or the target type.

Implementing classes should also provide a typeSystem attribute giving a short name of the type system they convert to.

mapComplex(type, length)[source]
class gavo.utils.typeconversions.FromVOTableConverter[source]

Bases: object

convert(type, arraysize, xtype=None)[source]
mapComplex(type, arraysize)[source]
simpleMap = {('boolean', '1'): 'boolean', ('char', '*'): 'text', ('char', '1'): 'char', ('double', '1'): 'double precision', ('float', '1'): 'real', ('int', '1'): 'integer', ('long', '1'): 'bigint', ('raw', '1'): 'raw', ('short', '1'): 'smallint', ('unsignedByte', '1'): 'smallint'}
typeSystem = 'db'
xtypeMap = {'adql:POINT': 'spoint', 'adql:REGION': 'spoly', 'adql:TIMESTAMP': 'timestamp', 'circle': 'scircle', 'moc': 'smoc', 'point': 'spoint', 'polygon': 'spoly', 'timestamp': 'timestamp', 'x-box': 'sbox'}
class gavo.utils.typeconversions.ToVOTableConverter[source]

Bases: FromSQLConverter

mapComplex(type, length)[source]
simpleMap = {'bigint': ('long', None, None), 'boolean': ('boolean', None, None), 'box': ('double', '*', None), 'bytea': ('unsignedByte', None, None), 'char': ('char', '1', None), 'date': ('char', '*', None), 'double precision': ('double', None, None), 'file': ('bytea', '*', None), 'int4range': ('int', '2', 'interval'), 'integer': ('int', None, None), 'pql-date': ('char', '*', None), 'pql-float': ('char', '*', None), 'pql-int': ('char', '*', None), 'pql-string': ('char', '*', None), 'pql-upload': ('char', '*', None), 'raw': ('unsignedByte', '*', None), 'real': ('float', None, None), 'sbox': ('double', '4', 'x-box'), 'scircle': ('double', '3', 'circle'), 'smallint': ('short', None, None), 'smoc': ('char', '*', 'moc'), 'spoint': ('double', '2', 'point'), 'spoly': ('double', '*', 'polygon'), 'text': ('char', '*', None), 'time': ('char', '*', None), 'timestamp': ('char', '19', 'timestamp'), 'unicode': ('unicodeChar', '*', None), 'vexpr-date': ('char', '*', None), 'vexpr-float': ('char', '*', None), 'vexpr-mjd': ('char', '*', None), 'vexpr-string': ('char', '*', None)}
typeSystem = 'VOTable'
gavo.utils.typeconversions.voTableToSQLType(type, arraysize, xtype=None)