1919package com .dtstack .flinkx .enums ;
2020
2121import com .dtstack .flinkx .constants .ConstantValue ;
22+ import org .apache .commons .lang3 .StringUtils ;
2223
2324import java .util .Arrays ;
2425import java .util .List ;
26+ import java .util .Locale ;
2527
2628/**
2729 * Define standard column type for all the readers or writers that do not
@@ -66,6 +68,12 @@ public enum ColumnType {
6668 STRING , VARCHAR , VARCHAR2 , CHAR , NVARCHAR , TEXT , KEYWORD , BINARY
6769 );
6870
71+ /**
72+ * 根据字段类型的字符串找出对应的枚举
73+ * 找不到直接报错 IllegalArgumentException
74+ * @param type
75+ * @return
76+ */
6977 public static ColumnType fromString (String type ) {
7078 if (type == null ) {
7179 throw new RuntimeException ("null ColumnType!" );
@@ -75,15 +83,31 @@ public static ColumnType fromString(String type) {
7583 type = type .substring (0 , type .indexOf (ConstantValue .LEFT_PARENTHESIS_SYMBOL ));
7684 }
7785
78- return valueOf (type .toUpperCase ());
86+ type = type .toUpperCase (Locale .ENGLISH );
87+ //为了支持无符号类型 如 int unsigned
88+ if (StringUtils .contains (type ,ConstantValue .DATA_TYPE_UNSIGNED )){
89+ type = type .replace (ConstantValue .DATA_TYPE_UNSIGNED ,"" ).trim ();
90+ }
91+ return valueOf (type );
7992 }
8093
94+ /**
95+ * 根据字段类型的字符串找到对应的枚举 找不到就直接返回ColumnType.STRING;
96+ * @param type
97+ * @return
98+ */
8199 public static ColumnType getType (String type ){
100+ type = type .toUpperCase (Locale .ENGLISH );
82101 if (type .contains (ConstantValue .LEFT_PARENTHESIS_SYMBOL )){
83102 type = type .substring (0 , type .indexOf (ConstantValue .LEFT_PARENTHESIS_SYMBOL ));
84103 }
85104
86- if (type .toLowerCase ().contains (ColumnType .TIMESTAMP .name ().toLowerCase ())){
105+ //为了支持无符号类型 如 int unsigned
106+ if (StringUtils .contains (type ,ConstantValue .DATA_TYPE_UNSIGNED )){
107+ type = type .replaceAll (ConstantValue .DATA_TYPE_UNSIGNED ,"" ).trim ();
108+ }
109+
110+ if (type .contains (ColumnType .TIMESTAMP .name ())){
87111 return TIMESTAMP ;
88112 }
89113
0 commit comments