import json


def get_all_topic_id_and_meta(client):
    """
    Execute query to return meta dict for all topics.
    This information should take from 'meta' measurement in the InfluxDB database.

    :param client: InfluxDB client connected in historian_setup method.
    :return: a dictionary that maps topic_id to its actual topic name and
             a dictionary that maps each topic to its metadata
    """

    topic_id_map = {}
    meta_dicts = {}

    query = 'SELECT topic, meta_dict, topic_id FROM meta'
    rs = client.query(query)
    rs = list(rs.get_points())

    for point in rs:
        topic_id_map[point['topic_id']] = point['topic']
        meta = point['meta_dict'].replace("u'", "\"").replace("'", "\"")
        meta_dicts[point['topic_id']] = json.loads(meta)

    return topic_id_map, meta_dicts