def filter_sql_query(log):
    """Extract SQL statements from log"""
    sqls = []
    in_sql = False

    for q in log:
        if 'sqlalchemy.engine.base.Engine' in q:
            # Remove '2017-11-22 15:17:14,810 INFO [sqlalchemy.engine.base.Engine] '
            q = q[61:].strip()
            sqls.append(q)
            in_sql = True
        elif in_sql and not q.startswith('2017-'):
            # Rest of previous SQL query: append to previous sql
            sqls[-1] = sqls[-1] + ' ' + q.strip()
        else:
            in_sql = False

    return sqls