【发布时间】:2016-08-17 06:55:40
【问题描述】:
我是 Spark Echo 系统的新手,我尝试将数据从 CSV 写入镶木地板,但因 NullPointerException 而失败。不知道我错过了什么。
case class PdRecordData(id: String, dates: String, dayOfWeek: String, pdDistrict: String,address: String, longitude: String, latitude: String)
val sqlContext = new SQLContext(sc)
sqlContext.createParquetFile[PdRecordData]("C:\\AS\\Parquet", true, new Configuration()).registerTempTable("PdRegistry")
val csvFile = sc.textFile("C:\\AS\\crimeratedata\\samplefromorg.csv")
val rowsWithHeader = csvFile.map { x => x.split(",").map { _.trim } }
val maps = rowsWithHeader.map { case Array(id,dates, dayOfWeek, pdDistrict, address, longitude, latitude) => PdRecordData(id,dates, dayOfWeek, pdDistrict, address, longitude, latitude) }
maps.foreach { x => sqlContext.sql("INSERT INTO PdRegistry SELECT " + "'" + x.dates + "','" + x.dayOfWeek + "','" + x.pdDistrict + "','" + x.address + "','" + x.longitude + "','" + x.latitude + "'")}
抛出以下异常。
java.lang.NullPointerException
at org.apache.spark.sql.SQLConf$class.getConf(SQLConf.scala:175)
at org.apache.spark.sql.SQLContext.getConf(SQLContext.scala:50)
at org.apache.spark.sql.SQLConf$class.dialect(SQLConf.scala:85)
at org.apache.spark.sql.SQLContext.dialect(SQLContext.scala:50)
at org.apache.spark.sql.SQLContext.sql(SQLContext.scala:302)
【问题讨论】:
-
我做的一件事是使用 [Apache Drill][1] 从 CSV 创建我的 parquet 文件,然后通过 Spark SQL 在 Apache Spark 作业中使用 parquet 文件。使用 Apache Drill 将 CSV 加载到 Parquet 文件非常简单。 [1]:drill.apache.org
标签: scala apache-spark apache-spark-sql parquet