if args["mode"] == "create":
if table.exists():
raise Exception("table %s already exists; use "append" or "overwrite" as mode." % name)
if not cell_body or "schema" not in cell_body:
raise Exception("Table does not exist, and no schema specified in cell; cannot load.")
env = google.datalab.utils.commands.notebook_environment()
config = google.datalab.utils.commands.parse_config(cell_body, env, False)
schema = config["schema"]
// schema can be an instance of google.datalab.bigquery.Schema.
// For example, user can run "my_schema = bq.Schema.from_data(df)" in a previous cell and
// specify "schema: $my_schema" in cell input.
if not isinstance(schema, google.datalab.bigquery.Schema):
jsonschema.validate(config, table_schema_schema)
schema = google.datalab.bigquery.Schema(schema)
table.create(schema=schema)
elif not table.exists():
raise Exception("table %s does not exist; use "create" as mode." % name)