code: def _get_query_argument(args, cell, env):
    
    sql_arg = args.get('query', None)
    if sql_arg is None:
      # Assume we have inline SQL in the cell
      if not isinstance(cell, basestring):
        raise Exception('Expected a --query argument or inline SQL')
      return datalab.bigquery.Query(cell, values=env)
  
    item = datalab.utils.commands.get_notebook_item(sql_arg)
    if isinstance(item, datalab.bigquery.Query):  # Queries are already expanded.
      return item
  
    # Create an expanded BQ Query.
    config = datalab.utils.commands.parse_config(cell, env)
    item, env = datalab.data.SqlModule.get_sql_statement_with_environment(item, config)
    if cell:
      env.update(config)  # config is both a fallback and an override.
    return datalab.bigquery.Query(item, values=env)
docs: Get a query argument to a cell magic.
  
    The query is specified with args['query']. We look that up and if it is a BQ query
    just return it. If it is instead a SqlModule or SqlStatement it may have variable
    references. We resolve those using the arg parser for the SqlModule, then override
    the resulting defaults with either the Python code in cell, or the dictionary in
    overrides. The latter is for if the overrides are specified with YAML or JSON and
    eventually we should eliminate code in favor of this.
  
    Args:
      args: the dictionary of magic arguments.
      cell: the cell contents which can be variable value overrides (if args has a 'query'
          value) or inline SQL otherwise.
      env: a dictionary that is used for looking up variable values.
    Returns:
      A Query object.