简体   繁体   English

sc.textFile Scala错误

[英]sc.textFile scala error

I am trying to read a file from a path that I've written a file at. 我正在尝试从写入文件的路径读取文件。 I am following the documentation so I am using the following line of code: 我正在关注文档,因此我在使用以下代码行:

 val data = sc.textFile(PATH)

This give a compilation error: not found: value sc. 这给出了编译错误:找不到:值sc。

I found solutions that involve commands that should be given in terminal, but in my case I am using eclipse. 我找到了涉及应在终端中给出的命令的解决方案,但就我而言,我正在使用eclipse。 Is there a way to resolve this issue by importing a library or something like this? 是否可以通过导入库或类似的方法来解决此问题?

thank you! 谢谢!

You need to create the spark context first. 您需要首先创建spark上下文。

For example: 例如:

val conf = new SparkConf().setAppName(appName).setMaster(master)
val sc = new SparkContext(conf)

When you are using the Spark shell there is no need to create the spark context, because it is already created for you, in the variable called sc. 使用Spark Shell时,无需创建spark上下文,因为已经为您创建了spark上下文,该变量名为sc。

You can read more about the spark context initialization there . 您可以在此处了解有关spark上下文初始化的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM