在Spark会话中设置 “table”。

huangapple go评论61阅读模式
英文:

Set "table" in spark session

问题

You can set salaryData as a table in a SparkSession using the createOrReplaceTempView method like this:

salaryData.createOrReplaceTempView("salaries")

After this, you can fetch it from the SparkSession as you mentioned:

val salaryDataframeFromSession = spark.table("salaries")

This will allow you to access the salaryData DataFrame as a table named "salaries" within your SparkSession.

英文:

In some spark/scala code (I cannot link the source) I see a dataframe being created like this:

val someDataFrame = spark.table("dataframeName")

where spark is a SparkSession. How can I set a table in the spark session? i.e. if I have a frame like this:

 val salaryData = Seq(("James", "Sales", 3000),
    ("Michael", "Sales", 4600),
    ("Robert", "Sales", 4100),
    ("Maria", "Finance", 3000),
    ("James", "Sales", 3000),
  )
  val salaryData = simpleData.toDF("employee_name", "department", "salary")

how can I set salaryData as a table in a SparkSession and fetch it like this:

val salaryDataframeFromSession = spark.table("salaries")

答案1

得分: 0

我成功解决了这个问题,通过以下代码:

salaryData.createOrReplaceTempView("salaries")
英文:

I was able to solve this via

salaryData.createOrReplaceTempView("salaries")

huangapple
  • 本文由 发表于 2023年6月29日 09:55:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76577628.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定