我是 spark 新手,并试图将数据帧写入 db2 表。我得到的错误是:Exception in thread "main" java.lang.IllegalArgumentException: Can't get JDBC type for struct <data:int, day:int, hours:int, minutes:int, month:int, seconds:int, time:bigint, timeZoneOffset:int, year:int>我的数据库架构是localId <-- Integer typeeffectiveDate <-- TimestampactivityDate <-- TimestampinDate <-- TimestampoutDate <-- Timestamp我为我的 db 表创建了一个 POJO 类,如下所示public class StowageTable { private long localId; private Date effectiveDate; private Date activityDate; private Date inDate; private Date outDate; //setters and getters}然后,我基本上读取了一个与 db 表具有相同架构的 csv,如下所示:JavaRDD<String> dataFromCSV = javaSparkContext.textFile(fileURL);//The I create a JavaRDD of the POJO typeJavaRDD<StowageTable> dataToPOJO = dataFromCSV.map((Function<String, StowageTable) line -> { String[] fields = line.split(","); StowageTable st = createNewStowageTable(fields); return st;});//converting the RDD to DataFrameDataFrame stowageTableDF = sqlContext.createDataFrame(dataToPOJO, StowageTable.class);//call jdbc persisterpersistToTable(stowageTableDF);我的persistToTable(DataFrame df)方法如下:private void persistToTable(DataFrame df) { Class.forName("")//driver here //skipping a few lines for brevity df.write().mode(SaveMode.Append).jdbc(url, table, connectionProperties);}我在这里找到了一些解决方案:Spark DataFrame write to JDBC - Can't get JDBC type for array<array<int>> and java.lang.IllegalArgumentException: Can't get JDBC type for array<string> but could not find any它解决了日期时间数据类型问题。请建议我一些解决方案。我在火花 1.6.3。
1 回答
www说
TA贡献1775条经验 获得超8个赞
由于我还找不到任何答案,并且在此期间为自己找到了解决方案,因此这是基本思想。如果数据库的数据类型为时间戳,那么您必须在对象的 POJO 中使用时间戳,然后将该时间戳转换为 spark 的结构类型。
添加回答
举报
0/150
提交
取消