createTable
Creates a table based on the dataset in a data source.
Syntax
createTable(tableName: str, path: str = None, source: str = None, schema: StructType = None, description: str = None, **options: str)
Parameters
Parameter | Type | Description |
|---|---|---|
| str | Name of the table to create. Can be qualified with catalog name. |
| str, optional | The path in which the data for this table exists. When |
| str, optional | The source of this table such as |
|
| The schema for this table. |
| str, optional | The description of this table. |
| dict, optional | Extra options to specify in the table. |
Returns
DataFrame
The DataFrame associated with the table.
Examples
Python
# Creating a managed table.
_ = spark.catalog.createTable("tbl1", schema=spark.range(1).schema, source='parquet')
_ = spark.sql("DROP TABLE tbl1")
# Creating an external table.
import tempfile
with tempfile.TemporaryDirectory(prefix="createTable") as d:
_ = spark.catalog.createTable(
"tbl2", schema=spark.range(1).schema, path=d, source='parquet')
_ = spark.sql("DROP TABLE tbl2")