java.lang.StringIndexOutOfBoundsException: String index out of range: -2147483648 成功解决

前言

最近一个小伙伴出现一个从未见过的一个异常,不知道如何解决,于是找我帮忙,看到问题我也是有点懵,怎么会出现这个问题呢,于是找他要了sql脚本,开始找问题的原因。。。

问题描述

出现了如下异常:

ERROR yarn.Client: Application diagnostics message: User class threw exception: java.lang.StringIndexOutOfBoundsException: String index out of range: -2147483648
        at java.lang.String.charAt(String.java:658)
        at com.alibaba.druid.sql.parser.Lexer.charAt(Lexer.java:161)
        at com.alibaba.druid.sql.parser.Lexer.scanChar(Lexer.java:273)
        at com.alibaba.druid.sql.parser.Lexer.scanHiveComment(Lexer.java:2130)
        at com.alibaba.druid.sql.dialect.hive.parser.HiveLexer.scanComment(HiveLexer.java:83)
        at com.alibaba.druid.sql.parser.Lexer.nextToken(Lexer.java:1173)
        at com.alibaba.druid.sql.dialect.hive.parser.HiveExprParser.<init>(HiveExprParser.java:54)
        at com.alibaba.druid.sql.dialect.hive.parser.HiveStatementParser.<init>(HiveStatementParser.java:39)
        at com.alibaba.druid.sql.parser.SQLParserUtils.createSQLStatementParser(SQLParserUtils.java:131)
        at com.alibaba.druid.sql.SQLUtils.parseStatements(SQLUtils.java:563)
        at com.alibaba.druid.sql.SQLUtils.parseStatements(SQLUtils.java:587)
        at com.quantex.utils.HiveSqlUtils.getCreateTableName(HiveSqlUtils.java:128)
        at com.quantex.utils.HiveSqlUtils.executeHive(HiveSqlUtils.java:43)
        at com.quantex.MainRun.main(MainRun.java:63)
        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:665)

解决方案

在排查问题过程中,执行 SQL 脚本没有问题,但是一加上文件头部的注释部分就报错,那么问题就是出在这个注释部分,一般来说注释怎么会出现问题呢,最后发现注释中有英文分号; ,于是去掉注释中的英文分号,任务可以正常执行!
终于发现问题所在,spark sql 中除了在设置参数和最后可以添加英文分号外,其他任何地方添加都会执行异常!

解决方法:去掉 sql 中设置参数和最后可以添加英文分号外的任何英文分号!!!

猜你喜欢

转载自blog.csdn.net/u011109589/article/details/130601594