Coverage for python/lsst/sims/catalogs/db/CompoundCatalogDBObject.py : 92%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" This is a class for taking several CatalogDBObject daughter classes that query the same table of the same database for the same rows (but different columns; note that the columns can be transformed by the CatalogDBObjects' self.columns member), and combining their queries into one.
You feed the constructor a list of CatalogDBObject daughter classes. The CompoundCatalogDBObject verifies that they all do, indeed, query the same table of the same database. It then constructs its own self.columns member (note that CompoundCatalogDBObject is a daughter class of CatalogDBObject) which combines all of the requested data.
When you call query_columns, a recarray will be returned as in a CatalogDBObject. Note, however, that the names of the columns of the recarray will be modified. If the first CatalogDBObject in the list of CatalogDBObjects passed to the constructor asks for a column named 'col1', that will be mapped to 'catName_col1' where 'catName' is the CatalogDBObject's objid member. 'col2' will be mapped to 'catName_col2', etc. In cases where the CatalogDBObject does not change the name of the column, the column will also be returned by its original, un-mangled name.
In cases where a custom query_columns method must be implemented, this class can be sub-classed and the custom method added as a member method. In that case, the _table_restriction member variable should be set to a list of table names corresponding to the tables for which this class was designed. An exception will be raised if the user tries to use the CompoundCatalogDBObject class to query tables for which it was not written. _table_restriction defaults to None, which means that the class is for use with any table. """
# This member variable is an optional list of tables supported # by a specific CompoundCatalogDBObject sub-class. If # _table_restriction==None, then any table is supported
""" @param [in] catalogDbObjectClassList is a list of CatalogDBObject daughter classes (not instantiations of those classes; the classes themselves) that all query the same database table
Note: this is a list of classes, not a list of instantiations of those classes. The connection to the database is established as soon as you instantiate a CatalogDBObject daughter class. To avoid creating unnecessary database connections, CompoundCatalogDBObject will read in classes without an active connection and establish its own connection in this constructor. This means that all connection parameters must be specified in the class definitions of the classes passed into catalogDbObjectClassList.
@param [in] connection is an optional instantiation of DBConnection representing an active connection to the database required by this CompoundCatalogDBObject (prevents the CompoundCatalogDBObject from opening a redundant connection) """
# need to instantiate the first one because sometimes # idColKey is not defined until instantiation # (see GalaxyTileObj in sims_catUtils/../baseCatalogModels/GalaxyModels.py)
""" Construct the self.columns member by concatenating the self.columns from the input CatalogDBObjects and modifying the names of the returned columns to identify them with their specific CatalogDBObjects. """
# 25 August 2015 # This is a modification that needs to be made in order for this # class to work with GalaxyTileObj. The column galaxytileid in # GalaxyTileObj is removed from the query by query_columns, but # somehow injected back in by the query procedure on fatboy. This # leads to confusion if you try to query something like # galaxyAgn_galaxytileid. We deal with that by removing all column # names like 'galaxytileid' in query_columns, but leaving 'galaxytileid' # un-mangled in self.columns so that self.typeMap knows how to deal # with it when it comes back.
""" Construct the self.dbTypeMap member by concatenating the self.dbTypeMaps from the input CatalogDBObjects. """
""" Construct the self.dbDefaultValues member by concatenating the self.dbDefaultValues from the input CatalogDBObjects. """
""" Verify that the CatalogDBObjects passed to the constructor do, indeed, query the same table of the same database.
Also verify that this class is designed to query the tables it is being used on (in cases where a custom query_columns has been implemented). """
else: 'is duplicated in your list of ' + 'CatalogDBObjects\n' + 'CompoundCatalogDBObject requires each' + ' CatalogDBObject have a unique objid\n')
acceptable = False msg += ' hosts: ' + str(hostList) + '\n'
acceptable = False msg += ' ports: ' + str(portList) + '\n'
acceptable = False msg += ' drivers: ' + str(driverList) + '\n'
'CompoundCatalogDBObject do not all ' + 'query the same table:\n' + msg)
"the table '%s' " % tableList[0]) |