<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def from_bigquery(sql):
 """Create a Metrics instance from a bigquery query or table. Returns: a Metrics instance. Args: sql: A BigQuery table name or a query. """


    if isinstance(sql, bq.Query):
      sql = sql._expanded_sql()

    parts = sql.split('.')
    if len(parts) == 1 or len(parts) > 3 or any(' ' in x for x in parts):
      sql = '(' + sql + ')'  # query, not a table name
    else:
      sql = '`' + sql + '`'  # table name

    metrics = Metrics(bigquery=sql)
    return metrics