在spark streaming 過程中遇到數據不對的地方,最有check 到時我們RDD到dataframe 出現了問題
rowRdd = rdd.flatMap(build_data_row) statsRdd = rowRdd.map(map_to_id) dfstats = sqlContext.createDataFrame(statsRdd, schema=docShema)
上面的程序中map_to_id 這個function 盡管return Row(.......) 但是在sqlContext.createDataFrame 中出現數據跟預期的不一樣的情況最后從spark 的文檔發現, RDD ==> DataFrame 中要指定schema, 或者sampleRatio 的, 如果沒有指定的話,可能出現數據的錯亂
尤其是在table 字段很多的情況下.
PS:
data – an RDD of Row/tuple/list/dict, list, or pandas.DataFrameschema – a StructType or list of names of columnssamplingRatio – the sample ratio of rows used for inferring
新聞熱點
疑難解答