createTable

基于数据源中的数据集创建表。

Syntax

createTable(tableName: str, path: str = None, source: str = None, schema: StructType = None, description: str = None, **options: str)

参数

参数 类型 Description
tableName str 要创建的表的名称。 可以使用目录名称进行限定。
path str,可选 此表的数据所在的路径。 指定时 path ,将从给定路径处的数据创建外部表。 否则会创建托管表。
source str,可选 此表的源,例如 'parquet''orc'等等。如果未 source 指定,将使用由 spark.sql.sources.default 其配置的默认数据源。
schema StructType自选 此表的架构。
description str,可选 此表的说明。
**options dict,可选 在表中指定的额外选项。

退货

DataFrame

与表关联的 DataFrame。

示例

# 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")