0

我正在尝试使用 JavaSparkContext 对象创建 SQL 上下文对象,因为它的参数如下:

SparkConf sparkConf=new SparkConf().setMaster("local").setAppName("Example");
JavaSparkContext sc=new JavaSparkContext(sparkConf);
SQLContext sqlctx=new HiveContext(sc);

Eclipse 抛出一个错误说:

The constructor HiveContext(JavaSparkContext) is undefined

但是我在互联网上查找的所有示例,包括文档都使用 JavaSparkContext 作为参数。我错过了什么吗?

Maven依赖:

<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-hive_2.10</artifactId>
<version>1.2.0</version>
<scope>provided</scope>
</dependency>
4

1 回答 1

1

Shouldn't you have Spark 2.2 dependency for spark_hive ?

<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-hive_2.10</artifactId>
<version>2.2.0</version>
<scope>provided</scope>
</dependency>

And if you use Spark 2.2, HiveContext is deprecated I think, you should just only use SparkSession as the entry point for queries and computations :

Upgrading From Spark SQL 1.6 to 2.0

SparkSession is now the new entry point of Spark that replaces the old SQLContext and HiveContext. Note that the old SQLContext and HiveContext are kept for backward compatibility. A new catalog interface is accessible from SparkSession - existing API on databases and tables access such as listTables, createExternalTable, dropTempView, cacheTable are moved here.

于 2017-09-01T15:09:13.580 回答