mirror of https://github.com/apache/druid.git
Improve exception message for native binary operators (#12335)
* Improve exception message * Update message
This commit is contained in:
parent
7b89682bbe
commit
df074f2f96
|
@ -21,6 +21,7 @@ package org.apache.druid.math.expr;
|
|||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.apache.druid.common.config.NullHandling;
|
||||
import org.apache.druid.java.util.common.IAE;
|
||||
import org.apache.druid.java.util.common.StringUtils;
|
||||
import org.apache.druid.segment.column.Types;
|
||||
|
||||
|
@ -151,7 +152,11 @@ abstract class BinaryEvalOpExprBase extends BinaryOpExprBase
|
|||
|
||||
protected ExprEval evalString(@Nullable String left, @Nullable String right)
|
||||
{
|
||||
throw new IllegalArgumentException("unsupported type " + ExprType.STRING);
|
||||
throw new IAE("operator '%s' in expression (%s %s %s) is not supported on type 'string'.",
|
||||
this.op,
|
||||
this.left.stringify(),
|
||||
this.op,
|
||||
this.right.stringify());
|
||||
}
|
||||
|
||||
protected abstract long evalLong(long left, long right);
|
||||
|
|
|
@ -80,7 +80,9 @@ public class FunctionTest extends InitializedNullHandlingTest
|
|||
.put("a", new String[] {"foo", "bar", "baz", "foobar"})
|
||||
.put("b", new Long[] {1L, 2L, 3L, 4L, 5L})
|
||||
.put("c", new Double[] {3.1, 4.2, 5.3})
|
||||
.put("someComplex", new TypeStrategiesTest.NullableLongPair(1L, 2L));
|
||||
.put("someComplex", new TypeStrategiesTest.NullableLongPair(1L, 2L))
|
||||
.put("str1", "v1")
|
||||
.put("str2", "v2");
|
||||
bindings = InputBindings.withMap(builder.build());
|
||||
}
|
||||
|
||||
|
@ -973,6 +975,36 @@ public class FunctionTest extends InitializedNullHandlingTest
|
|||
assertArrayExpr("mv_to_array()", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlusOnString()
|
||||
{
|
||||
assertExpr("str1 + str2", "v1v2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiplyOnString()
|
||||
{
|
||||
expectedException.expect(IAE.class);
|
||||
expectedException.expectMessage("operator '*' in expression (\"str1\" * \"str2\") is not supported on type 'string'.");
|
||||
assertExpr("str1 * str2", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinusOnString()
|
||||
{
|
||||
expectedException.expect(IAE.class);
|
||||
expectedException.expectMessage("operator '-' in expression (\"str1\" - \"str2\") is not supported on type 'string'.");
|
||||
assertExpr("str1 - str2", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDivOnString()
|
||||
{
|
||||
expectedException.expect(IAE.class);
|
||||
expectedException.expectMessage("operator '/' in expression (\"str1\" / \"str2\") is not supported on type 'string'.");
|
||||
assertExpr("str1 / str2", null);
|
||||
}
|
||||
|
||||
private void assertExpr(final String expression, @Nullable final Object expectedResult)
|
||||
{
|
||||
final Expr expr = Parser.parse(expression, ExprMacroTable.nil());
|
||||
|
|
Loading…
Reference in New Issue