LSST Applications  21.0.0-147-g0e635eb1+1acddb5be5,22.0.0+052faf71bd,22.0.0+1ea9a8b2b2,22.0.0+6312710a6c,22.0.0+729191ecac,22.0.0+7589c3a021,22.0.0+9f079a9461,22.0.1-1-g7d6de66+b8044ec9de,22.0.1-1-g87000a6+536b1ee016,22.0.1-1-g8e32f31+6312710a6c,22.0.1-10-gd060f87+016f7cdc03,22.0.1-12-g9c3108e+df145f6f68,22.0.1-16-g314fa6d+c825727ab8,22.0.1-19-g93a5c75+d23f2fb6d8,22.0.1-19-gb93eaa13+aab3ef7709,22.0.1-2-g8ef0a89+b8044ec9de,22.0.1-2-g92698f7+9f079a9461,22.0.1-2-ga9b0f51+052faf71bd,22.0.1-2-gac51dbf+052faf71bd,22.0.1-2-gb66926d+6312710a6c,22.0.1-2-gcb770ba+09e3807989,22.0.1-20-g32debb5+b8044ec9de,22.0.1-23-gc2439a9a+fb0756638e,22.0.1-3-g496fd5d+09117f784f,22.0.1-3-g59f966b+1e6ba2c031,22.0.1-3-g849a1b8+f8b568069f,22.0.1-3-gaaec9c0+c5c846a8b1,22.0.1-32-g5ddfab5d3+60ce4897b0,22.0.1-4-g037fbe1+64e601228d,22.0.1-4-g8623105+b8044ec9de,22.0.1-5-g096abc9+d18c45d440,22.0.1-5-g15c806e+57f5c03693,22.0.1-7-gba73697+57f5c03693,master-g6e05de7fdc+c1283a92b8,master-g72cdda8301+729191ecac,w.2021.39
LSST Data Management Base Package
Public Member Functions | Static Public Attributes | List of all members
lsst.pipe.tasks.ingestPgsql.PgsqlRegisterTask Class Reference
Inheritance diagram for lsst.pipe.tasks.ingestPgsql.PgsqlRegisterTask:
lsst.pipe.tasks.ingest.RegisterTask

Public Member Functions

def openRegistry (self, directory, create=False, dryrun=False)
 
def createTable (self, conn, table=None)
 
def openRegistry (self, directory, create=False, dryrun=False, name="registry.sqlite3")
 
def createTable (self, conn, table=None, forceCreateTables=False)
 
def check (self, conn, info, table=None)
 
def addRow (self, conn, info, dryrun=False, create=False, table=None)
 

Static Public Attributes

string placeHolder = "%s"
 
 ConfigClass = RegisterConfig
 
dictionary typemap = {'text': str, 'int': int, 'double': float}
 

Detailed Description

Definition at line 49 of file ingestPgsql.py.

Member Function Documentation

◆ addRow()

def lsst.pipe.tasks.ingest.RegisterTask.addRow (   self,
  conn,
  info,
  dryrun = False,
  create = False,
  table = None 
)
inherited
Add a row to the file table (typically 'raw').

@param conn    Database connection
@param info    File properties to add to database
@param table   Name of table in database

Definition at line 359 of file ingest.py.

359  def addRow(self, conn, info, dryrun=False, create=False, table=None):
360  """Add a row to the file table (typically 'raw').
361 
362  @param conn Database connection
363  @param info File properties to add to database
364  @param table Name of table in database
365  """
366  with conn:
367  if table is None:
368  table = self.config.table
369  ignoreClause = ""
370  if self.config.ignore:
371  ignoreClause = " OR IGNORE"
372  sql = "INSERT%s INTO %s (%s) VALUES (" % (ignoreClause, table, ",".join(self.config.columns))
373  sql += ",".join([self.placeHolder] * len(self.config.columns)) + ")"
374  values = [self.typemap[tt](info[col]) for col, tt in self.config.columns.items()]
375 
376  if dryrun:
377  print("Would execute: '%s' with %s" % (sql, ",".join([str(value) for value in values])))
378  else:
379  conn.cursor().execute(sql, values)
380 
381  sql = "INSERT OR IGNORE INTO %s_visit VALUES (" % table
382  sql += ",".join([self.placeHolder] * len(self.config.visit)) + ")"
383  values = [self.typemap[self.config.columns[col]](info[col]) for col in self.config.visit]
384 
385  if dryrun:
386  print("Would execute: '%s' with %s" % (sql, ",".join([str(value) for value in values])))
387  else:
388  conn.cursor().execute(sql, values)
389 
390 

◆ check()

def lsst.pipe.tasks.ingest.RegisterTask.check (   self,
  conn,
  info,
  table = None 
)
inherited
Check for the presence of a row already

Not sure this is required, given the 'ignore' configuration option.

Definition at line 340 of file ingest.py.

340  def check(self, conn, info, table=None):
341  """Check for the presence of a row already
342 
343  Not sure this is required, given the 'ignore' configuration option.
344  """
345  if table is None:
346  table = self.config.table
347  if self.config.ignore or len(self.config.unique) == 0:
348  return False # Our entry could already be there, but we don't care
349  cursor = conn.cursor()
350  sql = "SELECT COUNT(*) FROM %s WHERE " % table
351  sql += " AND ".join(["%s = %s" % (col, self.placeHolder) for col in self.config.unique])
352  values = [self.typemap[self.config.columns[col]](info[col]) for col in self.config.unique]
353 
354  cursor.execute(sql, values)
355  if cursor.fetchone()[0] > 0:
356  return True
357  return False
358 

◆ createTable() [1/2]

def lsst.pipe.tasks.ingestPgsql.PgsqlRegisterTask.createTable (   self,
  conn,
  table = None 
)
Create the registry tables

One table (typically 'raw') contains information on all files, and the
other (typically 'raw_visit') contains information on all visits.

This method is required because there's a slightly different syntax
compared to SQLite (FLOAT instead of DOUBLE, SERIAL instead of
AUTOINCREMENT).

@param conn    Database connection
@param table   Name of table to create in database

Definition at line 65 of file ingestPgsql.py.

65  def createTable(self, conn, table=None):
66  """Create the registry tables
67 
68  One table (typically 'raw') contains information on all files, and the
69  other (typically 'raw_visit') contains information on all visits.
70 
71  This method is required because there's a slightly different syntax
72  compared to SQLite (FLOAT instead of DOUBLE, SERIAL instead of
73  AUTOINCREMENT).
74 
75  @param conn Database connection
76  @param table Name of table to create in database
77  """
78  if table is None:
79  table = self.config.table
80 
81  typeMap = {'int': 'INT',
82  'double': 'FLOAT', # Defaults to double precision
83  }
84 
85  cur = conn.cursor()
86  cmd = "CREATE TABLE %s (id SERIAL NOT NULL PRIMARY KEY, " % table
87  cmd += ",".join(["%s %s" % (col, typeMap.get(colType.lower(), 'text')) for
88  col, colType in self.config.columns.items()])
89  if len(self.config.unique) > 0:
90  cmd += ", UNIQUE(" + ",".join(self.config.unique) + ")"
91  cmd += ")"
92  cur.execute(cmd)
93 
94  cmd = "CREATE TABLE %s_visit (" % self.config.table
95  cmd += ",".join(["%s %s" % (col, typeMap.get(self.config.columns[col].lower(), 'TEXT')) for
96  col in self.config.visit])
97  cmd += ", UNIQUE(" + ",".join(set(self.config.visit).intersection(set(self.config.unique))) + ")"
98  cmd += ")"
99  cur.execute(cmd)
100  del cur
101  conn.commit()
102 
103 
daf::base::PropertySet * set
Definition: fits.cc:912

◆ createTable() [2/2]

def lsst.pipe.tasks.ingest.RegisterTask.createTable (   self,
  conn,
  table = None,
  forceCreateTables = False 
)
inherited
Create the registry tables

One table (typically 'raw') contains information on all files, and the
other (typically 'raw_visit') contains information on all visits.

@param conn    Database connection
@param table   Name of table to create in database

Definition at line 302 of file ingest.py.

302  def createTable(self, conn, table=None, forceCreateTables=False):
303  """Create the registry tables
304 
305  One table (typically 'raw') contains information on all files, and the
306  other (typically 'raw_visit') contains information on all visits.
307 
308  @param conn Database connection
309  @param table Name of table to create in database
310  """
311  cursor = conn.cursor()
312  if table is None:
313  table = self.config.table
314  cmd = "SELECT name FROM sqlite_master WHERE type='table' AND name='%s'" % table
315  cursor.execute(cmd)
316  if cursor.fetchone() and not forceCreateTables: # Assume if we get an answer the table exists
317  self.log.info('Table "%s" exists. Skipping creation', table)
318  return
319  else:
320  cmd = "drop table if exists %s" % table
321  cursor.execute(cmd)
322  cmd = "drop table if exists %s_visit" % table
323  cursor.execute(cmd)
324 
325  cmd = "create table %s (id integer primary key autoincrement, " % table
326  cmd += ",".join([("%s %s" % (col, colType)) for col, colType in self.config.columns.items()])
327  if len(self.config.unique) > 0:
328  cmd += ", unique(" + ",".join(self.config.unique) + ")"
329  cmd += ")"
330  cursor.execute(cmd)
331 
332  cmd = "create table %s_visit (" % table
333  cmd += ",".join([("%s %s" % (col, self.config.columns[col])) for col in self.config.visit])
334  cmd += ", unique(" + ",".join(set(self.config.visit).intersection(set(self.config.unique))) + ")"
335  cmd += ")"
336  cursor.execute(cmd)
337 
338  conn.commit()
339 

◆ openRegistry() [1/2]

def lsst.pipe.tasks.ingestPgsql.PgsqlRegisterTask.openRegistry (   self,
  directory,
  create = False,
  dryrun = False 
)
Open the registry and return the connection handle.

@param directory  Directory in which the registry file will be placed
@param create  Clobber any existing registry and create a new one?
@param dryrun  Don't do anything permanent?
@return Database connection

Definition at line 52 of file ingestPgsql.py.

52  def openRegistry(self, directory, create=False, dryrun=False):
53  """Open the registry and return the connection handle.
54 
55  @param directory Directory in which the registry file will be placed
56  @param create Clobber any existing registry and create a new one?
57  @param dryrun Don't do anything permanent?
58  @return Database connection
59  """
60  if dryrun:
61  return fakeContext()
62  registryName = os.path.join(directory, "registry.pgsql")
63  return PgsqlRegistryContext(registryName, self.createTable, create)
64 

◆ openRegistry() [2/2]

def lsst.pipe.tasks.ingest.RegisterTask.openRegistry (   self,
  directory,
  create = False,
  dryrun = False,
  name = "registry.sqlite3" 
)
inherited
Open the registry and return the connection handle.

@param directory  Directory in which the registry file will be placed
@param create  Clobber any existing registry and create a new one?
@param dryrun  Don't do anything permanent?
@param name    Filename of the registry
@return Database connection

Reimplemented in lsst.pipe.tasks.ingestCalibs.CalibsRegisterTask.

Definition at line 286 of file ingest.py.

286  def openRegistry(self, directory, create=False, dryrun=False, name="registry.sqlite3"):
287  """Open the registry and return the connection handle.
288 
289  @param directory Directory in which the registry file will be placed
290  @param create Clobber any existing registry and create a new one?
291  @param dryrun Don't do anything permanent?
292  @param name Filename of the registry
293  @return Database connection
294  """
295  if dryrun:
296  return fakeContext()
297 
298  registryName = os.path.join(directory, name)
299  context = RegistryContext(registryName, self.createTable, create, self.config.permissions)
300  return context
301 

Member Data Documentation

◆ ConfigClass

lsst.pipe.tasks.ingest.RegisterTask.ConfigClass = RegisterConfig
staticinherited

Definition at line 282 of file ingest.py.

◆ placeHolder

string lsst.pipe.tasks.ingestPgsql.PgsqlRegisterTask.placeHolder = "%s"
static

Definition at line 50 of file ingestPgsql.py.

◆ typemap

dictionary lsst.pipe.tasks.ingest.RegisterTask.typemap = {'text': str, 'int': int, 'double': float}
staticinherited

Definition at line 284 of file ingest.py.


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