Spark SQL读取hive数据时报找不到mysql驱动
Exception:
Caused by: org.datanucleus.exceptions.NucleusException: Attempt to invoke the "BoneCP" plugin to create a ConnectionPool gave an error : The specified datastore driver ("com.mysql.jdbc.Driver") was not found in the CLASSPATH. Please check your CLASSPATH specification, and the name of the driver.
Solution:
1、$HIVE_HOME/conf/hive-site.xml中增加关于 hive.metastore.uris 的配置信息,如下:
<property>
<name>hive.metastore.uris</name>
<value>thrift://namenode1:9083</value>
<description>IP address (or fully-qualified domain name) and port of the metastore host</description>
</property> 2、执行:$HIVE_HOME/bin/hive --service metastore,启动元数据存储服务; 3、将$HIVE_HOME/conf/hive-site.xml拷贝至$SPARK_HOME/conf/目录下; 4、启动spark-shell进行验证:$SPARK_HOME/bin/spark-shell --master namenode1:7077或spark-sql -> show databases. Note:
1. 当在Intellij IDE中编写Spark SQL程序时(val hiveContext = new HiveContext(sc); import hiveContext.sql; sql("show databases")),打包成相应的.jar文件,并利用如下脚本将任务提交到Spark集群运行时,Spark默认采用derby进行metastore,即元数据的存储;当再次在不同目录下执行该任务时,之前创建的数据库或表数据无法获取,有点即用即删的感觉。故要想访问Hive下的元数据,首先需要将Hive目录下的配置文件中的hive-site.xml文件放到Spark目录下的配置文件中,让Spark集群执行程序时能识别进入Hive元数据的路径,然后启动上述服务(hive --service metastore)即可访问Hive相应数据。 2.
/**
* An instance of the Spark SQL execution engine that integrates with data stored in Hive.
* Configuration for Hive is read from hive-site.xml on the classpath.
*/
class HiveContext(sc: SparkContext) extends SQLContext(sc) { .................................... }
3.
Use HiveContext instead. It will still create a local metastore if one is not specified. However, note that the default directory is ./metastore_db, not ./metastore
测试程序如下:
package com.husor.Hive import org.apache.spark.{SparkContext, SparkConf}
import org.apache.spark.sql.hive.HiveContext /* Spark SQL执行时的sql是临时的,即用即删 **/ /**
* Created by kelvin on 2015/1/27.
*/
object Recommendation {
def main(args: Array[String]) { println("Test is starting......") if (args.length < ) {
System.err.println("Usage:HDFS_OutputDir <Directory>")
System.exit()
} //System.setProperty("hadoop.home.dir", "d:\\winutil\\") val conf = new SparkConf().setAppName("Recommendation")
val spark = new SparkContext(conf) val hiveContext = new HiveContext(spark) import hiveContext.sql /*sql("create database if not exists baby")
val databases = sql("show databases")
databases.collect.foreach(println)*/ sql("use baby")
/*sql("CREATE EXTERNAL TABLE if not exists origin_orders (oid string, uid INT, gmt_create INT) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' LOCATION '/beibei/order'")
sql("CREATE EXTERNAL TABLE if not exists items (iid INT, pid INT, title string, cid INT, brand INT) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' LOCATION '/beibei/item'")
sql("CREATE EXTERNAL TABLE if not exists order_item (oid string, iid INT) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' LOCATION '/beibei/order_item'")
sql("create table if not exists test_orders(oid string, uid INT, gmt_create INT)")
sql("create table if not exists verify_orders(oid string, uid INT, gmt_create INT)")
sql("insert OVERWRITE table test_orders select * from origin_orders where gmt_create <= 1415635200")
sql("insert OVERWRITE table verify_orders select * from origin_orders where gmt_create > 1415635200") val tables = sql("show tables")
tables.collect.foreach(println)*/ sql("SET spark.sql.shuffle.partitions = 5") val olderTime = System.currentTimeMillis() val userOrderData = sql("select i.pid, o.uid, o.gmt_create from items i " +
"join order_item oi " +
"on i.iid = oi.iid " +
"join test_orders o " +
"on oi.oid = o.oid") userOrderData.take().foreach(println) val newTime = System.currentTimeMillis() println("Consume Time: " + (newTime - olderTime)) userOrderData.saveAsTextFile(args())
spark.stop() println("Test is Succeed!!!") } }
Spark SQL读取hive数据时报找不到mysql驱动的更多相关文章
- spark sql 访问hive数据时找不mysql的解决方法
我尝试着在classpath中加n入mysql的驱动仍不行 解决方法:在启动的时候加入参数--driver-class中加入mysql 驱动 [hadoop@master spark-1.0.1-bi ...
- Spark SQL 操作Hive 数据
Spark 2.0以前版本:val sparkConf = new SparkConf().setAppName("soyo") val spark = new SparkC ...
- Spark教程——(10)Spark SQL读取Phoenix数据本地执行计算
添加配置文件 phoenixConnectMode.scala : package statistics.benefits import org.apache.hadoop.conf.Configur ...
- Spark SQL读取Oracle的number类型的数据时精度丢失问题
Spark SQL读取数据Oracle的数据时,发现number类型的字段在读取的时候精度丢失了,使用的spark版本是Spark2.1.0的版本,竟然最后经过排查和网上查资料发现是一个bug.在Sp ...
- Spark sql 在yarn-cluster模式下找不到表
在hive里建一个数据库test,在数据库里建了一张表user,然后在Spark程序中使用Spark sql读取这张表 "select * form test.user" 当部署模 ...
- spark SQL读取ORC文件从Driver启动到开始执行Task(或stage)间隔时间太长(计算Partition时间太长)且产出orc单个文件中stripe个数太多问题解决方案
1.背景: 控制上游文件个数每天7000个,每个文件大小小于256M,50亿条+,orc格式.查看每个文件的stripe个数,500个左右,查询命令:hdfs fsck viewfs://hadoop ...
- spark2.3.0 配置spark sql 操作hive
spark可以通过读取hive的元数据来兼容hive,读取hive的表数据,然后在spark引擎中进行sql统计分析,从而,通过spark sql与hive结合实现数据分析将成为一种最佳实践.配置步骤 ...
- spark sql数据源--hive
使用的是idea编辑器 spark sql从hive中读取数据的步骤:1.引入hive的jar包 2.将hive-site.xml放到resource下 3.spark sql声明对hive的支持 案 ...
- Spark SQL with Hive
前一篇文章是Spark SQL的入门篇Spark SQL初探,介绍了一些基础知识和API,可是离我们的日常使用还似乎差了一步之遥. 终结Shark的利用有2个: 1.和Spark程序的集成有诸多限制 ...
随机推荐
- F4 help for month
INCLUDE rmcs0f0m. s_month FOR s001-spmon NO-EXTENSION NO INTERVALS OBLIGATORY. AT SELECTION-SCREEN O ...
- Poiji:基于列名绑定方式将Excel单元行转换为JavaBean的开源框架
公司的日常事务中经常需要使用excel进行数据汇总,导入导出进行归类统计分析. 因为没有广泛流行的单元行到类转换/属性绑定工具,在功能开发之初或者很长一段时间内, 业务系统中我们处理普通excel数据 ...
- 最短路径(SP)问题相关算法与模板
相关概念: 有向图.无向图:有向图的边是双行道,无向图的边是单行道.在处理无向图时,可以把一条无向边看做方向相反的两条有向边. 圈 cycle / 回路 circuit:在相同顶点上开始并结束且长度大 ...
- 2018php最新面试题之PHP核心技术
一.PHP核心技术 1.写出一个能创建多级目录的PHP函数(新浪网技术部) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 <?php ...
- linux就该这么学,第十一天了
今天讲了,网卡绑,定,两块网卡同时工作,自动备源,理论上速度提升一倍,工作中可以用到的技术 还有sshd服务,端口22,远程连接使用,还可以设置root是否可以直接登录,主要配置文件在,/etc/ss ...
- vue中的import、export、requre的区别
在es6之前js一直没有自己的模块语法,为了解决这种尴尬就有了require.js的出现.在es6发布之后js又引入了import的概念使得不清楚两者之间的区别的同学在实际使用过程中造成了自己的误解, ...
- mysql的innodb和myisam的区别和应用场景
1. 区别: (1)事务处理: MyISAM是非事务安全型的,而InnoDB是事务安全型的(支持事务处理等高级处理): (2)锁机制不同: MyISAM是表级锁,而InnoDB是行级锁: (3)sel ...
- 学习blinker
from blinker import signal do_sth = signal('do_sth') #创建信号 def process(f, a, b, **kwargs): f(a, b, * ...
- centos7配置Hadoop集群环境
参考: https://blog.csdn.net/pucao_cug/article/details/71698903 设置免密登陆后,必须重启ssh服务 systermctl restart ss ...
- Unity3D中声音播放
Unity3D 播放声音需要使用 Audio Source 组件,并且需要 Audio Listener 组件配合,不然无法听到声音.Main Camera 会默认有 Audio Lisetener. ...