diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/arithmetic/Mul.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/arithmetic/Mul.java index 3eb78ef953f8f..e439c3982091c 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/arithmetic/Mul.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/predicate/operator/arithmetic/Mul.java @@ -34,6 +34,7 @@ public Mul(Source source, Expression left, Expression right) { ); } + /* @Override protected TypeResolution resolveType() { if (childrenResolved() == false) { @@ -51,6 +52,8 @@ protected TypeResolution resolveType() { return new TypeResolution(format(null, "[{}] has arguments with incompatible types [{}] and [{}]", symbol(), l, r)); } + */ + @Override public ArithmeticOperationFactory binaryComparisonInverse() { return Div::new; diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java index 2596340e7f206..8c583e0164d47 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java @@ -28,11 +28,11 @@ public class VerifierTests extends ESTestCase { public void testIncompatibleTypesInMathOperation() { assertEquals( - "1:40: second argument of [a + c] must be [numeric], found value [c] type [keyword]", + "1:40: second argument of [a + c] must be [datetime or numeric], found value [c] type [keyword]", error("row a = 1, b = 2, c = \"xxx\" | eval y = a + c") ); assertEquals( - "1:40: second argument of [a - c] must be [numeric], found value [c] type [keyword]", + "1:40: second argument of [a - c] must be [datetime or numeric], found value [c] type [keyword]", error("row a = 1, b = 2, c = \"xxx\" | eval y = a - c") ); } @@ -214,14 +214,13 @@ public void testUnsignedLongTypeMixInArithmetics() { assertThat( error("row n = to_" + type + "(1), ul = to_ul(1) | eval " + op), containsString( - "first argument of [" - + op - + "] is [" - + leftType - + "] and second is [" - + rightType - + "]." - + " [unsigned_long] can only be operated on together with another [unsigned_long]" + "[" + + operation + + "] has arguments with incompatible types [" + + leftType.toUpperCase() + + "] and [" + + rightType.toUpperCase() + + "]" ) ); } @@ -230,7 +229,7 @@ public void testUnsignedLongTypeMixInArithmetics() { public void testUnsignedLongNegation() { assertEquals( - "1:29: negation unsupported for arguments of type [unsigned_long] in expression [-x]", + "1:29: argument of [-x] must be [numeric, date_period or time_duration], found value [x] type [unsigned_long]", error("row x = to_ul(1) | eval y = -x") ); } diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/predicate/operator/arithmetic/MulTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/predicate/operator/arithmetic/MulTests.java index 2ab72ebf9d5f6..68c7794ec12a0 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/predicate/operator/arithmetic/MulTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/predicate/operator/arithmetic/MulTests.java @@ -10,6 +10,7 @@ import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; +import org.elasticsearch.xpack.esql.expression.function.AbstractFunctionTestCase; import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier; import org.elasticsearch.xpack.ql.expression.Expression; import org.elasticsearch.xpack.ql.tree.Source; @@ -23,7 +24,7 @@ import static org.elasticsearch.xpack.ql.util.NumericUtils.unsignedLongAsBigInteger; import static org.hamcrest.Matchers.equalTo; -public class MulTests extends AbstractArithmeticTestCase { +public class MulTests extends AbstractFunctionTestCase { public MulTests(@Name("TestCase") Supplier testCaseSupplier) { this.testCase = testCaseSupplier.get(); } @@ -86,29 +87,7 @@ public static Iterable parameters() { } @Override - protected Mul build(Source source, Expression lhs, Expression rhs) { - return new Mul(source, lhs, rhs); - } - - @Override - protected double expectedValue(double lhs, double rhs) { - return lhs * rhs; - } - - @Override - protected int expectedValue(int lhs, int rhs) { - return lhs * rhs; - } - - @Override - protected long expectedValue(long lhs, long rhs) { - return lhs * rhs; - } - - @Override - protected long expectedUnsignedLongValue(long lhs, long rhs) { - BigInteger lhsBI = unsignedLongAsBigInteger(lhs); - BigInteger rhsBI = unsignedLongAsBigInteger(rhs); - return asLongUnsigned(lhsBI.multiply(rhsBI).longValue()); + protected Expression build(Source source, List args) { + return new Mul(source, args.get(0), args.get(1)); } }