Skip to content

Commit e4f326d

Browse files
guojn1githubgxll
authored andcommitted
[fix][runtime] Support converting binary to int type
1 parent ca27f87 commit e4f326d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ private IntCastCheckOpFactory() {
4747
opMap.put(keyOf(Types.STRING), new IntCastString());
4848
opMap.put(keyOf(Types.DOUBLE), new IntCastDouble());
4949
opMap.put(keyOf(Types.INT), new IntCastInt());
50+
opMap.put(keyOf(Types.BYTES), new IntCastBytes());
5051
}
5152

5253
@Override
@@ -166,6 +167,22 @@ public OpKey getKey() {
166167
}
167168
}
168169

170+
public static final class IntCastBytes extends IntCastCheckOp {
171+
172+
@Serial
173+
private static final long serialVersionUID = -3226282053385258209L;
174+
175+
@Override
176+
protected Integer evalNonNullValue(@NonNull Object value, ExprConfig config) {
177+
return intCastAny.evalNonNullValue(value, config);
178+
}
179+
180+
@Override
181+
public OpKey getKey() {
182+
return keyOf(Types.STRING);
183+
}
184+
}
185+
169186
public static final class IntCastAny extends IntCastCheckOp {
170187

171188
@Serial
@@ -190,6 +207,12 @@ protected Integer evalNonNullValue(@NonNull Object value, ExprConfig config) {
190207
return intCast((BigDecimal) value);
191208
} else if (value instanceof Boolean) {
192209
return intCast((Boolean) value);
210+
} else if (value instanceof byte[]) {
211+
try {
212+
return Integer.parseInt(new String((byte[]) value));
213+
} catch (Exception e) {
214+
return null;
215+
}
193216
} else {
194217
return null;
195218
}

0 commit comments

Comments
 (0)