LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst.daf.persistence.registries.SqlRegistry Class Reference
Inheritance diagram for lsst.daf.persistence.registries.SqlRegistry:
lsst.daf.persistence.registries.Registry lsst.daf.persistence.registries.PgsqlRegistry lsst.daf.persistence.registries.SqliteRegistry

Public Member Functions

def __init__ (self, conn)
 
def __del__ (self)
 
def lookup (self, lookupProperties, reference, dataId, **kwargs)
 
def executeQuery (self, returnFields, joinClause, whereFields, range, values)
 

Static Public Member Functions

def create (location)
 

Public Attributes

 conn
 

Static Public Attributes

string placeHolder = "?"
 

Detailed Description

A base class for SQL-based registries

Subclasses should define the class variable `placeHolder` (the particular
placeholder to use for parameter substitution) appropriately. The
database's python module should define `paramstyle` (see PEP 249), which
would indicate what to use for a placeholder:
* paramstyle = "qmark" --> placeHolder = "?"
* paramstyle = "format" --> placeHolder = "%s"
Other `paramstyle` values are not currently supported.

Constructor parameters
----------------------
conn : DBAPI connection object
    Connection object

Definition at line 286 of file registries.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.daf.persistence.registries.SqlRegistry.__init__ (   self,
  conn 
)
Constructor.

Parameters
----------
conn : DBAPI connection object
    Connection object

Reimplemented in lsst.daf.persistence.registries.PgsqlRegistry, and lsst.daf.persistence.registries.SqliteRegistry.

Definition at line 304 of file registries.py.

304  def __init__(self, conn):
305  """Constructor.
306 
307  Parameters
308  ----------
309  conn : DBAPI connection object
310  Connection object
311  """
312  Registry.__init__(self)
313  self.conn = conn
314 

◆ __del__()

def lsst.daf.persistence.registries.SqlRegistry.__del__ (   self)

Reimplemented from lsst.daf.persistence.registries.Registry.

Definition at line 315 of file registries.py.

315  def __del__(self):
316  if hasattr(self, "conn") and self.conn:
317  self.conn.close()
318  super().__del__()
319 

Member Function Documentation

◆ create()

def lsst.daf.persistence.registries.Registry.create (   location)
staticinherited
Create a registry object of an appropriate type.
@param location (string) Path or URL for registry, or None if
                         unavailable

Definition at line 71 of file registries.py.

71  def create(location):
72  """Create a registry object of an appropriate type.
73  @param location (string) Path or URL for registry, or None if
74  unavailable"""
75 
76  if location is None:
77  return
78 
79  # if re.match(r'.*\.registry', location):
80  # return FileRegistry(location)
81 
82  if location.endswith(".pgsql"):
83  return PgsqlRegistry(location)
84 
85  # look for an sqlite3 registry
86  if re.match(r'.*\.sqlite3', location):
87  if not haveSqlite3:
88  raise RuntimeError("sqlite3 registry specified (%s), but unable to import sqlite3 module" %
89  (location,))
90  registry = SqliteRegistry(location)
91  if registry.conn is None:
92  return None
93  return registry
94 
95  # if re.match(r'mysql:', location):
96  # return DbRegistry(location)
97  # return FsRegistry(location)
98 
99  # next try to create a PosixRegistry
100  if os.path.isdir(location):
101  return PosixRegistry(root=location)
102 
103  raise RuntimeError("Unable to create registry using location: " + location)
104 
105 

◆ executeQuery()

def lsst.daf.persistence.registries.SqlRegistry.executeQuery (   self,
  returnFields,
  joinClause,
  whereFields,
  range,
  values 
)
Extract metadata from the registry.
@param returnFields (list of strings) Metadata fields to be extracted.
@param joinClause   (list of strings) Tables in which metadata fields
                    are located.
@param whereFields  (list of tuples) First tuple element is metadata
                    field to query; second is the value that field
                    must have (often '?').
@param range        (tuple) Value, lower limit, and upper limit for a
                    range condition on the metadata.  Any of these can
                    be metadata fields.
@param values       (tuple) Tuple of values to be substituted for '?'
                    characters in the whereFields values or the range
                    values.
@return (list of tuples) All sets of field values that meet the
        criteria

Definition at line 401 of file registries.py.

401  def executeQuery(self, returnFields, joinClause, whereFields, range, values):
402  """Extract metadata from the registry.
403  @param returnFields (list of strings) Metadata fields to be extracted.
404  @param joinClause (list of strings) Tables in which metadata fields
405  are located.
406  @param whereFields (list of tuples) First tuple element is metadata
407  field to query; second is the value that field
408  must have (often '?').
409  @param range (tuple) Value, lower limit, and upper limit for a
410  range condition on the metadata. Any of these can
411  be metadata fields.
412  @param values (tuple) Tuple of values to be substituted for '?'
413  characters in the whereFields values or the range
414  values.
415  @return (list of tuples) All sets of field values that meet the
416  criteria"""
417  if not self.conn:
418  return None
419  cmd = "SELECT DISTINCT "
420  cmd += ", ".join(returnFields)
421  cmd += " FROM " + " NATURAL JOIN ".join(joinClause)
422  whereList = []
423  if whereFields:
424  for k, v in whereFields:
425  whereList.append("(%s = %s)" % (k, v))
426  if range is not None:
427  whereList.append("(%s BETWEEN %s AND %s)" % range)
428  if len(whereList) > 0:
429  cmd += " WHERE " + " AND ".join(whereList)
430  cursor = self.conn.cursor()
431  cursor.execute(cmd, values)
432  return [row for row in cursor.fetchall()]
433 
434 

◆ lookup()

def lsst.daf.persistence.registries.SqlRegistry.lookup (   self,
  lookupProperties,
  reference,
  dataId,
**  kwargs 
)
Perform a lookup in the registry.

Return values are refined by the values in dataId.
Returns a list of values that match keys in lookupProperties.
e.g. if the template is 'raw/raw_v%(visit)d_f%(filter)s.fits.gz', and
dataId={'visit':1}, and lookupProperties is ['filter'], and the
filesystem under self.root has exactly one file 'raw/raw_v1_fg.fits.gz'
then the return value will be [('g',)]

:param lookupProperties:
:param dataId: must be a key/value iterable. Keys must be string.
If value is a string then will look for elements in the repository that match value for value.
If value is a 2-item iterable then will look for elements in the repository where the value is between
the values of value[0] and value[1].
:param reference: other data types that may be used to search for values.
:param **kwargs: nothing needed for sqlite lookup
:return: a list of values that match keys in lookupProperties.

Definition at line 370 of file registries.py.

370  def lookup(self, lookupProperties, reference, dataId, **kwargs):
371  """Perform a lookup in the registry.
372 
373  Return values are refined by the values in dataId.
374  Returns a list of values that match keys in lookupProperties.
375  e.g. if the template is 'raw/raw_v%(visit)d_f%(filter)s.fits.gz', and
376  dataId={'visit':1}, and lookupProperties is ['filter'], and the
377  filesystem under self.root has exactly one file 'raw/raw_v1_fg.fits.gz'
378  then the return value will be [('g',)]
379 
380  :param lookupProperties:
381  :param dataId: must be a key/value iterable. Keys must be string.
382  If value is a string then will look for elements in the repository that match value for value.
383  If value is a 2-item iterable then will look for elements in the repository where the value is between
384  the values of value[0] and value[1].
385  :param reference: other data types that may be used to search for values.
386  :param **kwargs: nothing needed for sqlite lookup
387  :return: a list of values that match keys in lookupProperties.
388  """
389  if not self.conn:
390  return None
391 
392  # input variable sanitization:
393  reference = sequencify(reference)
394  lookupProperties = sequencify(lookupProperties)
395 
396  try:
397  return self._lookup(lookupProperties, dataId, reference)
398  except sqlite3.OperationalError: # try again, with extra checking of the dataId keys
399  return self._lookup(lookupProperties, dataId, reference, checkColumns=True)
400 

Member Data Documentation

◆ conn

lsst.daf.persistence.registries.SqlRegistry.conn

Definition at line 313 of file registries.py.

◆ placeHolder

string lsst.daf.persistence.registries.SqlRegistry.placeHolder = "?"
static

Definition at line 302 of file registries.py.


The documentation for this class was generated from the following file: