sparksql連線hive中出現的錯誤

2021-09-12 02:42:34 字數 1231 閱讀 6831

解決方案:mysql的jar包不匹配,所以從hive中cp mysql.jar 進到spark的jars中

package com.cmd.spark

import org.apache.spark.sparkconf

import org.apache.spark.sql.

val hivecontext = sparksession.builder().config(conf).enablehivesupport().getorcreate()

// //3.建立hive表

val createsql = 「create table if not exists t_student(id int,name string) row format delimited fields terminated by 『,』」

hivecontext.sql(createsql)

//4.載入資料

val loaddata = 「load data local inpath 『/student.log』 into table t_student」

hivecontext.sql(loaddata)

//5.獲取hive中的資料.放入sparksql中dataframe

val df:dataframe = hivecontext.sql(「select * from t_student」)

//6.處理 求出

val resultd2 = df.where(「id>2」)

的dlf風格。

resultd2.createorreplacetempview(「result01」)

hivecontext.sql(「create table if not exists tmp_student as select * from result01」)}}

打包

配置環境。把hive的配置檔案賦值到spark配置檔案中。
cp hive-site.xml

/usr/spark/spark-2.1.1-bin-hadoop2.7/conf/

hive.metastore.schema.verification false

提交到集群:

spark-submit --master [local/spark/yarn] --class /jar包

Spark SQL操作Hive實戰

在目前企業級 spark大資料開發中,大多數情況下都是採用hive來作為資料倉儲的。spark提供了對hive的支援,spark通過hivecontext可以直接操作hive中的資料。基於hivecontext,我們可以使用sql hql兩種方式來編寫sql語句 對hive進行操作,包括 建立表 刪...

Hive與SparkSQL別名中的區別

先上 select vid,from unixtime gpsdate,yyyy mm dd hh mm ss as time from xx where pdt 2020 01 01 and vid 010019410390 order by gpsdate limit 10 一行簡單的 沒啥毛病...

Spark sql與Hive的關係

spark sql 在某些部分是重用的hive的東西,比如語法解析 元資料儲存,到執行計畫的翻譯部分。hiveql可以翻譯成mapreduce執行,也可以翻譯成spark執行計畫執行。在同時安裝了hive和spark時,我使用hive下的beeline執行hql,執行引擎是mapreuce 使用sp...