windows上spark shell读取本地文件

作者: yimengtianya1 | 来源:发表于2019-06-17 20:18 被阅读6次

1、windows上spark shell读取本地文件时,需要在文件地址前加“file:///”
2、文本文件的后缀要有。
3、由于不知道默认读取位置,因此建议使用绝对路径。

如读取本地文件HelloSpark.txt:

    scala> val lines = sc.textFile("file:///C:/spark-2.4.3-bin-hadoop2.7/data/testfile/HelloSpark.txt")

    scala>  val lines = sc.textFile("file:///C:/spark-2.4.3-bin-hadoop2.7/data/testfile/HelloSpark.txt")
    lines: org.apache.spark.rdd.RDD[String] = file:///C:/spark-2.4.3-bin-hadoop2.7/data/testfile/HelloSpark.txt MapPartitionsRDD[15] at textFile at <console>:24

    scala> lines.first()
    res6: String = testfile

    scala> lines.count()
    res7: Long = 3

相关文章

网友评论

    本文标题:windows上spark shell读取本地文件

    本文链接:https://www.haomeiwen.com/subject/angzfctx.html