我試圖將值插入Hive表中,並且如果每列都有值,則沒有問題,但我需要在其中一列中插入NULL值。 我做這種事兒:將NULL值插入Hive with Spark中的dataFrame
val errorsToAlert = List(("source1", "table1","27-01-2002", null))
val data = sqlContext.createDataFrame(errorsToAlert).toDF("source",
"table_name", "open_date", "close_date")
data.write.mode("append").saveAsTable("management.alerts")
我試過用NULL和無,但都代表這個錯誤:
17/06/26 11:59:38 ERROR yarn.ApplicationMaster: User class threw exception:
scala.MatchError: scala.None.type (of class scala.reflect.internal.Types$UniqueSingleType)
scala.MatchError: scala.None.type (of class scala.reflect.internal.Types$UniqueSingleType)
那是因爲你只有一排數據與close_date爲null,其處理作爲None類型而不是StringType。您必須顯式定義模式,或者在close_date列中添加另一個非空值的行。 –