【异常】update更新java.sql.SQLException: Duplicate entry '2019-07-30 00:00:00-110100' for key

1 详细异常信息

User class threw exception: java.sql.SQLException: Duplicate entry '2019-07-30 00:00:00-110100' for key 'dc' Query: update t_user_register_analyse set city_code = ?, city = ?, total_user_register_count = ?, day_user_register_count = ?, first_order_user_count = ?, day_user_register_ordered_conversion_rate = ? where day_time = ? Parameters: [110100, 北京市, 6304, 10, 0, 0, 2019-07-30 00:00:00]
at org.apache.commons.dbutils.AbstractQueryRunner.rethrow(AbstractQueryRunner.java:527)
at org.apache.commons.dbutils.QueryRunner.execute(QueryRunner.java:890)
at org.apache.commons.dbutils.QueryRunner.execute(QueryRunner.java:800)
at com.wm.bigdata.common.mysql.dao.TUserRegisterAnalyseDao$.update(TUserRegisterAnalyseDao.scala:25)
at com.wm.bigdata.spark.etl.UserAnalysisEtl$$anonfun$main$1$$anonfun$apply$mcVJ$sp$2.apply(UserAnalysisEtl.scala:370)
at com.wm.bigdata.spark.etl.UserAnalysisEtl$$anonfun$main$1$$anonfun$apply$mcVJ$sp$2.apply(UserAnalysisEtl.scala:310)
at scala.collection.Iterator$class.foreach(Iterator.scala:891)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1334)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
at com.wm.bigdata.spark.etl.UserAnalysisEtl$$anonfun$main$1.apply$mcVJ$sp(UserAnalysisEtl.scala:310)
at com.wm.bigdata.spark.etl.UserAnalysisEtl$$anonfun$main$1.apply(UserAnalysisEtl.scala:141)
at com.wm.bigdata.spark.etl.UserAnalysisEtl$$anonfun$main$1.apply(UserAnalysisEtl.scala:141)
at scala.collection.Iterator$class.foreach(Iterator.scala:891)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1334)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
at com.wm.bigdata.spark.etl.UserAnalysisEtl$.main(UserAnalysisEtl.scala:141)
at com.wm.bigdata.spark.etl.UserAnalysisEtl.main(UserAnalysisEtl.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.spark.deploy.yarn.ApplicationMaster$$anon$2.run(ApplicationMaster.scala:678)

2 原因,自己建的联合主键是 day_time 和 city_code

  但是更新语句只把day_time作为了条件,所以抛出了多主键异常,更新条件改为 day_time加city_code解决问题。  

 

posted @ 2019-07-31 11:22  Questions张  阅读(1691)  评论(0编辑  收藏  举报