2626import com .google .common .collect .Lists ;
2727import com .google .common .collect .Maps ;
2828import org .apache .commons .lang3 .StringUtils ;
29+ import org .apache .flink .api .java .tuple .Tuple2 ;
2930
3031import java .util .List ;
3132import java .util .Map ;
@@ -49,6 +50,8 @@ public abstract class AbstractTableParser {
4950 private static Pattern nestJsonFieldKeyPattern = Pattern .compile ("(?i)((@*\\ S+\\ .)*\\ S+)\\ s+(.+?)\\ s+AS\\ s+(\\ w+)(\\ s+NOT\\ s+NULL)?$" );
5051 private static Pattern physicalFieldFunPattern = Pattern .compile ("\\ w+\\ ((\\ w+)\\ )$" );
5152 private static Pattern charTypePattern = Pattern .compile ("(?i)CHAR\\ ((\\ d*)\\ )$" );
53+ private static Pattern typePattern = Pattern .compile ("(\\ S+)\\ s+(\\ w+.*)" );
54+
5255
5356 private Map <String , Pattern > patternMap = Maps .newHashMap ();
5457
@@ -95,23 +98,16 @@ public void parseFieldsInfo(String fieldsInfo, AbstractTableInfo tableInfo) {
9598 throw new RuntimeException (String .format ("table [%s],exists field empty." , tableInfo .getName ()));
9699 }
97100
98- String [] fieldInfoArr = fieldRow .split ("\\ s+" );
99-
100- String errorMsg = String .format ("table [%s] field [%s] format error." , tableInfo .getName (), fieldRow );
101- Preconditions .checkState (fieldInfoArr .length >= 2 , errorMsg );
102-
103101 boolean isMatcherKey = dealKeyPattern (fieldRow , tableInfo );
104102 if (isMatcherKey ) {
105103 continue ;
106104 }
107105
108- //Compatible situation may arise in space in the fieldName
109- String [] filedNameArr = new String [fieldInfoArr .length - 1 ];
110- System .arraycopy (fieldInfoArr , 0 , filedNameArr , 0 , fieldInfoArr .length - 1 );
111- String fieldName = String .join (" " , filedNameArr );
112- String fieldType = fieldInfoArr [fieldInfoArr .length - 1 ].trim ();
106+ Tuple2 <String , String > t = extractType (fieldRow , tableInfo .getName ());
107+ String fieldName = t .f0 ;
108+ String fieldType = t .f1 ;
113109
114- Class fieldClass = null ;
110+ Class fieldClass ;
115111 AbstractTableInfo .FieldExtraInfo fieldExtraInfo = null ;
116112
117113 Matcher matcher = charTypePattern .matcher (fieldType );
@@ -123,7 +119,7 @@ public void parseFieldsInfo(String fieldsInfo, AbstractTableInfo tableInfo) {
123119 fieldClass = dbTypeConvertToJavaType (fieldType );
124120 }
125121
126- tableInfo .addPhysicalMappings (fieldInfoArr [ 0 ], fieldInfoArr [ 0 ] );
122+ tableInfo .addPhysicalMappings (fieldName , fieldName );
127123 tableInfo .addField (fieldName );
128124 tableInfo .addFieldClass (fieldClass );
129125 tableInfo .addFieldType (fieldType );
@@ -133,11 +129,23 @@ public void parseFieldsInfo(String fieldsInfo, AbstractTableInfo tableInfo) {
133129 tableInfo .finish ();
134130 }
135131
132+ private Tuple2 <String , String > extractType (String fieldRow , String tableName ) {
133+ Matcher matcher = typePattern .matcher (fieldRow );
134+ if (matcher .matches ()) {
135+ String fieldName = matcher .group (1 );
136+ String fieldType = matcher .group (2 );
137+ return Tuple2 .of (fieldName , fieldType );
138+ } else {
139+ String errorMsg = String .format ("table [%s] field [%s] format error." , tableName , fieldRow );
140+ throw new RuntimeException (errorMsg );
141+ }
142+ }
143+
136144 public void dealPrimaryKey (Matcher matcher , AbstractTableInfo tableInfo ) {
137145 String primaryFields = matcher .group (1 ).trim ();
138- String [] splitArry = primaryFields .split ("," );
139- List <String > primaryKes = Lists .newArrayList (splitArry );
140- tableInfo .setPrimaryKeys (primaryKes );
146+ String [] splitArray = primaryFields .split ("," );
147+ List <String > primaryKeys = Lists .newArrayList (splitArray );
148+ tableInfo .setPrimaryKeys (primaryKeys );
141149 }
142150
143151 /**
0 commit comments