spark 读取mysql 自增id,用getAsLong()方法解析报错
原因:mysql中id字段的类型为 unsigned bigint ,而不是 bigint
Caused by: java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.Long
1. mysql中类型为 bigint 的字段,在spark解析后,默认是long类型
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
root
|-- id: long (nullable = true)
2.mysql中类型为 unsigned bigint 的字段,在spark解析后,默认是decimal类型
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
root
|-- id: decimal(20,0) (nullable = true)