pyspark.sql.DataFrame.createTempView¶
-
DataFrame.
createTempView
(name)[source]¶ Creates a local temporary view with this
DataFrame
.The lifetime of this temporary table is tied to the
SparkSession
that was used to create thisDataFrame
. throwsTempTableAlreadyExistsException
, if the view name already exists in the catalog.New in version 2.0.0.
Examples
>>> df.createTempView("people") >>> df2 = spark.sql("select * from people") >>> sorted(df.collect()) == sorted(df2.collect()) True >>> df.createTempView("people") Traceback (most recent call last): ... AnalysisException: u"Temporary table 'people' already exists;" >>> spark.catalog.dropTempView("people")