创建 SQLContext 对象时,构造函数 HiveContext(JavaSparkContext) 未定义错误

The constructor HiveContext(JavaSparkContext) is undefined error while create SQLContext object

我正在尝试使用 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>

spark_hive 不应该依赖 Spark 2.2 吗?

<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>

如果您使用 Spark 2.2,我认为 HiveContext 已被弃用,您应该只使用 SparkSession 作为查询和计算的入口点:

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.