How to use the datalab.utils.commands.get_notebook_item function in datalab

To help you get started, we’ve selected a few datalab examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googledatalab / pydatalab / datalab / bigquery / commands / _bigquery.py View on Github external
def _get_table(name):
  """ Given a variable or table name, get a Table if it exists.

  Args:
    name: the name of the Table or a variable referencing the Table.
  Returns:
    The Table, if found.
  """
  # If name is a variable referencing a table, use that.
  item = datalab.utils.commands.get_notebook_item(name)
  if isinstance(item, datalab.bigquery.Table):
    return item
  # Else treat this as a BQ table name and return the (cached) table if it exists.
  try:
    return _table_cache[name]
  except KeyError:
    table = datalab.bigquery.Table(name)
    if table.exists():
      _table_cache[name] = table
      return table
  return None