Support Questions
Find answers, ask questions, and share your expertise
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Error while running hive support on Spark

Error while running hive support on Spark


Hello i am trying use Hive with spark but when i try executing, it shows this error

Exception in thread "main" java.lang.IllegalArgumentException: Unable to instantiate SparkSession with Hive support because Hive classes are not found.

This is my source code


package com.spark.hiveconnect


import org.apache.spark.sql.{Row, SaveMode, SparkSession}

object sourceToHIve {
case class Record(key: Int, value: String)
def main(args: Array[String]){
val warehouseLocation = new File("spark-warehouse").getAbsolutePath

val spark = SparkSession
.appName("Spark Hive Example")
.config("spark.sql.warehouse.dir", warehouseLocation)

import spark.implicits._
import spark.sql

sql("CREATE TABLE IF NOT EXISTS src (key INT, value STRING) USING hive")
sql("LOAD DATA LOCAL INPATH '/usr/local/spark3/examples/src/main/resources/kv1.txt' INTO TABLE src")
sql("SELECT * FROM src").show()



 This is my build.sbt file.

name := "SparkHive"

version := "0.1"

scalaVersion := "2.12.10"

libraryDependencies += "org.apache.spark" %% "spark-core" % "2.4.5"
libraryDependencies += "org.apache.spark" %% "spark-sql" % "2.4.5"

And i also have hive running in the console.

Can anyone help me with this?

Thank You.

Don't have an account?
Coming from Hortonworks? Activate your account here