spark将rdd写入文件,由于字段太多,无法写入
解决办法,将rdd中的字段转成对象,再输出
case class RefuceCodeResult(
ID:String,
TOTAL:Int,
CS_D1:Double,
CS_D4:Double,
CS_D5:Double,
ZS_D1:Double,
ZS_D2:Double,
ZS_D3:Double,
ZS_D4:Double,
ZS_D5:Double,
ZS_D6:Double,
ZS_D7:Double,
ZS_D8:Double,
ZS_D9:Double,
XS_T1:Double,
XS_T2:Double,
YBR_D1:Double,
YBR_D3:Double,
YBR_D4:Double,
YBR_D5:Double,
YBR_D6:Double,
FQZ_A01:Double,
FQZ_A02:Double,
FQZ_A03:Double,
FQZ_A04:Double,
FQZ_A05:Double,
FQZ_A06:Double,
FQZ_A07:Double,
FQZ_A08:Double,
FQZ_A09:Double,
FQZ_A10:Double
) extends Product {
override def productArity = 31 //字段总数
override def canEqual(that: Any) = that.isInstanceOf[this.type]
override def productElement(n: Int): Any = n match {
case 0 => ID: String
case 1 => TOTAL: Int
case 2 => CS_D1: Double
case 3 => CS_D4: Double
case 4 => CS_D5: Double
case 5 => ZS_D1: Double
case 6 => ZS_D2: Double
case 7 => ZS_D3: Double
case 8 => ZS_D4: Double
case 9 => ZS_D5: Double
case 10 => ZS_D6: Double
case 11 => ZS_D7: Double
case 12 => ZS_D8: Double
case 13 => ZS_D9: Double
case 14 => XS_T1: Double
case 15 => XS_T2: Double
case 16 => YBR_D1: Double
case 17 => YBR_D3: Double
case 18 => YBR_D4: Double
case 19 => YBR_D5: Double
case 20 => YBR_D6: Double
case 21 => FQZ_A01: Double
case 22 => FQZ_A02: Double
case 23 => FQZ_A03: Double
case 24 => FQZ_A04: Double
case 25 => FQZ_A05: Double
case 26 => FQZ_A06: Double
case 27 => FQZ_A07: Double
case 28 => FQZ_A08: Double
case 29 => FQZ_A09: Double
case 30 => FQZ_A10: Double
}
}
val intopices_oneHop_refuceCode_rdd = intopices_oneHop_refuceCode_group.map( s =>
RefuceCodeResult
(s._1, intopice_oneHopIntopices_size_bc.value.get(s._1).get,
s._2.get("CS_D1").get, s._2.get("CS_D4").get, s._2.get("CS_D5").get,
s._2.get("ZS_D1").get, s._2.get("ZS_D2").get, s._2.get("ZS_D3").get, s._2.get("ZS_D4").get, s._2.get("ZS_D5").get, s._2.get("ZS_D6").get, s._2.get("ZS_D7").get, s._2.get("ZS_D8").get, s._2.get("ZS_D9").get,
s._2.get("XS_T1").get, s._2.get("XS_T2").get,
formatDouble(s._2.get("YBR_D1").get, 2), formatDouble(s._2.get("YBR_D3").get, 2), formatDouble(s._2.get("YBR_D4").get, 2), formatDouble(s._2.get("YBR_D5").get, 2), formatDouble(s._2.get("YBR_D6").get, 2),
s._2.get("FQZ_A01").get, s._2.get("FQZ_A02").get, s._2.get("FQZ_A03").get, s._2.get("FQZ_A04").get, s._2.get("FQZ_A05").get, s._2.get("FQZ_A06").get, s._2.get("FQZ_A07").get, s._2.get("FQZ_A08").get, s._2.get("FQZ_A09").get, s._2.get("FQZ_A10").get
)
).map(s=>s.toString)
val intopices_oneHop_refuceCode_all = intopices_oneHop_refuceCode_rdd.map(s=>{
val start = s.indexOf("(")+1
val end = s.indexOf(")")
s.substring(start,end)
})
intopices_oneHop_refuceCode_all.coalesce(16).saveAsTextFile("file:///opt/refuce_code_new/intopices_oneHop_refuceCode_highrelations_"+startDay+endDay)