2015-08-17 38 views
1

我使用spark從s3讀取文件,然後將其加載到數據框,然後嘗試將它寫入hdfs作爲拼花。 問題是,當文件很大(65G)時,出於某種原因,我的內存不足......無論如何,我不知道爲什麼我的內存不足,因爲它看起來像數據分區很好。Spark DataFrame另存爲拼接 - 內存不足

這是我的代碼sampel:

val records = gzCsvFile.filter { x => x.length == 31 }.map { x => 

    var d:Date = Date.valueOf(x(0)) 

     //var z = new GregorianCalendar();z.getWeekYear 

    var week = (1900+d.getYear)* 1000 + d.getMonth()*10 + Math.ceil(d.getDate()/7.0).toInt 
    Row(d, Timestamp.valueOf(x(1)), toLong(x(2)), toLong(x(3)), toLong(x(4)), toLong(x(5)), toLong(x(6)), toLong(x(7)), toLong(x(8)), toLong(x(9)), toLong(x(10)), toLong(x(11)), toLong(x(12)), toLong(x(13)), toLong(x(14)), toLong(x(15)), toLong(x(16)), toLong(x(17)), toLong(x(18)), toLong(x(19)), toLong(x(20)), toLong(x(21)), toLong(x(22)), toLong(x(23)), toLong(x(24)), toLong(x(25)), x(26).trim(), toLong(x(27)), toLong(x(28)), toLong(x(29)), toInt(x(30)), week) 
} 
var cubeDF = sqlContext.createDataFrame(records, cubeSchema) 
cubeDF.write.mode(SaveMode.Overwrite).partitionBy("CREATION_DATE","COUNTRY_ID","CHANNEL_ID").parquet(cubeParquetUrl) 

沒有任何人有任何想法是怎麼回事?

+0

65GB不是很大 - 您爲執行程序分配了多少內存? –

+0

約20GB。 請記住,現在我正在紗線下進行測試。 – user1960555

+1

這可能是因爲單個拼花文件需要更多的內存(壓縮之前)。我經常看到臨時階段比原始文件大小需要更多的內存 –

回答

1

你打這個錯誤:寫入輸出出來的時候https://issues.apache.org/jira/browse/SPARK-8890

木地板的內存消耗比我們想象的大得多。在即將發佈的Spark 1.5中,爲了減少內存消耗,我們在寫入大量實木複合分區之前轉而對數據進行排序。