gavo.rscdef.tabledef module

Description and definition of tables.

class gavo.rscdef.tabledef.ADQLVisibilityAttribute(name, default=None, description='Undocumented', copyable=False, aliases=None, callbacks=None, before=None)[source]

Bases: BooleanAttribute

An attribute that has values True/False and hidden.

feedObject(instance, value)[source]
parse(value)[source]

returns a typed python value for the string representation value.

value can be expected to be a unicode string.

trueValue = True
typeDesc_ = "boolean or 'hidden'"
unparse(value)[source]

returns a typed python value for the string representation value.

value can be expected to be a unicode string.

class gavo.rscdef.tabledef.ColumnTupleAttribute(name, **kwargs)[source]

Bases: StringListAttribute

is a tuple of column names.

In a validate method, it checks that the names actually are in parent’s fields.

iterParentMethods()[source]

adds a getPrimaryIn method to the parent class.

This function will return the value of the primary key in a row passed. The whole thing is a bit dense in that I want to compile that method to avoid having to loop every time it is called. This compilation is done in a descriptor – ah well, probably it’s a waste of time anyway.

validate(parent)[source]
class gavo.rscdef.tabledef.DBIndex(parent, **kwargs)[source]

Bases: Structure

A description of an index in the database.

In real databases, indices may be fairly complex things; still, the most common usage here will be to just index a single column:

<index columns="my_col"/>

To index over functions, use the character content; you will have to put parentheses when using expressions. An explicit specification of the index expression is also necessary to allow RE pattern matches using indices in character columns (outside of the C locale). That would be:

<index columns="uri">uri text_pattern_ops</index>

(you still want to give columns so the metadata engine is aware of the index). See section “Operator Classes and Operator Families” in the Postgres documentation for details.

For pgsphere-valued columns, you at the time of writing need to specify the method:

<index columns="coverage" method="GIST"/>

To define q3c indices, use the //scs#q3cindex mixin; if you’re devious enough to require something more flexible, have a look at that mixin’s definition.

If indexed columns take part in a DaCHS-defined view, DaCHS will not notice. You should still declare the indices so users will see them in the metadata; writing:

<index columns="col1, col2, col3"/>

is sufficient for that.

attrSeq = [<gavo.base.attrdef.BooleanAttribute object>, <gavo.base.structure.DataContent object>, <gavo.base.attrdef.StringListAttribute object>, <gavo.base.parsecontext.IdAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.complexattrs.ListOfAtomsAttribute object>]
completeElement(ctx)[source]
completedCallbacks = []
create(querier)[source]

creates the index on the parent table if necessary.

querier is an object mixing in the DBMethodsMixin, usually the DBTable object the index should be created on.

property dbname
drop(querier)[source]

drops the index if it exists.

querier is an object mixing in the DBMethodsMixin, usually the DBTable object the index possibly exists on.

iterCode()[source]
managedAttrs = {'cluster': <gavo.base.attrdef.BooleanAttribute object>, 'columns': <gavo.base.attrdef.StringListAttribute object>, 'content_': <gavo.base.structure.DataContent object>, 'id': <gavo.base.parsecontext.IdAttribute object>, 'kind': <gavo.base.attrdef.UnicodeAttribute object>, 'metaOnly': <gavo.base.attrdef.UnicodeAttribute object>, 'method': <gavo.base.attrdef.UnicodeAttribute object>, 'name': <gavo.base.attrdef.UnicodeAttribute object>, 'option': <gavo.base.complexattrs.ListOfAtomsAttribute object>, 'options': <gavo.base.complexattrs.ListOfAtomsAttribute object>}
name_ = 'index'
class gavo.rscdef.tabledef.ForeignKey(parent, **kwargs)[source]

Bases: Structure

A description of a foreign key relation between this table and another one.

attrSeq = [<gavo.base.attrdef.UnicodeAttribute object>, <gavo.base.parsecontext.IdAttribute object>, <gavo.base.parsecontext.ReferenceAttribute object>, <gavo.base.attrdef.BooleanAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>]
completedCallbacks = []
create(querier)[source]
delete(querier)[source]
getAnnotation(roleName, container, instance)[source]

returns a dm annotation for this foreign key.

getDescription()[source]
managedAttrs = {'dest': <gavo.base.attrdef.UnicodeAttribute object>, 'id': <gavo.base.parsecontext.IdAttribute object>, 'inTable': <gavo.base.parsecontext.ReferenceAttribute object>, 'metaOnly': <gavo.base.attrdef.BooleanAttribute object>, 'source': <gavo.base.attrdef.UnicodeAttribute object>}
name_ = 'foreignKey'
onElementComplete()[source]
class gavo.rscdef.tabledef.PublishableDataMixin[source]

Bases: StructCallbacks

A mixin with a few classes and attributes for data that can be published to the VO registry.

In particular, this contains the publish element (registration attribute).

getPublicationsForSet(setNames, includeDatalink=True)[source]

returns a sequence of publication elements for the data, suitable for OAI responses for the sets setNames.

Essentially: if registration is None, or its sets don’t match setNames, return an empty sequence.

If the registration mentions services, we turn their publications into auxiliary publications and yield them

Otherwise, if we’re published for ADQL, return the TAP service as an auxiliary publication.

class gavo.rscdef.tabledef.STCDef(parent, **kwargs)[source]

Bases: Structure

A definition of a space-time coordinate system using STC-S.

attrSeq = [<gavo.base.parsecontext.IdAttribute object>, <gavo.base.structure.DataContent object>]
completeElement(ctx)[source]
completedCallbacks = []
iterColTypes()[source]
managedAttrs = {'content_': <gavo.base.structure.DataContent object>, 'id': <gavo.base.parsecontext.IdAttribute object>}
name_ = 'stc'
onParentComplete()[source]

produces new-style STC annotation from the utypes.

This is being called as an onParentCompleted function from the tables’ stc attribute. It makes <stc> declarations work with new-style COOSYS and perhaps one day with mivot-based annotation.

classmethod sanitizeUtype(utype)[source]

returns utypes without the stupid 2D/3D qualifications.

class gavo.rscdef.tabledef.TableDef(parent, **kwargs)[source]

Bases: Structure, ComputedMetaMixin, PrivilegesMixin, IVOMetaMixin, StandardMacroMixin, PublishableDataMixin, ScriptingMixin

A definition of a table, both on-disk and internal.

Some attributes are ignored for in-memory tables, e.g., roles or adql.

Properties for tables:

  • supportsModel – a short name of a data model supported through this table (for TAPRegExt dataModel); you can give multiple names separated by commas.

  • supportsModelURI – a URI of a data model supported through this table. You can give multiple URIs separated by blanks.

  • forceStats – if present (with any value), dachs limits on the embedding RD will obtain statistics of this even if it is a view.

Somewhat inconsistently, to set a table’s utype if you have to, set its utype meta.

If you give multiple data model names or URIs, the sequences of names and URIs must be identical (in particular, each name needs a URI).

acceptedScriptTypes = {'afterMeta', 'beforeDrop', 'postCreation', 'preCreation', 'preIndex'}
attrSeq = [<gavo.rscdef.tabledef.ADQLVisibilityAttribute object>, <gavo.rscdef.common.ProfileListAttribute object>, <gavo.dm.dmrd.DataModelRolesAttribute object>, <gavo.rscdef.common.ColumnListAttribute object>, <gavo.base.attrdef.EnumeratedUnicodeAttribute object>, <gavo.base.attrdef.BooleanAttribute object>, <gavo.base.complexattrs.StructListAttribute object>, <gavo.base.complexattrs.StructListAttribute object>, <gavo.base.parsecontext.IdAttribute object>, <gavo.base.complexattrs.StructListAttribute object>, <gavo.base.meta.MetaAttribute object>, <gavo.rscdef.mixins.MixinAttribute object>, <gavo.rscdef.common.NamePathAttribute object>, <gavo.base.attrdef.IntAttribute object>, <gavo.base.attrdef.BooleanAttribute object>, <gavo.base.parsecontext.OriginalAttribute object>, <gavo.rscdef.common.ColumnListAttribute object>, <gavo.rscdef.tabledef.ColumnTupleAttribute object>, <gavo.base.complexattrs.PropertyAttribute object>, <gavo.rscdef.common.RDAttribute object>, <gavo.rscdef.common.ProfileListAttribute object>, <gavo.base.complexattrs.StructAttribute object>, <gavo.base.complexattrs.StructListAttribute object>, <gavo.base.complexattrs.StructListAttribute object>, <gavo.base.attrdef.BooleanAttribute object>, <gavo.base.attrdef.BooleanAttribute object>, <gavo.base.attrdef.UnicodeAttribute object>]
property caseFixer
clearProperty(name)
completeElement(ctx)[source]
completedCallbacks = []
static disambiguateColumns(columns)[source]

returns a sequence of columns without duplicate names.

doSimpleQuery(selectClause=None, fragments='', params=None, postfix='')[source]

runs a query generated via getSimpleQuery and returns a list of rowdicts.

This uses a table connection and queryToDicts; the keys in the dictionaries will have the right case for this table’s columns, though.

params is a dictionary of fillers for fragments and postfix.

fixupFunction = None
classmethod fromColumns(columns, **kwargs)[source]

returns a TableDef from a sequence of columns.

You can give additional constructor arguments. makeStruct is used to build the instance, the mixin hack is applied.

Columns with identical names will be disambiguated.

getByName(name)[source]

returns the column or param with name.

There is nothing keeping you from having both a column and a param with the same name. If that happens, you will only see the column. But don’t do it.

getByUtype(utype)[source]

returns the column or param with utype.

This is supposed to be unique, but the function will just return the first matching item it finds.

getByUtypes(*utypes)[source]

returns the first param or column matching the first utype matching anything.

getColumnById(id)[source]
getColumnByName(name)[source]
getColumnByUCD(ucd)[source]
getColumnByUCDs(*ucds)[source]
getColumnsByUCD(ucd)[source]
getColumnsByUCDs(*ucds)[source]
getDDL()[source]

returns an SQL statement that creates the table.

getDefaults()[source]

returns a mapping from column names to defaults to be used when making a row for this table.

getElementForName(name)[source]

returns the first of column and param having name name.

The function raises a NotFoundError if neither column nor param with name exists.

getFieldIndex(fieldName)[source]

returns the index of the field named fieldName.

getFullId()
getNote(noteTag)[source]

returns the table note meta value for noteTag.

This will raise a NotFoundError if we don’t have such a note.

You will not usually use this to retrieve meta items since columns have the meta values in their note attributes. Columns, of course, use this to get their note attribute value.

getParamByName(name)[source]
getPrimaryIn(row)
getProperty(name, default=<Undefined>)
getQName()[source]
getSTCDefs()[source]

returns a set of all STC specs referenced in this table as ASTs.

getSimpleQuery(selectClause=None, fragments='', postfix='')[source]

returns a query against this table.

selectClause is a list of column names (in which case the names are validated against the real column names and you can use user input) or a literal string (in which case you must not provide user input or have a SQL injection hole).

fragments (the WHERE CLAUSE) and postfix are taken as literal strings (so they must not contain user input).

This is purely a string operation, so you’ll have your normal value references in fragments and postfix, and should maintain the parameter dictionaries as usual.

All parts are optional, defaulting to pulling the entire table.

getURL(rendName, absolute=True)[source]

returns the URL DaCHS will show the table info page for this table under.

Of course the URL is only valid for imported tables.

hasProperty(name)
iterAnnotationsOfType(typeName)

returns the first annotation of the type passed.

macro_colNames()[source]

returns an SQL-ready list of column names of this table.

macro_curtable()[source]

returns the qualified name of the current table.

(this is identical to the `macro qName`_, which you should prefer in new RDs.)

macro_getParam(parName, default='')[source]

returns the string representation of the parameter parName.

This is the parameter as given in the table definition. Any changes to an instance are not reflected here.

If the parameter named does not exist, an empty string is returned. NULLs/Nones are rendered as NULL; this is mainly a convenience for obscore-like applications and should not be exploited otherwise, since it’s ugly and might change at some point.

If a default is given, it will be returned for both NULL and non-existing params.

macro_nameForUCD(ucd)[source]

returns the (unique!) name of the field having ucd in this table.

If there is no or more than one field with the ucd in this table, we raise a ValueError.

macro_nameForUCDs(ucds)[source]

returns the (unique!) name of the field having one of ucds in this table.

Ucds is a selection of ucds separated by vertical bars (|). The rules for when this raises errors are so crazy you don’t want to think about them. This really is only intended for cases where “old” and “new” standards are to be supported, like with pos.eq.*;meta.main and POS_EQ_*_MAIN.

If there is no or more than one field with the ucd in this table, we raise an exception.

macro_qName()[source]

returns the qualified name of the current table.

macro_tablename()[source]

returns the unqualified name of the current table.

In most contexts, you will probably need to use the `macro qName`_ instead of this.

makeRowFromTuple(dbTuple)[source]

returns a row (dict) from a row as returned from the database.

managedAttrs = {'adql': <gavo.rscdef.tabledef.ADQLVisibilityAttribute object>, 'allProfiles': <gavo.rscdef.common.ProfileListAttribute object>, 'column': <gavo.rscdef.common.ColumnListAttribute object>, 'columns': <gavo.rscdef.common.ColumnListAttribute object>, 'dm': <gavo.dm.dmrd.DataModelRolesAttribute object>, 'dupePolicy': <gavo.base.attrdef.EnumeratedUnicodeAttribute object>, 'forceUnique': <gavo.base.attrdef.BooleanAttribute object>, 'foreignKey': <gavo.base.complexattrs.StructListAttribute object>, 'foreignKeys': <gavo.base.complexattrs.StructListAttribute object>, 'group': <gavo.base.complexattrs.StructListAttribute object>, 'groups': <gavo.base.complexattrs.StructListAttribute object>, 'id': <gavo.base.parsecontext.IdAttribute object>, 'index': <gavo.base.complexattrs.StructListAttribute object>, 'indices': <gavo.base.complexattrs.StructListAttribute object>, 'meta': <gavo.base.meta.MetaAttribute object>, 'meta_': <gavo.base.meta.MetaAttribute object>, 'mixin': <gavo.rscdef.mixins.MixinAttribute object>, 'namePath': <gavo.rscdef.common.NamePathAttribute object>, 'nrows': <gavo.base.attrdef.IntAttribute object>, 'onDisk': <gavo.base.attrdef.BooleanAttribute object>, 'original': <gavo.base.parsecontext.OriginalAttribute object>, 'param': <gavo.rscdef.common.ColumnListAttribute object>, 'params': <gavo.rscdef.common.ColumnListAttribute object>, 'primary': <gavo.rscdef.tabledef.ColumnTupleAttribute object>, 'properties': <gavo.base.complexattrs.PropertyAttribute object>, 'property': <gavo.base.complexattrs.PropertyAttribute object>, 'publish': <gavo.base.complexattrs.StructAttribute object>, 'rd': <gavo.rscdef.common.RDAttribute object>, 'readProfiles': <gavo.rscdef.common.ProfileListAttribute object>, 'register': <gavo.base.complexattrs.StructAttribute object>, 'registration': <gavo.base.complexattrs.StructAttribute object>, 'script': <gavo.base.complexattrs.StructListAttribute object>, 'scripts': <gavo.base.complexattrs.StructListAttribute object>, 'stc': <gavo.base.complexattrs.StructListAttribute object>, 'system': <gavo.base.attrdef.BooleanAttribute object>, 'temporary': <gavo.base.attrdef.BooleanAttribute object>, 'viewStatement': <gavo.base.attrdef.UnicodeAttribute object>}
metaModel = 'creationDate(1), description(1),subject, referenceURL(1)'
mixesIn(mixinRef)
name_ = 'table'
onElementComplete()[source]
property rd
resType = 'table'
resolveName(context, id)
setProperty(name, value)
updateAnnotationFromChildren()
validate()[source]
validateRow(row)[source]

checks that row is complete and complies with all known constraints on the columns

The function raises a ValidationError with an appropriate message and the relevant field if not.

gavo.rscdef.tabledef.makeTDForColumns(name, cols, **moreKWs)[source]

returns a TableDef object named names and having the columns cols.

cols is some sequence of Column objects. You can give arbitrary table attributes in keyword arguments.