src/dirbs/listgen/generator.py
def _populate_new_pairings_imei_imsi_table(self, conn):
        """Function to populate the pairings list IMEI/IMSI temp table for this run."""
        with conn.cursor() as cursor, CodeProfiler() as cp:
            tblname = self._pairings_imei_imsi_new_tblname
            # Queries to generate is_valid and imei_norm_with_check_digit which do nothing if not required
            is_valid_query, imei_norm_with_check_digit_query = self._is_valid_and_check_digit_queries

            if self._restrict_exceptions_list:
                is_blacklisted_query = \
                    sql.SQL("""SELECT EXISTS (SELECT 1
                                                FROM {blacklist_tblname}
                                               WHERE imei_norm = pl.imei_norm
                                                 AND virt_imei_shard
                                                        = calc_virt_imei_shard(pl.imei_norm)) AS is_blacklisted
                            """).format(blacklist_tblname=sql.Identifier(self._blacklist_new_tblname))
            else:
                is_blacklisted_query = sql.SQL('SELECT NULL::BOOLEAN AS is_blacklisted')

            if not self._include_barred_imeis:
                is_barred_query = \
                    sql.SQL("""SELECT EXISTS (SELECT 1
                                                FROM barred_list
                                               WHERE imei_norm = pl.imei_norm
                                                 AND virt_imei_shard
                                                        = calc_virt_imei_shard(pl.imei_norm)) AS is_barred""")

                have_barred_tac_query = \
                    sql.SQL("""SELECT EXISTS (SELECT 1
                                                FROM barred_tac_list
                                               WHERE tac = LEFT(pl.imei_norm, 8)) AS have_barred_tac""")
            else:
                is_barred_query = sql.SQL('SELECT NULL::BOOLEAN AS is_barred')
                have_barred_tac_query = sql.SQL('SELECT NULL::BOOLEAN AS have_barred_tac')

            query = sql.SQL("""INSERT INTO {tblname}(imei_norm,
                                                     virt_imei_shard,
                                                     imsi,
                                                     is_valid,
                                                     imei_norm_with_check_digit,
                                                     home_operator,
                                                     is_blacklisted,
                                                     is_barred,
                                                     have_barred_tac,
                                                     msisdn)
                                    SELECT imei_norm,
                                           virt_imei_shard,
                                           imsi,
                                           is_valid,
                                           imei_norm_with_check_digit,
                                           operator_id,
                                           is_blacklisted,
                                           is_barred,
                                           have_barred_tac,
                                           msisdn
                                      FROM pairing_list pl,
                                           LATERAL ({is_valid_query}) is_valid_tbl,
                                           LATERAL ({imei_norm_with_check_digit_query}) check_digit_tbl,
                                           LATERAL ({is_blacklisted_query}) is_blacklisted_tbl,
                                           LATERAL ({is_barred_query}) is_barred_tbl,
                                           LATERAL ({have_barred_tac_query}) have_barred_tac_tbl
                                 LEFT JOIN LATERAL ({home_network_query}) home_network_tbl
                                           ON TRUE
                            """).format(tblname=sql.Identifier(tblname),
                                        is_valid_query=is_valid_query,
                                        imei_norm_with_check_digit_query=imei_norm_with_check_digit_query,
                                        is_blacklisted_query=is_blacklisted_query,
                                        is_barred_query=is_barred_query,
                                        have_barred_tac_query=have_barred_tac_query,
                                        home_network_query=self._home_network_query)

            cursor.execute(query)
            num_records = cursor.rowcount
            self._add_pk(conn, tblname=tblname, pk_columns=['imei_norm', 'imsi', 'msisdn'])
            self._analyze_helper(cursor, tblname)

        return num_records, cp.duration
Function to populate the pairings list IMEI/IMSI temp table for this run.
Function to populate the pairings list IMEI/IMSI temp table for this run.
Function to populate the pairings list IMEI / IMSI temp table for this run .
def _populate_new_pairings_imei_imsi_table(self, conn):
        with conn.cursor() as cursor, CodeProfiler() as cp:
            tblname = self._pairings_imei_imsi_new_tblname
            is_valid_query, imei_norm_with_check_digit_query = self._is_valid_and_check_digit_queries
            if self._restrict_exceptions_list:
                is_blacklisted_query = \
                    sql.SQL("""SELECT EXISTS (SELECT 1
                                                FROM {blacklist_tblname}
                                               WHERE imei_norm = pl.imei_norm
                                                 AND virt_imei_shard
                                                        = calc_virt_imei_shard(pl.imei_norm)) AS is_blacklisted
                            """).format(blacklist_tblname=sql.Identifier(self._blacklist_new_tblname))
            else:
                is_blacklisted_query = sql.SQL('SELECT NULL::BOOLEAN AS is_blacklisted')
            if not self._include_barred_imeis:
                is_barred_query = \
                    sql.SQL("""SELECT EXISTS (SELECT 1
                                                FROM barred_list
                                               WHERE imei_norm = pl.imei_norm
                                                 AND virt_imei_shard
                                                        = calc_virt_imei_shard(pl.imei_norm)) AS is_barred""")
                have_barred_tac_query = \
                    sql.SQL("""SELECT EXISTS (SELECT 1
                                                FROM barred_tac_list
                                               WHERE tac = LEFT(pl.imei_norm, 8)) AS have_barred_tac""")
            else:
                is_barred_query = sql.SQL('SELECT NULL::BOOLEAN AS is_barred')
                have_barred_tac_query = sql.SQL('SELECT NULL::BOOLEAN AS have_barred_tac')
            query = sql.SQL("""INSERT INTO {tblname}(imei_norm,
                                                     virt_imei_shard,
                                                     imsi,
                                                     is_valid,
                                                     imei_norm_with_check_digit,
                                                     home_operator,
                                                     is_blacklisted,
                                                     is_barred,
                                                     have_barred_tac,
                                                     msisdn)
                                    SELECT imei_norm,
                                           virt_imei_shard,
                                           imsi,
                                           is_valid,
                                           imei_norm_with_check_digit,
                                           operator_id,
                                           is_blacklisted,
                                           is_barred,
                                           have_barred_tac,
                                           msisdn
                                      FROM pairing_list pl,
                                           LATERAL ({is_valid_query}) is_valid_tbl,
                                           LATERAL ({imei_norm_with_check_digit_query}) check_digit_tbl,
                                           LATERAL ({is_blacklisted_query}) is_blacklisted_tbl,
                                           LATERAL ({is_barred_query}) is_barred_tbl,
                                           LATERAL ({have_barred_tac_query}) have_barred_tac_tbl
                                 LEFT JOIN LATERAL ({home_network_query}) home_network_tbl
                                           ON TRUE
                            """).format(tblname=sql.Identifier(tblname),
                                        is_valid_query=is_valid_query,
                                        imei_norm_with_check_digit_query=imei_norm_with_check_digit_query,
                                        is_blacklisted_query=is_blacklisted_query,
                                        is_barred_query=is_barred_query,
                                        have_barred_tac_query=have_barred_tac_query,
                                        home_network_query=self._home_network_query)
            cursor.execute(query)
            num_records = cursor.rowcount
            self._add_pk(conn, tblname=tblname, pk_columns=['imei_norm', 'imsi', 'msisdn'])
            self._analyze_helper(cursor, tblname)
        return num_records, cp.duration
def _populate_new_pairings_imei_imsi_table ( self , conn ) : with conn . cursor ( ) as cursor , CodeProfiler ( ) as cp : tblname = self . _pairings_imei_imsi_new_tblname is_valid_query , imei_norm_with_check_digit_query = self . _is_valid_and_check_digit_queries if self . _restrict_exceptions_list : is_blacklisted_query = sql . SQL ( """SELECT EXISTS (SELECT 1
                                                FROM {blacklist_tblname}
                                               WHERE imei_norm = pl.imei_norm
                                                 AND virt_imei_shard
                                                        = calc_virt_imei_shard(pl.imei_norm)) AS is_blacklisted
                            """ ) . format ( blacklist_tblname = sql . Identifier ( self . _blacklist_new_tblname ) ) else : is_blacklisted_query = sql . SQL ( 'SELECT NULL::BOOLEAN AS is_blacklisted' ) if not self . _include_barred_imeis : is_barred_query = sql . SQL ( """SELECT EXISTS (SELECT 1
                                                FROM barred_list
                                               WHERE imei_norm = pl.imei_norm
                                                 AND virt_imei_shard
                                                        = calc_virt_imei_shard(pl.imei_norm)) AS is_barred""" ) have_barred_tac_query = sql . SQL ( """SELECT EXISTS (SELECT 1
                                                FROM barred_tac_list
                                               WHERE tac = LEFT(pl.imei_norm, 8)) AS have_barred_tac""" ) else : is_barred_query = sql . SQL ( 'SELECT NULL::BOOLEAN AS is_barred' ) have_barred_tac_query = sql . SQL ( 'SELECT NULL::BOOLEAN AS have_barred_tac' ) query = sql . SQL ( """INSERT INTO {tblname}(imei_norm,
                                                     virt_imei_shard,
                                                     imsi,
                                                     is_valid,
                                                     imei_norm_with_check_digit,
                                                     home_operator,
                                                     is_blacklisted,
                                                     is_barred,
                                                     have_barred_tac,
                                                     msisdn)
                                    SELECT imei_norm,
                                           virt_imei_shard,
                                           imsi,
                                           is_valid,
                                           imei_norm_with_check_digit,
                                           operator_id,
                                           is_blacklisted,
                                           is_barred,
                                           have_barred_tac,
                                           msisdn
                                      FROM pairing_list pl,
                                           LATERAL ({is_valid_query}) is_valid_tbl,
                                           LATERAL ({imei_norm_with_check_digit_query}) check_digit_tbl,
                                           LATERAL ({is_blacklisted_query}) is_blacklisted_tbl,
                                           LATERAL ({is_barred_query}) is_barred_tbl,
                                           LATERAL ({have_barred_tac_query}) have_barred_tac_tbl
                                 LEFT JOIN LATERAL ({home_network_query}) home_network_tbl
                                           ON TRUE
                            """ ) . format ( tblname = sql . Identifier ( tblname ) , is_valid_query = is_valid_query , imei_norm_with_check_digit_query = imei_norm_with_check_digit_query , is_blacklisted_query = is_blacklisted_query , is_barred_query = is_barred_query , have_barred_tac_query = have_barred_tac_query , home_network_query = self . _home_network_query ) cursor . execute ( query ) num_records = cursor . rowcount self . _add_pk ( conn , tblname = tblname , pk_columns = [ 'imei_norm' , 'imsi' , 'msisdn' ] ) self . _analyze_helper ( cursor , tblname ) return num_records , cp . duration
Function to populate the pairings list IMEI/IMSI temp table for this run.
Function to populate the pairings list IMEI / IMSI temp table for this run .
"""Function to populate the pairings list IMEI/IMSI temp table for this run.""" # Queries to generate is_valid and imei_norm_with_check_digit which do nothing if not required
self
conn