Skip to content

Commit 196dbba

Browse files
nokiaMSgithubgxll
authored andcommitted
[fix][runtime] Fix issue about string cast to numeric.
1 parent 4b04b78 commit 196dbba

File tree

1 file changed

+12
-2
lines changed
  • runtime/src/main/java/io/dingodb/expr/runtime/op/cast

1 file changed

+12
-2
lines changed

runtime/src/main/java/io/dingodb/expr/runtime/op/cast/CastOp.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,29 @@ public abstract class CastOp extends UnaryOp {
3535

3636
public static String trimDigitString(String value) {
3737
int lastNumberPos = 0;
38+
int ePos = -1;
3839

3940
value = value.trim();
4041
for (int i = 0; i < value.length(); i++) {
41-
if (Character.isDigit(value.charAt(i))
42-
|| value.charAt(i) == '.'
42+
if (Character.isDigit(value.charAt(i))) {
43+
lastNumberPos++;
44+
} else if (value.charAt(i) == '.'
4345
|| value.charAt(i) == 'e'
4446
|| value.charAt(i) == 'E') {
47+
if (ePos != -1) {
48+
break;
49+
} else {
50+
ePos = i;
51+
}
4552
lastNumberPos++;
4653
} else {
4754
break;
4855
}
4956
}
5057

58+
if (lastNumberPos > 0 && lastNumberPos == ePos + 1) {
59+
lastNumberPos--;
60+
}
5161
return value.substring(0, lastNumberPos);
5262
}
5363
}

0 commit comments

Comments
 (0)