Spark - Illegal pattern component: XXX 与org.apache.commons.lang3.time.FastDateFormat incompatible

简介: 使用 sparkSession 读文件时出现java.lang.IllegalArgumentException: Illegal pattern component: XXX 报错,解决后又出现java.io.InvalidClassException: org.apache.commons.lang3.time.FastDateFormat; local class incompatible: stream classdesc serialVersionUID = 2,下面解决一下。...

一.引言

使用 sparkSession 读文件时出现 java.lang.IllegalArgumentException: Illegal pattern component: XXX 报错,解决后又出现 java.io.InvalidClassException: org.apache.commons.lang3.time.FastDateFormat; local class incompatible: stream classdesc serialVersionUID = 2, local class serialVersionUID = 1 报错,下面整理下解决方案。

二.Illegal pattern component: XXX

1.问题描述

val spark = SparkSession
      .builder
      .config(conf)
      .getOrCreate() 
    val df = spark.read
                .option("header", "false")
                .option("delimiter", "\t")
                .csv(input)

image.gif

使用 SparkSession 读取 gz 文件时出现下述报错:

image.gif编辑

2.问题解决

上述异常栈定位到 org.apache.commons.lang3.time.FastDataFormat,看着是时间格式化的问题,但是我的小伙伴运行上述代码没有问题,很奇怪,看了网上大神们的解决方案,主要有以下两种:

val df = spark.read
                .option("timestampFormat", "yyyy/MM/dd HH:mm:ss ZZ")
                .option("header", "false")
                .option("delimiter", "\t")
                .csv(input)

image.gif

或者是:

val df = spark.read
                .option("timestampFormat", "MM/dd/yyyy")
                .option("header", "false")
                .option("delimiter", "\t")
                .csv(input)

image.gif

二者类似,主要是定义了上面 XXX 对应的 TimeFormat,楼主尝试了一下,两种 TimeFormat 的 option 都可以解决问题。

三.org.apache.commons.lang3.time.FastDateFormat; local class incompatible

1.问题描述

sqlContext.createDataFrame(rowRdd, TABLE_SCHEME)
        .write.mode(SaveMode.Overwrite)
        .option("timestampFormat", "MM/dd/yyyy")
        .format("parquet")
        .save(output + "/split" + i + ".parquet")

image.gif

代码整体逻辑为读取文件并保存为 parquet,parquet 相关内容可以参考: Spark - 一文搞懂 parquet。添加 timestampFormat 后读取和上述保存代码运行正常,spark 任务状态为 SUCCESS,但是观察 yarn 日志发现有很多 Failed 的节点,影响任务执行效率:

image.gif编辑

观察节点日志发现均为如下报错:

image.gif编辑

可以看到 Failed 节点上的报错又是 commons.lang3.time.FastDateFormat,和上面 java.lang.IllegalArgumentException: Illegal pattern component: XXX 异常栈指向的是同一个类即 org.apache.commons.lang3.time.FastDateFormat 类。

2.问题解决

报错显示了两种不同的 serialVersionUID = 2 和 serialVersionUID = 1,很有可能是依赖冲突导致,所以首先遍历当前代码环境下有多少 commons.lang3.time.FastDateFormat,这里使用 IDEA 的查询功能:

image.gif编辑

DailyTool 为我自己的项目,所以主要查下面的项目:

commons.lang3-3.3.3.jar /time/FastDateFormat.class:

image.gif编辑

jasper/util/FastDateFormat:

image.gif编辑

hive-exec:0.13.1 FastDateFormat.class:

image.gif编辑

只有 Hive common.lang3 对应的 serialVersionUID = 1L,所以锁定目标为该 jar,去除该 jar 运行任务即可。

3.其他解决方案

如果有童鞋没有安装 IDEA 可以使用 mvn tree 定位 common.lang3 的位置:

mvn -Dverbose dependency:tree > mvnTree

image.gif

image.gif编辑

cat + grep 可以大致看下有多少 jar 包内包含,通过 jar 包内的代码一次寻找即可:

cat ~/Desktop/mvnTree| grep commons.lang3

image.gif

image.gif编辑

mvn-tree 的更多使用也可以参考:Java - java.lang.NoSuchMethodError: xxx 错误详解

四.总结

java.lang.IllegalArgumentException: Illegal pattern component: XXX 以及其对应的 FastDateFormat 带来的报错大致解决了,但是还没有搞懂为什么其他童鞋不配置这个 option 也可以正常运行,后面再去整理下环境相关的问题,找到了继续更新。

目录
相关文章
|
8天前
Caused by: org.apache.ibatis.type.TypeException: Could not resolve type alias ‘order‘. Caus
Caused by: org.apache.ibatis.type.TypeException: Could not resolve type alias ‘order‘. Caus
38 0
|
8天前
|
Java
org.apache.jasper.JasperException...(line: 15, column: 16) quote symbol expected和处理办法
org.apache.jasper.JasperException...(line: 15, column: 16) quote symbol expected和处理办法
|
6月前
poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]
poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]
115 0
|
11月前
|
SQL XML Java
org.apache.ibatis.binding.BindingException: Parameter ‘startTime‘ not found. Available parameters
org.apache.ibatis.binding.BindingException: Parameter ‘startTime‘ not found. Available parameters
123 0
|
10月前
|
SQL Java 数据库连接
nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘‘ not found. Ava
用mybatis写注解SQL的执行报错,这个报错有很多原因就不说了,说一下我的问题 同一个mapper中方法有重名的,虽然编译没报错,相当于重载了,但是执行的时候就报错了 方法写的太多了都没注意
|
11月前
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
90 0
|
11月前
Cause: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMa
Cause: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMa
165 0
|
11月前
|
SQL
org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration
org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration
68 0
|
XML Java 数据库连接
解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题
解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题
7260 0
解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题
Zp
org.apache.ibatis.binding.BindingException: Parameter 'XXXX' not found.的问题解决办法
org.apache.ibatis.binding.BindingException: Parameter 'XXXX' not found.的问题解决办法
Zp
337 0

热门文章

最新文章