Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between createOrReplaceTempView and registerTempTable

I am new to spark and was trying out a few commands in sparkSql using python when I came across these two commands:

createOrReplaceTempView() and registerTempTable().

What is the difference between the two commands?. They seem to have same set of functionalities.

like image 820
Amogh Huilgol Avatar asked Jul 17 '17 13:07

Amogh Huilgol


People also ask

What is the difference between createOrReplaceTempView and Createglobaltempview?

createOrReplaceTempView has been introduced in Spark 2.0 to replace registerTempTable. CreateTempView creates an in-memory reference to the Dataframe in use. The lifetime for this depends on the spark session in which the Dataframe was created in.

What is createOrReplaceTempView?

createorreplacetempview is used when you desire to store the table for a specific spark session. createorreplacetempview creates (or replaces if that view name already exists) a lazily evaluated "view" that you can then use like a hive table in Spark SQL.

What is registerTempTable in spark?

registerTempTable (name)[source] Registers this DataFrame as a temporary table using the given name. The lifetime of this temporary table is tied to the SparkSession that was used to create this DataFrame . New in version 1.3. 0.

What is createTempView?

def createTempView(viewName: String): Unit Creates a local temporary view using the given name. The lifetime of this temporary view is tied to the SparkSession that was used to create this Dataset def registerTempTable(tableName: String): Unit Registers this Dataset as a temporary table using the given name.


2 Answers

registerTempTable is a part of the 1.x API and has been deprecated in Spark 2.0.

createOrReplaceTempView and createTempView have been introduced in Spark 2.0, as a replacement for registerTempTable.

Other than that registerTempTable and createOrReplaceTempView functionally equivalent and the former one calls the latter one.

like image 91
zero323 Avatar answered Sep 26 '22 00:09

zero323


No difference at all between createOrReplaceTempView and registerTempTable both performs the same functionality and if you open the below link and search for registerTempTable you can see that this function is deprecated in 2.0.

There is a note like below: Deprecated in 2.0 use createOrReplaceTempView instead.

https://spark.apache.org/docs/2.0.0/api/python/pyspark.sql.html

like image 43
Ankit Kumar Namdeo Avatar answered Sep 24 '22 00:09

Ankit Kumar Namdeo