【发布时间】:2016-07-07 16:50:16
【问题描述】:
我正在使用以下命令将 parquet 文件写入 hdfs:
df.write.mode(SaveMode.Append).partitionBy(id).parquet(path)
之后我会像这样读取和过滤文件:
val file = sqlContext.read.parquet(folder)
val data = file.map(r => Row(r.getInt(4).toString, r.getString(0), r.getInt(1),
r.getLong(2), r.getString(3)))
val filteredData = data.filter(x => x.thingId.equals("1"))
filteredData.collect()
我希望,Spark 将利用文件的分区并且只读取“thingId = 1”的分区。 事实上,Spark 确实读取了文件的所有分区,而不仅仅是过滤后的分区(thingId=1 的分区)。 如果我查看日志,我可以看到它确实读取了所有内容:
16/03/21 01:32:33 INFO ParquetRelation:从以下位置读取 Parquet 文件 hdfs://sandbox.hortonworks.com/path/id=1/part-r-00000-b4e27b02-9a21-4915-89a7-189c30ca3fe3.gz.parquet 21 年 16 月 3 日 01:32:33 信息 ParquetRelation:从 hdfs://sandbox.hortonworks.com/path/id=42/part-r-00000-b4e27b02-9a21-4915-89a7-189c30ca3fe3.gz.parquet 21 年 16 月 3 日 01:32:33 信息 ParquetRelation:从 hdfs://sandbox.hortonworks.com/path/id=17/part-r-00000-b4e27b02-9a21-4915-89a7-189c30ca3fe3.gz.parquet 21 年 16 月 3 日 01:32:33 信息 ParquetRelation:从 hdfs://sandbox.hortonworks.com/path/0833/id=33/part-r-00000-b4e27b02-9a21-4915-89a7-189c30ca3fe3.gz.parquet 21 年 16 月 3 日 01:32:33 信息 ParquetRelation:从 hdfs://sandbox.hortonworks.com/path/id=26/part-r-00000-b4e27b02-9a21-4915-89a7-189c30ca3fe3.gz.parquet 21 年 16 月 3 日 01:32:33 信息 ParquetRelation:从 hdfs://sandbox.hortonworks.com/path/id=12/part-r-00000-b4e27b02-9a21-4915-89a7-189c30ca3fe3.gz.parquet
我有什么遗漏吗?当我查看文档时,Spark 应该知道基于过滤器,它应该只读取带有 thingID=1 的分区。 有没有人知道问题出在哪里?
【问题讨论】:
标签: hadoop apache-spark hdfs parquet bigdata