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

查看:280
本文介绍了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')

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

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天全站免登陆