@@ -149,8 +149,8 @@ private Object convert(JsonNode node, TypeInformation<?> info) {
149149 return Time .valueOf (node .asText ());
150150 } else if (info .getTypeClass ().equals (Types .SQL_TIMESTAMP .getTypeClass ())) {
151151 // local zone
152- return Timestamp . valueOf (node .asText ());
153- } else if (info instanceof RowTypeInfo ) {
152+ return convertToTimestamp (node .asText ());
153+ } else if (info instanceof RowTypeInfo ) {
154154 return convertRow (node , (RowTypeInfo ) info );
155155 } else if (info instanceof ObjectArrayTypeInfo ) {
156156 return convertObjectArray (node , ((ObjectArrayTypeInfo ) info ).getComponentInfo ());
@@ -165,6 +165,16 @@ private Object convert(JsonNode node, TypeInformation<?> info) {
165165 }
166166 }
167167
168+ /**
169+ * 将 2020-09-07 14:49:10.0 和 1598446699685 两种格式都转化为 Timestamp
170+ */
171+ private Timestamp convertToTimestamp (String timestamp ) {
172+ if (timestamp .contains (" " )) {
173+ return Timestamp .valueOf (timestamp );
174+ }
175+ return new Timestamp (Long .parseLong (timestamp ));
176+ }
177+
168178 private Row convertTopRow () {
169179 Row row = new Row (fieldNames .length );
170180 try {
@@ -175,7 +185,7 @@ private Row convertTopRow() {
175185 if (node == null ) {
176186 if (fieldExtraInfo != null && fieldExtraInfo .getNotNull ()) {
177187 throw new IllegalStateException ("Failed to find field with name '"
178- + fieldNames [i ] + "'." );
188+ + fieldNames [i ] + "'." );
179189 } else {
180190 row .setField (i , null );
181191 }
@@ -216,6 +226,7 @@ private Object convertObjectArray(JsonNode node, TypeInformation<?> elementType)
216226 }
217227 return array ;
218228 }
229+
219230 @ Override
220231 public TypeInformation <Row > getProducedType () {
221232 return typeInfo ;
0 commit comments