spark.sql 与 SqlContext [英] spark.sql vs SqlContext

查看:33
本文介绍了spark.sql 与 SqlContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have used SQL in Spark, in this example:

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

其中ventas是一个数据框,以前像表格一样编目:

where ventas is a dataframe, previosuly cataloged like a table:

df.createOrReplaceTempView('ventas')

但我已经看到在 Spark 中使用 SQL 的其他方法,使用类 SqlContext:

but I have seen other ways of working with SQL in Spark, using the class SqlContext:

df = sqlContext.sql("SELECT * FROM table")

两者有什么区别?

提前致谢

推荐答案

Sparksession 现在是使用 Spark 对象的首选方式.Hivecontext 和 SQLContext 都可以作为这个单一对象 SparkSession 的一部分使用.

Sparksession is the preferred way of working with Spark object now. Both Hivecontext and SQLContext are available as a part of this single object SparkSession.

您正在通过创建视图 df.createOrReplaceTempView('ventas') 来使用最新语法.

You are using the latest syntax by creating a view df.createOrReplaceTempView('ventas').

这篇关于spark.sql 与 SqlContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆