diff --git a/dinky-client/dinky-client-base/src/main/java/org/dinky/utils/FlinkTableMetadataUtil.java b/dinky-client/dinky-client-base/src/main/java/org/dinky/utils/FlinkTableMetadataUtil.java index 7fcc9c96b7..5260c5fdcf 100644 --- a/dinky-client/dinky-client-base/src/main/java/org/dinky/utils/FlinkTableMetadataUtil.java +++ b/dinky-client/dinky-client-base/src/main/java/org/dinky/utils/FlinkTableMetadataUtil.java @@ -110,22 +110,10 @@ public static List getColumnList( column.setScale(((DecimalType) logicalType).getScale()); } - for (ColumnType columnType : ColumnType.values()) { - if (columnType - .getJavaType() - .equals(flinkColumn - .getDataType() - .getConversionClass() - .getName())) { - column.setJavaType(columnType); - break; - } - } - // FlinkColumn flinkColumn = FlinkColumn.build(i, - // column.getName(), column.getDataType().getConversionClass().getName(), - // isPrimaryKey.get(), column.getDataType().getLogicalType().isNullable(), - // column.explainExtras().orElse(""), "", column.getComment().orElse("")); - + String dataTypeName = + flinkColumn.getDataType().getConversionClass().getName(); + ColumnType columnType = ColumnType.getByJavaType(dataTypeName); + column.setJavaType(columnType); columns.add(column); } }); diff --git a/dinky-common/src/main/java/org/dinky/data/enums/ColumnType.java b/dinky-common/src/main/java/org/dinky/data/enums/ColumnType.java index 8f55bd476b..1d396b1e26 100644 --- a/dinky-common/src/main/java/org/dinky/data/enums/ColumnType.java +++ b/dinky-common/src/main/java/org/dinky/data/enums/ColumnType.java @@ -19,7 +19,11 @@ package org.dinky.data.enums; +import java.util.Arrays; +import java.util.Map; + import com.fasterxml.jackson.annotation.JsonValue; +import com.google.common.collect.Maps; /** * ColumnType @@ -61,6 +65,17 @@ public enum ColumnType { private final String javaType; private final String flinkType; + /** + * JavaType -> ColumnType + */ + private static final Map JAVA_COL_TYPE_MAP = Maps.newHashMap(); + + static { + Arrays.stream(ColumnType.values()).forEach(columnType -> { + JAVA_COL_TYPE_MAP.put(columnType.getJavaType(), columnType); + }); + } + ColumnType(String javaType, String flinkType) { this.javaType = javaType; this.flinkType = flinkType; @@ -74,4 +89,8 @@ public String getJavaType() { public String getFlinkType() { return flinkType; } + + public static ColumnType getByJavaType(String javaType) { + return JAVA_COL_TYPE_MAP.getOrDefault(javaType, STRING); + } }