3

I am new to spark and going through the data frame operations.

As per given in documentation of Apache Spark registerTempTable and createTempView looks similar a lot.

Can anyone tell what exactly is the difference between the registerTempTable and createTempView?

Thanks

Akash Sethi
  • 2,284
  • 1
  • 20
  • 40

2 Answers2

1

The registerTempTable method has been deprecated in spark 2.0.0+ and it internally calls createOrReplaceTempView. Dataset object-

 private[sql] object Dataset {

 /**
   * Registers this Dataset 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 Dataset.
   *
   * @group basic
   * @since 1.6.0
   */
  @deprecated("Use createOrReplaceTempView(viewName) instead.", "2.0.0")
  def registerTempTable(tableName: String): Unit = {
    createOrReplaceTempView(tableName)
  }

............
}
Rahul Sharma
  • 5,614
  • 10
  • 57
  • 91
1

Below is the description of the both.

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. The 
lifetime of this temporary table is tied to the SparkSession that was used to create this Dataset. 

enter image description here

From the image you can see registerTempTable is deprecated in Spark 2.0. Means registerTempTable was the feature prior to Spark 2.0.

Ishan Kumar
  • 1,941
  • 3
  • 20
  • 29