Skip to content

Commit 4fb1826

Browse files
committed
[fix-30060] fix timestamp format error
1 parent 56df6ec commit 4fb1826

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

core/src/main/java/com/dtstack/flink/sql/format/dtnest/DtNestRowDeserializationSchema.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)