Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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