@@ -106,6 +106,13 @@ private String determineDorisType(String fieldName, Object value) {
106106 && existingField .getTypeString ().equals (DorisType .STRING ))) {
107107 return DorisType .STRING ;
108108 }
109+ if (existingField != null ) {
110+ String existingType = existingField .getTypeString ();
111+ if (isDowngrade (existingType , dorisType )) {
112+ return existingType ;
113+ }
114+ }
115+
109116 // Check and process for decimal types
110117 DecimalJudgement decimalJudgement = judgeDecimalField (fieldName , dorisType );
111118 if (DecimalJudgement .needProcessing (decimalJudgement )) {
@@ -118,6 +125,27 @@ private String determineDorisType(String fieldName, Object value) {
118125 return dorisType ;
119126 }
120127
128+ /**
129+ * Check whether the newType is a downgrade from the existingType. Currently only considers
130+ * numeric types: TINYINT < SMALLINT < INT < BIGINT.
131+ */
132+ private boolean isDowngrade (String existingType , String newType ) {
133+ List <String > typeHierarchy =
134+ Arrays .asList (
135+ DorisType .TINYINT , DorisType .SMALLINT , DorisType .INT , DorisType .BIGINT );
136+
137+ int existingIndex = typeHierarchy .indexOf (existingType );
138+ int newIndex = typeHierarchy .indexOf (newType );
139+
140+ return newIndex != -1 && existingIndex != -1 && newIndex < existingIndex ;
141+ }
142+
143+ /**
144+ * Determine whether the field should be treated as a decimal type: - If the existing type is
145+ * already decimal and current value is also decimal, return CERTAIN_DECIMAL. - If the field's
146+ * type is convertible (e.g., INT, BIGINT) and the current value is decimal or double, return
147+ * CONVERT_TO_DECIMAL. - Otherwise, no decimal processing is needed.
148+ */
121149 private DecimalJudgement judgeDecimalField (String fieldName , String dorisType ) {
122150 FieldSchema existingField = fields .get (fieldName );
123151 if (existingField == null ) {
@@ -127,7 +155,7 @@ private DecimalJudgement judgeDecimalField(String fieldName, String dorisType) {
127155 boolean isDecimal = dorisType .startsWith (DorisType .DECIMAL );
128156 if (existDecimal && isDecimal ) {
129157 return DecimalJudgement .CERTAIN_DECIMAL ;
130- } else if (CONVERT_TYPE .contains (dorisType )) {
158+ } else if (existDecimal && CONVERT_TYPE .contains (dorisType )) {
131159 return DecimalJudgement .CONVERT_TO_DECIMAL ;
132160 }
133161 return DecimalJudgement .NOT_DECIMAL ;
0 commit comments