@@ -66,7 +66,9 @@ public class DtNestRowDeserializationSchema extends AbstractDeserializationSchem
6666 private final String charsetName ;
6767
6868 private static final Pattern TIMESTAMP_PATTERN = Pattern .compile ("^\\ d+$" );
69- private static final Pattern TIME_FORMAT_PATTERN = Pattern .compile ("\\ w+\\ d+:\\ d+:\\ d+" );
69+ private static final Pattern TIMESTAMP_FORMAT_PATTERN = Pattern .compile ("[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}?.*" );
70+ private static final Pattern TIME_FORMAT_PATTERN = Pattern .compile ("[0-9]{2}:[0-9]{2}:[0-9]{2}?.*" );
71+ private static final Pattern DATE_FORMAT_PATTERN = Pattern .compile ("[0-9]{4}-[0-9]{2}-[0-9]{2}" );
7072
7173 public DtNestRowDeserializationSchema (TypeInformation <Row > typeInfo , Map <String , String > rowAndFieldMapping ,
7274 List <AbstractTableInfo .FieldExtraInfo > fieldExtraInfos ,
@@ -147,7 +149,7 @@ private Object convert(JsonNode node, TypeInformation<?> info) {
147149 return node .asText ();
148150 }
149151 } else if (info .getTypeClass ().equals (Types .SQL_DATE .getTypeClass ())) {
150- return Date . valueOf (node .asText ());
152+ return convertToDate (node .asText ());
151153 } else if (info .getTypeClass ().equals (Types .SQL_TIME .getTypeClass ())) {
152154 // local zone
153155 return convertToTime (node .asText ());
@@ -169,27 +171,51 @@ private Object convert(JsonNode node, TypeInformation<?> info) {
169171 }
170172 }
171173
172- /**
173- * 将 2020-09-07 14:49:10.0 和 1598446699685 两种格式都转化为 Timestamp
174- */
174+ /** 将 2020-09-07 14:49:10.0 和 1598446699685 两种格式都转化为 Timestamp */
175175 private Timestamp convertToTimestamp (String timestamp ) {
176176 if (TIMESTAMP_PATTERN .matcher (timestamp ).find ()) {
177177 return new Timestamp (Long .parseLong (timestamp ));
178178 }
179- if (TIME_FORMAT_PATTERN .matcher (timestamp ).find ()) {
179+ if (TIMESTAMP_FORMAT_PATTERN .matcher (timestamp ).find ()) {
180180 return Timestamp .valueOf (timestamp );
181181 }
182- throw new IllegalArgumentException ("Incorrect time format of timestamp" );
182+ throw new IllegalArgumentException (
183+ String .format (
184+ "Incorrect timestamp format [yyyy-MM-dd hh:mm:ss] of timestamp type. Input value: [%s]" ,
185+ timestamp ));
186+ }
187+
188+ private Date convertToDate (String date ) {
189+ if (TIMESTAMP_PATTERN .matcher (date ).find ()) {
190+ return new Date (Long .parseLong (date ));
191+ }
192+ if (TIMESTAMP_FORMAT_PATTERN .matcher (date ).find ()) {
193+ return new Date (Timestamp .valueOf (date ).getTime ());
194+ }
195+ if (DATE_FORMAT_PATTERN .matcher (date ).find ()) {
196+ return Date .valueOf (date );
197+ }
198+ throw new IllegalArgumentException (
199+ String .format (
200+ "Incorrect date format [yyyy-MM-dd] of date type. Input value: [%s]" ,
201+ date ));
183202 }
184203
185204 private Time convertToTime (String timestamp ) {
186205 if (TIMESTAMP_PATTERN .matcher (timestamp ).find ()) {
187206 return new Time (Long .parseLong (timestamp ));
188207 }
208+ if (TIMESTAMP_FORMAT_PATTERN .matcher (timestamp ).find ()) {
209+ long time = Timestamp .valueOf (timestamp ).getTime ();
210+ return new Time (time );
211+ }
189212 if (TIME_FORMAT_PATTERN .matcher (timestamp ).find ()) {
190213 return Time .valueOf (timestamp );
191214 }
192- throw new IllegalArgumentException ("Incorrect time format of time" );
215+ throw new IllegalArgumentException (
216+ String .format (
217+ "Incorrect time format [hh:mm:ss] of time type. Input value: [%s]" ,
218+ timestamp ));
193219 }
194220
195221 private Row convertTopRow () {
0 commit comments