import re


def parse_ksql_query(query):
    """Read the parameters of the provided KSQL query.

    Args:
        query (str): the query given as string.

    Returns:
        (str, str, str, str): a tuple that contains: the name of the table, the name of
            the column that holds the metrics value, the name of the column that is used
            for comparison with the metric name, and the name to compare to.

    """
    query_pattern = "SELECT (\\w+) FROM (\\w+) WHERE (\\w+) *= *'(.+)';"
    match_group = re.match(query_pattern, query, re.IGNORECASE)

    assert match_group is not None, f"The query {query!r} has an invalid format."
    value_column, table, comparison_column, metric_name = match_group.groups()

    message = (
        "The column for the metric names and the one for the metrics values"
        " cannot be the same."
    )
    assert value_column != comparison_column, message

    return table, value_column, comparison_column, metric_name