我有一個Spark SQL將我的S3 JSON文件讀入DataFrame中。Spark SQL read.json讀取JSON輸入兩次
然後我在該DataFrame上運行2個SQL,並在執行每個SQL之前發現SparkSQL讀取我的S3 JSON文件兩次。
如果數據框對象不被重用,這將是非常昂貴的...
任何幫助表示讚賞。
這裏是我的代碼片段:
protected boolean doAggregations() throws IOException {
SQLContext sqlContext = getSQLContext();
DataFrame edgeDataFrame = sqlContext.read().json(sourceDataDirectory);
edgeDataFrame.cache();
getLogger().info("Registering and caching the table 'edgeData'");
edgeDataFrame.registerTempTable("edgeData");
String dateKey = DateTimeUtility.SECOND_FORMATTER.print(System.currentTimeMillis());
for (Map.Entry<String, AggregationMetadata> entry : aggMetadataMap.entrySet()) {
String aggName = entry.getKey();
String resultDir = getAggregationResultDirectory(aggName, dateKey);
String sql = entry.getValue().getSql();
// The input file(s) are being read again and again instead of operating on the "edgeDataFrame"
DataFrame dataFrame = sqlContext.sql(sql);
dataFrame.write().format("json").save(resultDir);
}
return true;
}