def parse_annotated_query()

in src/redash_stmo/query_runner/big_query.py [0:0]


def parse_annotated_query(query):
    """
    Parses the given query for the annotation that Redash left
    there when before running the job.

    E.g. a query that has the annotation on top::

        /* Task ID: 8ccd40c878f59fa69ccf31a72140b208, Query Hash: f6bf37efedbc0a2dfffc1caf5088d86e, Query ID: 12345, Queue: default, Username: jezdez */

        SELECT * FROM users;

    will lead to returning::

        {
            'Query Hash': 'f6bf37efedbc0a2dfffc1caf5088d86e',
            'Query ID': '12345',
            'Queue': 'default',
            'Task ID': '8ccd40c878f59fa69ccf31a72140b208',
            'Username': 'jezdez',
        }

    which we can use as labels when submitting the BigQuery job.
    """
    if not query or "/*" not in query:
        return {}
    match = ANNOTATION_RE.match(query.strip())
    if not match:
        return {}
    # Split by comma and colons to create a key/value dict of query annotations
    return dict(
        map(lambda s: (x.strip() for x in s.split(":")), match.group(1).split(","))
    )