如何通过 Spark SQL 作为 JDBC 分布式查询引擎访问 RDD 表? [英] How to Access RDD Tables via Spark SQL as a JDBC Distributed Query Engine?

查看:19
本文介绍了如何通过 Spark SQL 作为 JDBC 分布式查询引擎访问 RDD 表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

stackoverflow 上的一些帖子有关于如何通过 Spark SQL 作为 JDBC 分布式查询引擎访问 RDD 表的部分信息的回复.因此,我想问以下问题以获取有关如何执行此操作的完整信息:

  1. 在 Spark SQL 应用中,我们是否需要使用 HiveContext 来注册表?或者我们可以只使用 SQL 上下文吗?

  2. 我们在哪里以及如何使用 HiveThriftServer2.startWithContext?

  3. 当我们像这样运行 start-thriftserver.sh

<块引用>

/opt/mapr/spark/spark-1.3.1/sbin/start-thriftserver.sh --master spark://spark-master:7077 --hiveconf hive.server2.thrift.bind.host spark-master--hiveconf hive.server2.trift.port 10001

除了指定 Spark SQL 应用的 jar 和 main 类,我们还需要指定其他参数吗?

  1. 我们还有什么需要做的吗?

谢谢.

解决方案

通过HiveThriftServer2.startWithContext()暴露DataFrame临时表,你可能需要编写和运行一个简单的应用程序,可能不需要运行 start-thriftserver.sh.

回答您的问题:

  1. HiveContext 是必需的;sqlContext 在 spark-shell 中隐式转换为 HiveContext

  2. 编写一个简单的应用程序,示例:

<前>导入 org.apache.spark.sql.hive.thriftserver._val hiveContext = new HiveContext(sparkContext)hiveContext.parquetFile(path).registerTempTable("my_table1")HiveThriftServer2.startWithContext(hiveContext)

  1. 无需运行 start-thriftserver.sh,而是运行您自己的应用程序,例如:

<块引用>

spark-submit --class com.xxx.MyJdbcApp ./package_with_my_app.jar

  1. 服务器端没有别的,应该在默认端口 10000 上启动;您可以通过直线连接到服务器进行验证.

Several postings on stackoverflow has responses with partial information about How to Access RDD Tables via Spark SQL as a JDBC Distributed Query Engine. So I'd like to ask the following questions for complete information about how to do that:

  1. In the Spark SQL app, do we need to use HiveContext to register tables? Or can we use just SQL Context?

  2. Where and how do we use HiveThriftServer2.startWithContext?

  3. When we run start-thriftserver.sh as in

/opt/mapr/spark/spark-1.3.1/sbin/start-thriftserver.sh --master spark://spark-master:7077 --hiveconf hive.server2.thrift.bind.host spark-master --hiveconf hive.server2.trift.port 10001

besides specifying the jar and main class of the Spark SQL app, do we need to specify any other parameters?

  1. Are there any other things we need to do?

Thanks.

解决方案

To expose DataFrame temp tables through HiveThriftServer2.startWithContext(), you may need to write and run a simple application, may not need to run start-thriftserver.sh.

To your questions:

  1. HiveContext is needed; the sqlContext converted to HiveContext implicitly in spark-shell

  2. Write a simple application, example :

    import  org.apache.spark.sql.hive.thriftserver._  
    val  hiveContext  =  new  HiveContext(sparkContext)
    hiveContext.parquetFile(path).registerTempTable("my_table1")
      HiveThriftServer2.startWithContext(hiveContext)

  1. No need to run start-thriftserver.sh, but run your own application instead, e.g.:

spark-submit --class com.xxx.MyJdbcApp ./package_with_my_app.jar

  1. Nothing else from server side, should start on default port 10000; you may verify by connecting to the server with beeline.

这篇关于如何通过 Spark SQL 作为 JDBC 分布式查询引擎访问 RDD 表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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