src/dirbs/importer/operator_data_importer.py
def _update_network_imeis(self, src_partition, virt_imei_shard_start, virt_imei_shard_end):
        """Helper function to update the network_imeis table."""
        dest_partition = partition_utils.imei_shard_name(base_name='network_imeis',
                                                         virt_imei_range_start=virt_imei_shard_start,
                                                         virt_imei_range_end=virt_imei_shard_end)
        with create_db_connection(self._db_config) as conn, conn.cursor() as cursor:
            query = """INSERT INTO {0} AS target (first_seen, last_seen, seen_rat_bitmask,
                                                            virt_imei_shard, imei_norm)
                            SELECT MIN(connection_date),
                                   MAX(connection_date),
                                   bit_or(1 << rat_map.operator_rank),
                                   calc_virt_imei_shard(imei_norm),
                                   imei_norm
                              FROM (SELECT imei_norm,
                                           connection_date,
                                           regexp_split_to_table(COALESCE(rat_norm, ''), '\|') AS rat_code
                                      FROM {1}) exploded_rat
                         LEFT JOIN radio_access_technology_map rat_map
                             USING (rat_code)
                             WHERE imei_norm IS NOT NULL
                          GROUP BY imei_norm
                                   ON CONFLICT (imei_norm)
                                   DO UPDATE
                                         SET first_seen = LEAST(excluded.first_seen, target.first_seen),
                                             last_seen = GREATEST(excluded.last_seen, target.last_seen),
                                             seen_rat_bitmask = target.seen_rat_bitmask | excluded.seen_rat_bitmask
                                       WHERE excluded.first_seen < target.first_seen
                                          OR excluded.last_seen > target.last_seen
                                          OR (target.seen_rat_bitmask | excluded.seen_rat_bitmask)
                                                   != target.seen_rat_bitmask"""  # noqa: Q441, Q447, W605

            cursor.execute(sql.SQL(query).format(sql.Identifier(dest_partition), sql.Identifier(src_partition)))
Helper function to update the network_imeis table.
Helper function to update the network_imeis table.
Helper function to update the network_imeis table .
def _update_network_imeis(self, src_partition, virt_imei_shard_start, virt_imei_shard_end):
        dest_partition = partition_utils.imei_shard_name(base_name='network_imeis',
                                                         virt_imei_range_start=virt_imei_shard_start,
                                                         virt_imei_range_end=virt_imei_shard_end)
        with create_db_connection(self._db_config) as conn, conn.cursor() as cursor:
            query = """INSERT INTO {0} AS target (first_seen, last_seen, seen_rat_bitmask,
                                                            virt_imei_shard, imei_norm)
                            SELECT MIN(connection_date),
                                   MAX(connection_date),
                                   bit_or(1 << rat_map.operator_rank),
                                   calc_virt_imei_shard(imei_norm),
                                   imei_norm
                              FROM (SELECT imei_norm,
                                           connection_date,
                                           regexp_split_to_table(COALESCE(rat_norm, ''), '\|') AS rat_code
                                      FROM {1}) exploded_rat
                         LEFT JOIN radio_access_technology_map rat_map
                             USING (rat_code)
                             WHERE imei_norm IS NOT NULL
                          GROUP BY imei_norm
                                   ON CONFLICT (imei_norm)
                                   DO UPDATE
                                         SET first_seen = LEAST(excluded.first_seen, target.first_seen),
                                             last_seen = GREATEST(excluded.last_seen, target.last_seen),
                                             seen_rat_bitmask = target.seen_rat_bitmask | excluded.seen_rat_bitmask
                                       WHERE excluded.first_seen < target.first_seen
                                          OR excluded.last_seen > target.last_seen
                                          OR (target.seen_rat_bitmask | excluded.seen_rat_bitmask)
                                                   != target.seen_rat_bitmask"""  
            cursor.execute(sql.SQL(query).format(sql.Identifier(dest_partition), sql.Identifier(src_partition)))
def _update_network_imeis ( self , src_partition , virt_imei_shard_start , virt_imei_shard_end ) : dest_partition = partition_utils . imei_shard_name ( base_name = 'network_imeis' , virt_imei_range_start = virt_imei_shard_start , virt_imei_range_end = virt_imei_shard_end ) with create_db_connection ( self . _db_config ) as conn , conn . cursor ( ) as cursor : query = """INSERT INTO {0} AS target (first_seen, last_seen, seen_rat_bitmask,
                                                            virt_imei_shard, imei_norm)
                            SELECT MIN(connection_date),
                                   MAX(connection_date),
                                   bit_or(1 << rat_map.operator_rank),
                                   calc_virt_imei_shard(imei_norm),
                                   imei_norm
                              FROM (SELECT imei_norm,
                                           connection_date,
                                           regexp_split_to_table(COALESCE(rat_norm, ''), '\|') AS rat_code
                                      FROM {1}) exploded_rat
                         LEFT JOIN radio_access_technology_map rat_map
                             USING (rat_code)
                             WHERE imei_norm IS NOT NULL
                          GROUP BY imei_norm
                                   ON CONFLICT (imei_norm)
                                   DO UPDATE
                                         SET first_seen = LEAST(excluded.first_seen, target.first_seen),
                                             last_seen = GREATEST(excluded.last_seen, target.last_seen),
                                             seen_rat_bitmask = target.seen_rat_bitmask | excluded.seen_rat_bitmask
                                       WHERE excluded.first_seen < target.first_seen
                                          OR excluded.last_seen > target.last_seen
                                          OR (target.seen_rat_bitmask | excluded.seen_rat_bitmask)
                                                   != target.seen_rat_bitmask""" cursor . execute ( sql . SQL ( query ) . format ( sql . Identifier ( dest_partition ) , sql . Identifier ( src_partition ) ) )
Helper function to update the network_imeis table.
Helper function to update the network_imeis table .
"""Helper function to update the network_imeis table.""" # noqa: Q441, Q447, W605
self
src_partition
virt_imei_shard_start
virt_imei_shard_end