在 Hive 上执行 Spark SQL 查询 [英] Spark SQL query execution on Hive

查看:83
本文介绍了在 Hive 上执行 Spark SQL 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Spark SQL 的新手,但知道 hive 查询执行框架.我想了解spark是如何执行sql查询的(技术说明)?

I am new to Spark SQL but aware of hive query execution framework. I would like to understand how does spark executes sql queries (technical description) ?

如果我在命令下面开火

val sqlContext = new org.apache.spark.sql.hive.HiveContext(sc)
sqlContext.sql("select count(distinct(id)) from test.emp").collect

在 Hive 中它将被转换为 Map-Reduce 作业,但它如何在 Spark 中执行?

In Hive it will be converted into Map-Reduce job but how it gets executed in Spark?

hive Metastore 将如何出现?

How hive metastore will come into picture?

提前致谢.

推荐答案

简单回答你的问题:不,HiveContext 不会启动 MR 作业.您的 SQL 查询仍将使用 Spark 引擎

To answer you question briefly: No, HiveContext will not start MR job. Your SQL query will still use the spark engine

我将从 spark 文档中引用:

I will quote from the spark documentation:

除了基本的 SQLContext 之外,您还可以创建一个 HiveContext,它提供了基本 SQLContext 提供的功能的超集.其他功能包括使用更完整的 HiveQL 解析器编写查询的能力、访问 Hive UDF 以及从 Hive 表读取数据的能力.要使用 HiveContext,您不需要具有现有的 Hive 设置,并且 SQLContext 可用的所有数据源仍然可用.HiveContext 仅单独打包以避免在默认 Spark 构建中包含 Hive 的所有依赖项.如果这些依赖关系对您的应用程序来说不是问题,那么建议在 Spark 1.3 版本中使用 HiveContext.未来的版本将专注于将 SQLContext 提升到与 HiveContext 相同的特性

In addition to the basic SQLContext, you can also create a HiveContext, which provides a superset of the functionality provided by the basic SQLContext. Additional features include the ability to write queries using the more complete HiveQL parser, access to Hive UDFs, and the ability to read data from Hive tables. To use a HiveContext, you do not need to have an existing Hive setup, and all of the data sources available to a SQLContext are still available. HiveContext is only packaged separately to avoid including all of Hive’s dependencies in the default Spark build. If these dependencies are not a problem for your application then using HiveContext is recommended for the 1.3 release of Spark. Future releases will focus on bringing SQLContext up to feature parity with a HiveContext

因此,Spark 使用 HiveContext 来增强对现有 Hive 表的查询解析和访问,甚至可以持久化您的结果 DataFrames/Tables.而且实际上,Hive 可以使用 Spark 作为其执行引擎,而不是使用 MR 或 tez.

So The HiveContext is used by spark to enhance the query parsing and accessing to existing Hive tables, and even to persist your result DataFrames / Tables. Actually, moreover, Hive could use Spark as its execution engine instead of using MR or tez.

Hive Metastore 是关于 Hive 表的元数据.当使用 HiveContext spark 时,可以使用这个 Metastore 服务.请参阅文档:http://spark.apache.org/docs/最新/sql-programming-guide.html

Hive metastore is a metadata about Hive tables. And when using HiveContext spark could use this metastore service. Refer to the documentation: http://spark.apache.org/docs/latest/sql-programming-guide.html

这篇关于在 Hive 上执行 Spark SQL 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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