src/dirbs/listgen/generator.py
def _populate_delta_blacklist(self, executor):
        """Function to populate the old blacklist."""
        with create_db_connection(self._config.db_config) as conn, conn.cursor() as cursor, CodeProfiler() as cp:
            delta_tbl_name = self._blacklist_delta_tblname
            delta_tbl = sql.Identifier(delta_tbl_name)
            old_tbl = sql.Identifier(self._blacklist_old_tblname)
            new_tbl = sql.Identifier(self._blacklist_new_tblname)
            # First, generate a delta for any 'blocked' records (new adds)
            cursor.execute(sql.SQL("""INSERT INTO {delta_tbl}(imei_norm,
                                                              virt_imei_shard,
                                                              block_date,
                                                              reasons,
                                                              start_run_id,
                                                              end_run_id,
                                                              delta_reason)
                                           SELECT imei_norm, virt_imei_shard, block_date, reasons, %s, NULL, 'blocked'
                                             FROM {new_tbl} nt
                                            WHERE NOT EXISTS(SELECT 1
                                                               FROM {old_tbl}
                                                              WHERE imei_norm = nt.imei_norm
                                                                AND virt_imei_shard = nt.virt_imei_shard)
                                   """).format(delta_tbl=delta_tbl, old_tbl=old_tbl, new_tbl=new_tbl),  # noqa: Q449
                           [self._run_id])
            num_records = cursor.rowcount
            # Next, generate a delta for any 'unblocked' records (new removals) (table direction flipped)
            cursor.execute(sql.SQL("""INSERT INTO {delta_tbl}(imei_norm,
                                                              virt_imei_shard,
                                                              block_date,
                                                              reasons,
                                                              start_run_id,
                                                              end_run_id,
                                                              delta_reason)
                                           SELECT imei_norm, virt_imei_shard, block_date,
                                                  reasons, %s, NULL, 'unblocked'
                                             FROM {old_tbl} ot
                                            WHERE NOT EXISTS(SELECT 1
                                                               FROM {new_tbl}
                                                              WHERE imei_norm = ot.imei_norm
                                                                AND virt_imei_shard = ot.virt_imei_shard)
                                   """).format(delta_tbl=delta_tbl, old_tbl=old_tbl, new_tbl=new_tbl),  # noqa: Q449
                           [self._run_id])
            num_records += cursor.rowcount
            # Next, generate a delta for any 'changed' records
            cursor.execute(sql.SQL("""INSERT INTO {delta_tbl}(imei_norm,
                                                              virt_imei_shard,
                                                              block_date,
                                                              reasons,
                                                              start_run_id,
                                                              end_run_id,
                                                              delta_reason)
                                           SELECT nt.imei_norm, nt.virt_imei_shard, nt.block_date,
                                                  nt.reasons, %s, NULL, 'changed'
                                             FROM {new_tbl} nt
                                             JOIN {old_tbl} ot
                                            USING (imei_norm)
                                            WHERE ot.block_date <> nt.block_date
                                               OR ot.reasons <> nt.reasons
                                   """).format(delta_tbl=delta_tbl, old_tbl=old_tbl, new_tbl=new_tbl),
                           [self._run_id])
            num_records += cursor.rowcount
            self._analyze_helper(cursor, delta_tbl_name)

        return num_records, cp.duration
Function to populate the old blacklist.
Function to populate the old blacklist.
Function to populate the old blacklist .
def _populate_delta_blacklist(self, executor):
        with create_db_connection(self._config.db_config) as conn, conn.cursor() as cursor, CodeProfiler() as cp:
            delta_tbl_name = self._blacklist_delta_tblname
            delta_tbl = sql.Identifier(delta_tbl_name)
            old_tbl = sql.Identifier(self._blacklist_old_tblname)
            new_tbl = sql.Identifier(self._blacklist_new_tblname)
            cursor.execute(sql.SQL("""INSERT INTO {delta_tbl}(imei_norm,
                                                              virt_imei_shard,
                                                              block_date,
                                                              reasons,
                                                              start_run_id,
                                                              end_run_id,
                                                              delta_reason)
                                           SELECT imei_norm, virt_imei_shard, block_date, reasons, %s, NULL, 'blocked'
                                             FROM {new_tbl} nt
                                            WHERE NOT EXISTS(SELECT 1
                                                               FROM {old_tbl}
                                                              WHERE imei_norm = nt.imei_norm
                                                                AND virt_imei_shard = nt.virt_imei_shard)
                                   """).format(delta_tbl=delta_tbl, old_tbl=old_tbl, new_tbl=new_tbl),  
                           [self._run_id])
            num_records = cursor.rowcount
            cursor.execute(sql.SQL("""INSERT INTO {delta_tbl}(imei_norm,
                                                              virt_imei_shard,
                                                              block_date,
                                                              reasons,
                                                              start_run_id,
                                                              end_run_id,
                                                              delta_reason)
                                           SELECT imei_norm, virt_imei_shard, block_date,
                                                  reasons, %s, NULL, 'unblocked'
                                             FROM {old_tbl} ot
                                            WHERE NOT EXISTS(SELECT 1
                                                               FROM {new_tbl}
                                                              WHERE imei_norm = ot.imei_norm
                                                                AND virt_imei_shard = ot.virt_imei_shard)
                                   """).format(delta_tbl=delta_tbl, old_tbl=old_tbl, new_tbl=new_tbl),  
                           [self._run_id])
            num_records += cursor.rowcount
            cursor.execute(sql.SQL("""INSERT INTO {delta_tbl}(imei_norm,
                                                              virt_imei_shard,
                                                              block_date,
                                                              reasons,
                                                              start_run_id,
                                                              end_run_id,
                                                              delta_reason)
                                           SELECT nt.imei_norm, nt.virt_imei_shard, nt.block_date,
                                                  nt.reasons, %s, NULL, 'changed'
                                             FROM {new_tbl} nt
                                             JOIN {old_tbl} ot
                                            USING (imei_norm)
                                            WHERE ot.block_date <> nt.block_date
                                               OR ot.reasons <> nt.reasons
                                   """).format(delta_tbl=delta_tbl, old_tbl=old_tbl, new_tbl=new_tbl),
                           [self._run_id])
            num_records += cursor.rowcount
            self._analyze_helper(cursor, delta_tbl_name)
        return num_records, cp.duration
def _populate_delta_blacklist ( self , executor ) : with create_db_connection ( self . _config . db_config ) as conn , conn . cursor ( ) as cursor , CodeProfiler ( ) as cp : delta_tbl_name = self . _blacklist_delta_tblname delta_tbl = sql . Identifier ( delta_tbl_name ) old_tbl = sql . Identifier ( self . _blacklist_old_tblname ) new_tbl = sql . Identifier ( self . _blacklist_new_tblname ) cursor . execute ( sql . SQL ( """INSERT INTO {delta_tbl}(imei_norm,
                                                              virt_imei_shard,
                                                              block_date,
                                                              reasons,
                                                              start_run_id,
                                                              end_run_id,
                                                              delta_reason)
                                           SELECT imei_norm, virt_imei_shard, block_date, reasons, %s, NULL, 'blocked'
                                             FROM {new_tbl} nt
                                            WHERE NOT EXISTS(SELECT 1
                                                               FROM {old_tbl}
                                                              WHERE imei_norm = nt.imei_norm
                                                                AND virt_imei_shard = nt.virt_imei_shard)
                                   """ ) . format ( delta_tbl = delta_tbl , old_tbl = old_tbl , new_tbl = new_tbl ) , [ self . _run_id ] ) num_records = cursor . rowcount cursor . execute ( sql . SQL ( """INSERT INTO {delta_tbl}(imei_norm,
                                                              virt_imei_shard,
                                                              block_date,
                                                              reasons,
                                                              start_run_id,
                                                              end_run_id,
                                                              delta_reason)
                                           SELECT imei_norm, virt_imei_shard, block_date,
                                                  reasons, %s, NULL, 'unblocked'
                                             FROM {old_tbl} ot
                                            WHERE NOT EXISTS(SELECT 1
                                                               FROM {new_tbl}
                                                              WHERE imei_norm = ot.imei_norm
                                                                AND virt_imei_shard = ot.virt_imei_shard)
                                   """ ) . format ( delta_tbl = delta_tbl , old_tbl = old_tbl , new_tbl = new_tbl ) , [ self . _run_id ] ) num_records += cursor . rowcount cursor . execute ( sql . SQL ( """INSERT INTO {delta_tbl}(imei_norm,
                                                              virt_imei_shard,
                                                              block_date,
                                                              reasons,
                                                              start_run_id,
                                                              end_run_id,
                                                              delta_reason)
                                           SELECT nt.imei_norm, nt.virt_imei_shard, nt.block_date,
                                                  nt.reasons, %s, NULL, 'changed'
                                             FROM {new_tbl} nt
                                             JOIN {old_tbl} ot
                                            USING (imei_norm)
                                            WHERE ot.block_date <> nt.block_date
                                               OR ot.reasons <> nt.reasons
                                   """ ) . format ( delta_tbl = delta_tbl , old_tbl = old_tbl , new_tbl = new_tbl ) , [ self . _run_id ] ) num_records += cursor . rowcount self . _analyze_helper ( cursor , delta_tbl_name ) return num_records , cp . duration
Function to populate the old blacklist.
Function to populate the old blacklist .
"""Function to populate the old blacklist.""" # First, generate a delta for any 'blocked' records (new adds) # noqa: Q449 # Next, generate a delta for any 'unblocked' records (new removals) (table direction flipped) # noqa: Q449 # Next, generate a delta for any 'changed' records
self
executor