Apache Spark中`registerTempTable`和`createTempView`之间的区别

时间:2017-10-05 04:48:16

标签: apache-spark apache-spark-sql

我是新手,通过数据框操作。

根据Apache Spark registerTempTablecreateTempView的文档中给出的内容看起来很相似。

任何人都可以说出registerTempTablecreateTempView之间究竟有什么区别吗?

由于

2 个答案:

答案 0 :(得分:1)

已在spark 2.0.0+中弃用registerTempTable方法,并在内部调用createOrReplaceTempViewDataset对象 -

 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)
  }

............
}

答案 1 :(得分:1)

下面是两者的描述。

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

从图像中可以看到在Spark 2.0中不推荐使用registerTempTable。表示registerTempTable是Spark 2.0之前的功能。