代碼實現
// rdd轉化為df[kv格式]
val df = sqlContext.createDataFrame(check_data_type, structType) .select("cons_no", "org_no")
.distinct // 去重 .rdd .map(row => (row.getAs[String]("cons_no"), row.getAs[String]("org_no"))) .collect()// 數據量較少 .toMap[String, String] // 模式匹配 val value = df.get("2019") match{ case Some(a) => a // 提取出數據 case None => "" } println(value)