diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/serde/RexStandardizer.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/serde/RexStandardizer.java index 78afd4aaf01..9e8692c9448 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/serde/RexStandardizer.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/serde/RexStandardizer.java @@ -83,7 +83,19 @@ public RexNode visitCall(final RexCall call, ScriptParameterHelper helper) { // Do normalization before standardization Pair> normalized = RexNormalize.normalize(call.op, call.operands); List standardizedOperands = visitList(normalized.right, helper, update); - return helper.rexBuilder.makeCall(call.getType(), normalized.left, standardizedOperands); + RexNode result = + helper.rexBuilder.makeCall(call.getType(), normalized.left, standardizedOperands); + + if (allowNumericTypeWiden + && SqlTypeUtil.isExactNumeric(call.getType()) + && !call.getType().getSqlTypeName().equals(SqlTypeName.BIGINT)) { + RelDataType targetType = + OpenSearchTypeFactory.TYPE_FACTORY.createTypeWithNullability( + call.getType(), call.getType().isNullable()); + result = helper.rexBuilder.makeCast(targetType, result); + } + + return result; } finally { helper.stack.pop(); }