我有一个大约 1 GB 的 Parquet 文件。每个数据记录都是来自 IOT 设备的读数,它捕获设备在过去一分钟内消耗的能量。
架构:houseId、deviceId、能源
Parquet 文件根据 houseId 和 deviceId 进行分区。一个文件只包含过去 24 小时的数据。
我想使用 Spark SQL 对驻留在此 Parquet 文件中的数据执行一些查询示例查询找出给定房屋在过去 24 小时内每台设备消耗的平均能源。
Dataset<Row> df4 = ss.read().parquet("/readings.parquet");
df4.as(encoder).registerTempTable("deviceReadings");
ss.sql("Select avg(energy) from deviceReadings where houseId=3123).show();
上面的代码运行良好。我想了解 spark 如何执行此查询。
最佳答案
Does Spark read the whole Parquet file in memory from HDFS without looking at the query?
它不应该扫描所有数据文件,但通常可以访问所有文件的元数据。
Does Spark load only the required partitions from HDFS as per the query?
是的,它确实。
Does Spark load only the required partitions from HDFS as per the query?
它不是。每个查询都有自己的执行计划。
Will it make a difference in execution time if I cache df4 dataframe above?
是的,至少现在,它会有所作为 - Caching dataframes while keeping partitions
关于apache-spark - Spark SQL 如何读取 Parquet 分区文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49992952/