尽管使用 SQLContext 实例定义,但无法解析导入 sqlContext
import sqlContext cannot be resolved although defined with SQLContext instance
我遵循了 中的解决方案,但是,我仍然收到“无法解析符号 SQLContext”错误。 ".implicits._" 也无法解析。会是什么原因呢?
Spark/Scala 我使用的版本:
- Scala 2.12.13
- Spark 3.0.1(没有捆绑的 Hadoop)
这是我的相关代码部分:
import org.apache.log4j.LogManager
import org.apache.spark.{SparkConf, SparkContext}
object Count {
def main(args: Array[String]) {
...
...
val sc = new SparkContext(conf)
val sqlContext = new SQLContext(sc)
import sqlContext.implicits._
}}
您根本没有导入 SQLContext
:
import org.apache.spark.sql.SQLContext
你可能一开始就不再使用 SQLContext
:
As of Spark 2.0, this is replaced by SparkSession. However, we are keeping the class here for backward compatibility.
https://spark.apache.org/docs/latest/api/scala/org/apache/spark/sql/SQLContext.html
查看如何在 使用 SparkContext
的 SparkSession
,然后在 import sparkSession.implicits._
。
我遵循了
Spark/Scala 我使用的版本:
- Scala 2.12.13
- Spark 3.0.1(没有捆绑的 Hadoop)
这是我的相关代码部分:
import org.apache.log4j.LogManager
import org.apache.spark.{SparkConf, SparkContext}
object Count {
def main(args: Array[String]) {
...
...
val sc = new SparkContext(conf)
val sqlContext = new SQLContext(sc)
import sqlContext.implicits._
}}
您根本没有导入 SQLContext
:
import org.apache.spark.sql.SQLContext
你可能一开始就不再使用 SQLContext
:
As of Spark 2.0, this is replaced by SparkSession. However, we are keeping the class here for backward compatibility.
https://spark.apache.org/docs/latest/api/scala/org/apache/spark/sql/SQLContext.html
查看如何在 SparkContext
的 SparkSession
,然后在 import sparkSession.implicits._
。