diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/AbstractFunctionTestCase.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/AbstractFunctionTestCase.java
index 8b4a126d8a0c7..d6f3b61cb19dd 100644
--- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/AbstractFunctionTestCase.java
+++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/AbstractFunctionTestCase.java
@@ -49,6 +49,7 @@
import org.elasticsearch.xpack.ql.type.DataType;
import org.elasticsearch.xpack.ql.type.DataTypes;
import org.elasticsearch.xpack.ql.type.EsField;
+import org.elasticsearch.xpack.ql.util.NumericUtils;
import org.elasticsearch.xpack.ql.util.StringUtils;
import org.elasticsearch.xpack.versionfield.Version;
import org.hamcrest.Matcher;
@@ -92,6 +93,7 @@
import static org.elasticsearch.xpack.ql.util.SpatialCoordinateTypes.GEO;
import static org.hamcrest.Matchers.either;
import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.sameInstance;
@@ -241,7 +243,7 @@ private void testEvaluate(boolean readFloating) {
Object result;
try (ExpressionEvaluator evaluator = evaluator(expression).get(driverContext())) {
try (Block block = evaluator.eval(row(testCase.getDataValues()))) {
- result = toJavaObject(block, 0);
+ result = toJavaObjectUnsignedLongAware(block, 0);
}
}
assertThat(result, not(equalTo(Double.NaN)));
@@ -255,6 +257,16 @@ private void testEvaluate(boolean readFloating) {
}
}
+ private Object toJavaObjectUnsignedLongAware(Block block, int position) {
+ Object result;
+ result = toJavaObject(block, position);
+ if (result != null && testCase.expectedType == DataTypes.UNSIGNED_LONG) {
+ assertThat(result, instanceOf(Long.class));
+ result = NumericUtils.unsignedLongAsBigInteger((Long) result);
+ }
+ return result;
+ }
+
/**
* Evaluates a {@link Block} of values, all copied from the input pattern, read directly from the page.
*
@@ -398,7 +410,7 @@ private void testEvaluateBlock(BlockFactory inputBlockFactory, DriverContext con
assertThat(toJavaObject(block, p), allNullsMatcher());
continue;
}
- assertThat(toJavaObject(block, p), testCase.getMatcher());
+ assertThat(toJavaObjectUnsignedLongAware(block, p), testCase.getMatcher());
}
assertThat(
"evaluates to tracked block",
@@ -472,7 +484,7 @@ public final void testEvaluateInManyThreads() throws ExecutionException, Interru
try (EvalOperator.ExpressionEvaluator eval = evalSupplier.get(driverContext())) {
for (int c = 0; c < count; c++) {
try (Block block = eval.eval(page)) {
- assertThat(toJavaObject(block, 0), testCase.getMatcher());
+ assertThat(toJavaObjectUnsignedLongAware(block, 0), testCase.getMatcher());
}
}
}
@@ -513,7 +525,12 @@ public final void testFold() {
expression = new FoldNull().rule(expression);
assertThat(expression.dataType(), equalTo(testCase.expectedType));
assertTrue(expression.foldable());
- assertThat(expression.fold(), testCase.getMatcher());
+ Object result = expression.fold();
+ // Decode unsigned longs into BigIntegers
+ if (testCase.expectedType == DataTypes.UNSIGNED_LONG && result != null) {
+ result = NumericUtils.unsignedLongAsBigInteger((Long) result);
+ }
+ assertThat(result, testCase.getMatcher());
if (testCase.getExpectedWarnings() != null) {
assertWarnings(testCase.getExpectedWarnings());
}
diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/TestCaseSupplier.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/TestCaseSupplier.java
index faf10d499127a..9eab8cbef5fed 100644
--- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/TestCaseSupplier.java
+++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/TestCaseSupplier.java
@@ -10,6 +10,8 @@
import org.apache.lucene.document.InetAddressPoint;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.network.InetAddresses;
+import org.elasticsearch.logging.LogManager;
+import org.elasticsearch.logging.Logger;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.esql.expression.function.scalar.convert.AbstractConvertFunction;
import org.elasticsearch.xpack.esql.type.EsqlDataTypes;
@@ -48,6 +50,8 @@
public record TestCaseSupplier(String name, List types, Supplier supplier)
implements
Supplier {
+
+ private static Logger logger = LogManager.getLogger(TestCaseSupplier.class);
/**
* Build a test case without types.
*
@@ -530,6 +534,8 @@ public static void unary(
supplier.type(),
"value"
);
+ logger.info("Value is " + value + " of type " + value.getClass());
+ logger.info("expectedValue is " + expectedValue.apply(value));
TestCase testCase = new TestCase(
List.of(typed),
expectedEvaluatorToString,
@@ -949,6 +955,9 @@ public TypedData(Object data, String name) {
@Override
public String toString() {
+ if (type == DataTypes.UNSIGNED_LONG && data instanceof Long longData) {
+ return type.toString() + "(" + NumericUtils.unsignedLongAsBigInteger(longData).toString() + ")";
+ }
return type.toString() + "(" + (data == null ? "null" : data.toString()) + ")";
}
}
diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToUnsignedLongTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToUnsignedLongTests.java
index 080424602703d..8d5ee002a8f78 100644
--- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToUnsignedLongTests.java
+++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToUnsignedLongTests.java
@@ -16,7 +16,6 @@
import org.elasticsearch.xpack.ql.expression.Expression;
import org.elasticsearch.xpack.ql.tree.Source;
import org.elasticsearch.xpack.ql.type.DataTypes;
-import org.elasticsearch.xpack.ql.util.NumericUtils;
import java.math.BigDecimal;
import java.math.BigInteger;
@@ -26,10 +25,7 @@
import java.util.function.Supplier;
import static org.elasticsearch.xpack.ql.type.DataTypeConverter.safeToUnsignedLong;
-import static org.elasticsearch.xpack.ql.util.NumericUtils.ONE_AS_UNSIGNED_LONG;
import static org.elasticsearch.xpack.ql.util.NumericUtils.UNSIGNED_LONG_MAX_AS_DOUBLE;
-import static org.elasticsearch.xpack.ql.util.NumericUtils.ZERO_AS_UNSIGNED_LONG;
-import static org.elasticsearch.xpack.ql.util.NumericUtils.asLongUnsigned;
public class ToUnsignedLongTests extends AbstractFunctionTestCase {
public ToUnsignedLongTests(@Name("TestCase") Supplier testCaseSupplier) {
@@ -47,7 +43,7 @@ public static Iterable