4242import java .util .Iterator ;
4343import java .util .List ;
4444import java .util .Map ;
45+ import java .util .regex .Pattern ;
4546
4647/**
4748 * source data parse to json format
@@ -64,6 +65,9 @@ public class DtNestRowDeserializationSchema extends AbstractDeserializationSchem
6465 private final List <AbstractTableInfo .FieldExtraInfo > fieldExtraInfos ;
6566 private final String charsetName ;
6667
68+ private static final Pattern TIMESTAMP_PATTERN = Pattern .compile ("^\\ d+$" );
69+ private static final Pattern TIME_FORMAT_PATTERN = Pattern .compile ("\\ w+\\ d+:\\ d+:\\ d+" );
70+
6771 public DtNestRowDeserializationSchema (TypeInformation <Row > typeInfo , Map <String , String > rowAndFieldMapping ,
6872 List <AbstractTableInfo .FieldExtraInfo > fieldExtraInfos ,
6973 String charsetName ) {
@@ -146,7 +150,7 @@ private Object convert(JsonNode node, TypeInformation<?> info) {
146150 return Date .valueOf (node .asText ());
147151 } else if (info .getTypeClass ().equals (Types .SQL_TIME .getTypeClass ())) {
148152 // local zone
149- return Time . valueOf (node .asText ());
153+ return convertToTime (node .asText ());
150154 } else if (info .getTypeClass ().equals (Types .SQL_TIMESTAMP .getTypeClass ())) {
151155 // local zone
152156 return convertToTimestamp (node .asText ());
@@ -169,10 +173,23 @@ private Object convert(JsonNode node, TypeInformation<?> info) {
169173 * 将 2020-09-07 14:49:10.0 和 1598446699685 两种格式都转化为 Timestamp
170174 */
171175 private Timestamp convertToTimestamp (String timestamp ) {
172- if (timestamp .contains (" " )) {
176+ if (TIMESTAMP_PATTERN .matcher (timestamp ).find ()) {
177+ return new Timestamp (Long .parseLong (timestamp ));
178+ }
179+ if (TIME_FORMAT_PATTERN .matcher (timestamp ).find ()) {
173180 return Timestamp .valueOf (timestamp );
174181 }
175- return new Timestamp (Long .parseLong (timestamp ));
182+ throw new IllegalArgumentException ("Incorrect time format of timestamp" );
183+ }
184+
185+ private Time convertToTime (String timestamp ) {
186+ if (TIMESTAMP_PATTERN .matcher (timestamp ).find ()) {
187+ return new Time (Long .parseLong (timestamp ));
188+ }
189+ if (TIME_FORMAT_PATTERN .matcher (timestamp ).find ()) {
190+ return Time .valueOf (timestamp );
191+ }
192+ throw new IllegalArgumentException ("Incorrect time format of time" );
176193 }
177194
178195 private Row convertTopRow () {
0 commit comments