标签:index ring ram dataframe length frame 类型转换 map class
1 //将dataframe类型转换为hashmap 2 def getDFToMap(dimenDF: DataFrame, dimenKey: String, dimenValue: String): util.HashMap[String, String] = { 3 val dimenMap: util.HashMap[String, String] = new util.HashMap[String, String] 4 val arrayDF = dimenDF.rdd.collect() 5 for (i <- 0 to arrayDF.size - 1) { 6 val each = arrayDF(i) 7 val keyIndex = each.fieldIndex(dimenKey) 8 val key = each.get(keyIndex) 9 if (key != null) { 10 val array = dimenValue.split(",") 11 var values: String = "" 12 for (i <- 0 to array.length - 1) { 13 val valueIndex = each.fieldIndex(array(i)) 14 val value = each.get(valueIndex) 15 var fieldValue: String = "null" 16 if (value != null) { 17 fieldValue = value.toString 18 } 19 if (i == array.length - 1) { 20 values = values + fieldValue 21 } else { 22 values = values + fieldValue + "," 23 } 24 } 25 if (values.endsWith(",")) { 26 values = values + " " 27 } 28 dimenMap.put(key.toString, values) 29 } 30 } 31 dimenMap 32 }
标签:index ring ram dataframe length frame 类型转换 map class
原文地址:https://www.cnblogs.com/wall-eve/p/10161407.html