在 Spark SQL 中编写 SQL 与使用数据帧 API [英] Writing SQL vs using Dataframe APIs in Spark SQL

查看:25
本文介绍了在 Spark SQL 中编写 SQL 与使用数据帧 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Spark SQL 世界中的一只新蜜蜂.我目前正在迁移我的应用程序的摄取代码,其中包括在 HDFS 中的 stage、Raw 和应用程序层中摄取数据并执行 CDC(更改数据捕获),这目前是在 Hive 查询中编写的,并通过 Oozie 执行.这需要迁移到 Spark 应用程序(当前版本 1.6).另一部分代码稍后会迁移.

I am a new bee in Spark SQL world. I am currently migrating my application's Ingestion code which includes ingesting data in stage,Raw and Application layer in HDFS and doing CDC(change data capture), this is currently written in Hive queries and is executed via Oozie. This needs to migrate into a Spark application(current version 1.6). The other section of code will migrate later on.

在 spark-SQL 中,我可以直接从 Hive 中的表创建数据帧,并按原样简单地执行查询(如 sqlContext.sql("my hive hql") ).另一种方法是使用数据帧 API 并以这种方式重写 hql.

In spark-SQL, I can create dataframes directly from tables in Hive and simply execute queries as it is (like sqlContext.sql("my hive hql") ). The other way would be to use dataframe APIs and rewrite the hql in that way.

这两种方法有什么区别?

What is the difference in these two approaches?

使用 Dataframe API 是否有任何性能提升?

Is there any performance gain with using Dataframe APIs?

有些人建议,当直接使用SQL"查询时,Spark 核心引擎必须经过额外的 SQL 层,这可能会在一定程度上影响性能,但我没有找到任何材料证实该声明.我知道使用 Datafrmae API 代码会更紧凑,但是当我的 hql 查询都方便时,是否真的值得将完整的代码写入 Dataframe API?

Some people suggested, there is an extra layer of SQL that spark core engine has to go through when using "SQL" queries directly which may impact performance to some extent but I didn't find any material substantiating that statement. I know the code would be much more compact with Datafrmae APIs but when I have my hql queries all handy would it really worth to write complete code into Dataframe API?

谢谢.

推荐答案

再添加几个.数据帧使用钨内存表示,sql 使用的催化剂优化器以及数据帧.与 SparkSQL 相比,使用 Dataset API 可以更好地控制实际执行计划

Couple more additions. Dataframe uses tungsten memory representation , catalyst optimizer used by sql as well as dataframe. With Dataset API, you have more control on the actual execution plan than with SparkSQL

这篇关于在 Spark SQL 中编写 SQL 与使用数据帧 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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