Skip to content

Commit

Permalink
fix verifier tests
Browse files Browse the repository at this point in the history
  • Loading branch information
not-napoleon committed Jan 18, 2024
1 parent 7b7d3f6 commit d308af1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public Mul(Source source, Expression left, Expression right) {
);
}

/*
@Override
protected TypeResolution resolveType() {
if (childrenResolved() == false) {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
);
}
Expand Down Expand Up @@ -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()
+ "]"
)
);
}
Expand All @@ -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")
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.TestCase> testCaseSupplier) {
this.testCase = testCaseSupplier.get();
}
Expand Down Expand Up @@ -86,29 +87,7 @@ public static Iterable<Object[]> 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<Expression> args) {
return new Mul(source, args.get(0), args.get(1));
}
}

0 comments on commit d308af1

Please sign in to comment.