Spark dataFrame没有createGlobalTempView()函数?

时间:2018-10-24 02:13:24

标签: scala apache-spark dataframe

我正在使用spark2.3和scala 2.11。

  1. 我创建了dataFrame,可以使用createOrReplaceTempView()函数。
  2. 但是似乎createGlobalTempView()函数丢失了,intellij说它找不到这种方法,而intellisense也无法给我列表。

所以我想知道这种方法是否过时了(兼容性问题?)

谢谢!

1 个答案:

答案 0 :(得分:1)

createGlobalTempView()也可以使用ApiDoucment的功能。 这是sourceCode近3115行。
给您一个演示来处理您的数据。

val spark = SparkSession.
  builder.
  appName("Simple Application").
  master("local").
  getOrCreate()

val df = spark.read.json("my.json")
// Register the DataFrame as a SQL temporary view

df.createOrReplaceTempView("people1")//:people

val sqlDF = spark.sql("SELECT * FROM people1 ")

println("createOrReplaceTempView")

sqlDF.show()

// Register the DataFrame as a global temporary view
df.createGlobalTempView("people2")

// Global temporary view is tied to a system preserved database `global_temp`

val sqlDF2 = spark.sql("SELECT * FROM global_temp.people2")

sqlDF2.show()