(self, dst, part_time)
Create part table if not exists.

        It part_template present, execute it
        else if part function present in db, call it
        else clone master table
Create part table if not exists.
Create part table if not exists .
def check_part(self, dst, part_time):
        """Create part table if not exists.

        It part_template present, execute it
        else if part function present in db, call it
        else clone master table"""
        curs = self.dst_curs
        if (self.conf.ignore_old_events and self.conf.retention_period and
                self.is_obsolete_partition (dst, self.conf.retention_period, self.conf.period)):
            self.ignored_tables.add(dst)
            return
        if skytools.exists_table(curs, dst):
            return

        dst = quote_fqident(dst)
        vals = {'dest': dst,
                'part': dst,
                'parent': self.fq_dest_table,
                'pkeys': ",".join(self.pkeys), # quoting?
                # we do this to make sure that constraints for
                # tables who contain a schema will still work
                'schema_table': dst.replace(".", "__"),
                'part_field': self.conf.part_field,
                'part_time': part_time,
                'period': self.conf.period,
                }
        def exec_with_vals(tmpl):
            if tmpl:
                sql = tmpl % vals
                curs.execute(sql)
                return True
            return False

        exec_with_vals(self.conf.pre_part)

        if not exec_with_vals(self.conf.part_template):
            self.log.debug('part_template not provided, using part func')
            # if part func exists call it with val arguments
            pfargs = ', '.join('%%(%s)s' % arg for arg in PART_FUNC_ARGS)

            # set up configured function
            pfcall = 'select %s(%s)' % (self.conf.part_func, pfargs)
            have_func = skytools.exists_function(curs, self.conf.part_func, len(PART_FUNC_ARGS))

            # backwards compat
            if not have_func and self.conf.part_func == PART_FUNC_NEW:
                pfcall = 'select %s(%s)' % (PART_FUNC_OLD, pfargs)
                have_func = skytools.exists_function(curs, PART_FUNC_OLD, len(PART_FUNC_ARGS))

            if have_func:
                self.log.debug('check_part.exec: func: %s, args: %s', pfcall, vals)
                curs.execute(pfcall, vals)
            else:
                #
                # Otherwise create simple clone.
                #
                # FixMe: differences from create_partitions():
                # - check constraints
                # - inheritance
                #
                self.log.debug('part func %s not found, cloning table', self.conf.part_func)
                struct = TableStruct(curs, self.dest_table)
                struct.create(curs, T_ALL, dst)

        exec_with_vals(self.conf.post_part)
        self.log.info("Created table: %s", dst)

        if self.conf.retention_period:
            dropped = self.drop_obsolete_partitions (self.dest_table, self.conf.retention_period, self.conf.period)
            if self.conf.ignore_old_events and dropped:
                for tbl in dropped:
                    self.ignored_tables.add(tbl)
                    if tbl in self.row_handler.table_map:
                        del self.row_handler.table_map[tbl]
def check_part ( self , dst , part_time ) : curs = self . dst_curs if ( self . conf . ignore_old_events and self . conf . retention_period and self . is_obsolete_partition ( dst , self . conf . retention_period , self . conf . period ) ) : self . ignored_tables . add ( dst ) return if skytools . exists_table ( curs , dst ) : return dst = quote_fqident ( dst ) vals = { 'dest' : dst , 'part' : dst , 'parent' : self . fq_dest_table , 'pkeys' : "," . join ( self . pkeys ) , # quoting? # we do this to make sure that constraints for # tables who contain a schema will still work 'schema_table' : dst . replace ( "." , "__" ) , 'part_field' : self . conf . part_field , 'part_time' : part_time , 'period' : self . conf . period , } def exec_with_vals ( tmpl ) : if tmpl : sql = tmpl % vals curs . execute ( sql ) return True return False exec_with_vals ( self . conf . pre_part ) if not exec_with_vals ( self . conf . part_template ) : self . log . debug ( 'part_template not provided, using part func' ) # if part func exists call it with val arguments pfargs = ', ' . join ( '%%(%s)s' % arg for arg in PART_FUNC_ARGS ) # set up configured function pfcall = 'select %s(%s)' % ( self . conf . part_func , pfargs ) have_func = skytools . exists_function ( curs , self . conf . part_func , len ( PART_FUNC_ARGS ) ) # backwards compat if not have_func and self . conf . part_func == PART_FUNC_NEW : pfcall = 'select %s(%s)' % ( PART_FUNC_OLD , pfargs ) have_func = skytools . exists_function ( curs , PART_FUNC_OLD , len ( PART_FUNC_ARGS ) ) if have_func : self . log . debug ( 'check_part.exec: func: %s, args: %s' , pfcall , vals ) curs . execute ( pfcall , vals ) else : # # Otherwise create simple clone. # # FixMe: differences from create_partitions(): # - check constraints # - inheritance # self . log . debug ( 'part func %s not found, cloning table' , self . conf . part_func ) struct = TableStruct ( curs , self . dest_table ) struct . create ( curs , T_ALL , dst ) exec_with_vals ( self . conf . post_part ) self . log . info ( "Created table: %s" , dst ) if self . conf . retention_period : dropped = self . drop_obsolete_partitions ( self . dest_table , self . conf . retention_period , self . conf . period ) if self . conf . ignore_old_events and dropped : for tbl in dropped : self . ignored_tables . add ( tbl ) if tbl in self . row_handler . table_map : del self . row_handler . table_map [ tbl ]