天天看點

Error during generated code invocation: com.intellij.debugger.engine.evaluation.EvaluateException: Method threw \'java.lang.IllegalAccessError\' exception.

場景描述:

  再從該資料庫中讀取資料進行處理的時候,需要将某個字段加入到一個動态的map中,然後需要對該map進行filter過濾,在執行過濾方法的時候報錯

Error during generated code invocation:
 com.intellij.debugger.engine.evaluation.EvaluateException: Method threw \'java.lang.IllegalAccessError\' exception.      

  報錯截圖:

  

Error during generated code invocation: com.intellij.debugger.engine.evaluation.EvaluateException: Method threw \'java.lang.IllegalAccessError\' exception.

  也就是說該map執行不了這個方法。

code:

val maps = Collection.muttable.Map[String, Int]()
      for (elem <- referenceData.collect()) {
        maps.put(String.valueOf(elem.getAs[Timestamp]("datatime")), elem.getAs[Int]("innum"))
      }
      val exceptMsgs = auditData.rdd.collect().map(row => {
        var auditResult = 0
        val innum = row.getAs[Int]("innum")
        //擷取資料時間的時分秒
        val time = String.valueOf(row.getAs[Timestamp]("datatime")).substring(11)
        //擷取對應map中包含這個時間點的資料
        val mapArr = maps.filterKeys(_.substring(11).equals(time)).map(x => x._2)      

問題原因:

  上面面代碼中,我是将從資料庫查詢出來的資料"datatime"這個字段進行添加到maps中,而我使用的Timestamp類型,看下我資料庫中該字段的類型:

  

Error during generated code invocation: com.intellij.debugger.engine.evaluation.EvaluateException: Method threw \'java.lang.IllegalAccessError\' exception.

  資料庫中的該字段類型是datetime,本來我以為datetime對應到spark中的類型就是Timestamp,顯然這樣是會報上面的那個錯的,如果當做String類型進行讀取也是不行的,完全要按照datetime這個類型來進行修改,否則,資料讀取出來之後可以添加到maps中,但是,對maps中的元素進行操作是會有問題的。接下來就是修改

改後部分代碼:

val maps = Map[String, Int]()
      for (elem <- referenceData.collect()) {
        maps.put(String.valueOf(elem.getAs[DateTime]("datatime")), elem.getAs[Int]("innum"))
      }
      val exceptMsgs = auditData.rdd.collect().map(row => {
        var auditResult = 0
        val innum = row.getAs[Int]("innum")
        val time = String.valueOf(row.getAs[DateTime]("datatime")).substring(11)
        val mapArr = maps.filterKeys(_.substring(11).equals(time)).map(x => x._2)      

修改之後,問題消失