I have a very simple application that is trying to read an orc file from /src/main/resources using spark. I keep getting this error:
Unable to instantiate SparkSession with Hive support because Hive classes are not found.
I have tried adding the dependency
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-hive_2.11</artifactId>
<version>2.0.0</version>
</dependency>
as recommended here: Unable to instantiate SparkSession with Hive support because Hive classes are not found
however, no matter what I have added, I still get this error.
I am running this on my local windows machine through NetBeans IDE.
my code:
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SparkSession;
import org.apache.spark.sql.*;
public class Main {
public static void main(String[] args) {
SparkSession spark = SparkSession
.builder()
.enableHiveSupport()
.appName("Java Spark SQL basic example")
.getOrCreate();
Dataset<Row> df = spark.read().orc("/src/main/resources/testdir");
spark.close();
}
}
If you are running in IDE, I recommend to use .master("local") in you SparkSession object.
Next important point is that the version of spark-hive should match with spark-core and spark-sql versions. for safety you can define dependency as
<properties>
<spark.version>2.0.0</spark.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>${spark.version}</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.11</artifactId>
<version>${spark.version}</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-hive_2.11</artifactId>
<version>${spark.version}</version>
</dependency>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With