【发布时间】:2018-10-05 12:11:00
【问题描述】:
我正在尝试将一个简单的文本文件读入 Spark RDD,我发现有两种方法:
from pyspark.sql import SparkSession
spark = SparkSession.builder.master("local[*]").getOrCreate()
sc = spark.sparkContext
textRDD1 = sc.textFile("hobbit.txt")
textRDD2 = spark.read.text('hobbit.txt').rdd
然后我查看数据,发现两个 RDD 的结构不同
textRDD1.take(5)
['The king beneath the mountain',
'The king of carven stone',
'The lord of silver fountain',
'Shall come unto his own',
'His throne shall be upholden']
textRDD2.take(5)
[Row(value='The king beneath the mountain'),
Row(value='The king of carven stone'),
Row(value='The lord of silver fountain'),
Row(value='Shall come unto his own'),
Row(value='His throne shall be upholden')]
基于此,必须更改所有后续处理以反映“值”的存在
我的问题是
- 使用这两种读取文本文件的方式意味着什么?
- 什么情况下应该使用哪种方法?
【问题讨论】:
标签: apache-spark rdd