gpt4 book ai didi

apache-spark - spark.sql 与 SqlContext

转载 作者:行者123 更新时间:2023-12-03 23:15:29 25 4
gpt4 key购买 nike

我在 Spark 中使用了 SQL,在这个例子中:

results = spark.sql("select * from ventas")

其中ventas是一个数据框,以前像表格一样编目:
df.createOrReplaceTempView('ventas')

但我已经看到使用类 SqlContext 在 Spark 中使用 SQL 的其他方法:
df = sqlContext.sql("SELECT * FROM table")

它们之间有什么区别?

提前致谢

最佳答案

从用户的角度(不是贡献者),我只能重新讨论开发人员在升级说明中提供的内容:

Upgrading From Spark SQL 1.6 to 2.0

  • SparkSession is now the new entry point of Spark that replaces the old SQLContext and HiveContext. Note that the old SQLContext and HiveContext are kept for backward compatibility. A new catalog interface is accessible from SparkSession - existing API on databases and tables access such as listTables, createExternalTable, dropTempView, cacheTable are moved here.


在 2.0 之前, SqlContext需要额外调用创建它的工厂。与 SparkSession ,他们使事情变得更加方便。

如果您查看源代码,您会注意到 SqlContext类大多被标记 @deprecated .仔细检查发现,最常用的方法只是调用 sparkSession .

有关更多信息,请查看开发人员说明、Jira 问题、关于 spark 2.0 的 session 演讲和 Databricks 博客。

关于apache-spark - spark.sql 与 SqlContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51813274/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com