分享

spark编程,使用java开发调用spark的执行hive的sql查询或insert操作

aurae 发表于 2016-4-22 16:59:49 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 2 11540
我pom.xml中引用了[mw_shl_code=applescript,true]<dependency>
                        <groupId>org.apache.spark</groupId>
                        <artifactId>spark-core_2.10</artifactId>
                        <version>1.6.1</version>
                </dependency>
                <dependency>
                        <groupId>org.apache.spark</groupId>
                        <artifactId>spark-sql_2.10</artifactId>
                        <version>1.6.1</version>
                </dependency>
                <dependency>
                        <groupId>org.apache.hadoop</groupId>
                        <artifactId>hadoop-client</artifactId>
                        <version>2.7.1</version>
                </dependency>[/mw_shl_code]

然后java代码中写了如下代码:
[mw_shl_code=applescript,true]public static void main(String[] args) {
                String appName = "Spark Test";
                String master = "yarn";
                SparkConf conf = new SparkConf().setAppName(appName).setMaster(master);
                JavaSparkContext sc = new JavaSparkContext(conf);
                HiveContext sqlContext = new org.apache.spark.sql.hive.HiveContext(sc.sc);
        }[/mw_shl_code]

其中的org.apache.spark.sql.hive.HiveContext没有这个class文件呀,这个jar该去哪找?
有没有java方面的在spark中调用执行hive的sql的demo?
谢谢大神~!

已有(2)人评论

跳转到指定楼层
s060403072 发表于 2016-4-22 19:40:05
导入HiveContext

scala> val hiveContext = new org.apache.spark.sql.hive.HiveContext(sc)
hiveContext: org.apache.spark.sql.hive.HiveContext = org.apache.spark.sql.hive.HiveContext@7766d31c

scala> import hiveContext._
import hiveContext._

回复

使用道具 举报

aurae 发表于 2016-4-26 09:55:14
s060403072 发表于 2016-4-22 19:40
导入HiveContext

scala> val hiveContext = new org.apache.spark.sql.hive.HiveContext(sc)

我想问一下java的代码,不是scala的。然后引jar都需要引用什么jar呢,比如可以提供一个maven的pom代码吗?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条