Я пытаюсь понять, как работает датафрейм. Я использую Spark 2+. Я хотел прочитать файл и передать порядок файлов для объединения с таблицей.
Размер файла небольшой, а таблица большая - размер данных почти 18 терабайт.
Не могли бы вы помочь мне понять, что происходит:
1. file1.txt: fixed length file and wanted to read based on positions.
12345xxx67890xxxxx564
56789xxx11111xxxxx555
2. Read file to dataframe:
Created spark session named as 'spark'
df_file = spark.read.text('file1.txt')
df_file: [Row(value=u'12345xxx67890xxxxx564'), Row(value=u'56789xxx11111xxxxx555')]
Question1: I understand Dataframe is List of Rows, but what is this value?
3. Question2: There is no map function on dataframe. How to iterate through each row of dataframe?
4. So, I convert Dataframe to RDD.
rdd1 = spark.read.text('file1.txt').rdd
rdd1: [Row(value=u'12345xxx67890xxxxx564'), Row(value=u'56789xxx11111xxxxx555')]
5. Using map retrieve values:
rdd1 = spark.read.text('file1.txt').rdd.map(lambda row: (row.value))
rdd1<pyspark.rdd.PipelinedRDD>: [u'12345xxx67890xxxxx564', u'56789xxx11111xxxxx555']
Question3: If the file size is equal or less than block size, will the entire file content be read by a single RDD. And if its large the file will be processed across many RDD's?
6. Now get the value I am interested in based on position:
rdd1 = spark.read.text('file1.txt').rdd.map(lambda row: (row.value)).map(lambda row: (row[:5],row[9:19]))
rdd1<pyspark.rdd.PipelinedRDD>: [(u'12345',u'67890'), (u'56789',u'11111')]
7. I will have to attach schema and convert to dataframe back.
Question4: Is there a better way to deal with this.
Спасибо.