Skip to content

Commit 59782e7

Browse files
committed
Improve tests, remove unsigned long
1 parent 7383dc9 commit 59782e7

File tree

3 files changed

+36
-168
lines changed

3 files changed

+36
-168
lines changed

x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToDenseVectorFromUnsignedLongEvaluator.java

Lines changed: 0 additions & 132 deletions
This file was deleted.

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToDenseVector.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
import static org.elasticsearch.xpack.esql.core.type.DataType.KEYWORD;
2929
import static org.elasticsearch.xpack.esql.core.type.DataType.LONG;
3030
import static org.elasticsearch.xpack.esql.core.type.DataType.TEXT;
31-
import static org.elasticsearch.xpack.esql.core.type.DataType.UNSIGNED_LONG;
3231
import static org.elasticsearch.xpack.esql.type.EsqlDataTypeConverter.stringToDouble;
33-
import static org.elasticsearch.xpack.esql.type.EsqlDataTypeConverter.unsignedLongToDouble;
3432

3533
public class ToDenseVector extends AbstractConvertFunction {
3634
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(
@@ -43,7 +41,6 @@ public class ToDenseVector extends AbstractConvertFunction {
4341
Map.entry(DENSE_VECTOR, (source, fieldEval) -> fieldEval),
4442
Map.entry(KEYWORD, ToDenseVectorFromStringEvaluator.Factory::new),
4543
Map.entry(TEXT, ToDenseVectorFromStringEvaluator.Factory::new),
46-
Map.entry(UNSIGNED_LONG, ToDenseVectorFromUnsignedLongEvaluator.Factory::new),
4744
Map.entry(LONG, ToDenseVectorFromLongEvaluator.Factory::new),
4845
Map.entry(INTEGER, ToDenseVectorFromIntEvaluator.Factory::new),
4946
Map.entry(DOUBLE, ToDenseVectorFromDoubleEvaluator.Factory::new)
@@ -57,7 +54,7 @@ public ToDenseVector(
5754
Source source,
5855
@Param(
5956
name = "field",
60-
type = { "keyword", "text", "double", "long", "unsigned_long", "integer", "float" },
57+
type = { "keyword", "text", "double", "long", "integer" },
6158
description = "Input multi-valued column or an expression."
6259
) Expression field
6360
) {
@@ -98,11 +95,6 @@ static float fromString(BytesRef in) {
9895
return (float) stringToDouble(in.utf8ToString());
9996
}
10097

101-
@ConvertEvaluator(extraName = "FromUnsignedLong")
102-
static float fromUnsignedLong(long l) {
103-
return (float) unsignedLongToDouble(l);
104-
}
105-
10698
@ConvertEvaluator(extraName = "FromLong")
10799
static float fromLong(long l) {
108100
return l;

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToDenseVectorTests.java

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99

1010
import com.carrotsearch.randomizedtesting.annotations.Name;
1111
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
12+
1213
import org.apache.lucene.util.BytesRef;
14+
import org.elasticsearch.test.ESTestCase;
1315
import org.elasticsearch.xpack.esql.core.expression.Expression;
1416
import org.elasticsearch.xpack.esql.core.tree.Source;
1517
import org.elasticsearch.xpack.esql.core.type.DataType;
1618
import org.elasticsearch.xpack.esql.expression.function.AbstractScalarFunctionTestCase;
1719
import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier;
1820

1921
import java.util.ArrayList;
22+
import java.util.Arrays;
2023
import java.util.List;
2124
import java.util.function.Supplier;
2225

@@ -36,41 +39,46 @@ public static Iterable<Object[]> parameters() {
3639
new TestCaseSupplier(
3740
"int",
3841
List.of(DataType.INTEGER),
39-
() -> new TestCaseSupplier.TestCase(
40-
List.of(
41-
new TestCaseSupplier.TypedData(
42-
1,
43-
DataType.INTEGER,
44-
"int"
45-
)
46-
),
47-
evaluatorName("Int", "i"),
48-
DataType.DENSE_VECTOR,
49-
equalTo(1.0f)
50-
)
42+
() -> {
43+
List<Integer> data = Arrays.asList(randomArray(1, 10, Integer[]::new, ESTestCase::randomInt));
44+
return new TestCaseSupplier.TestCase(
45+
List.of(
46+
new TestCaseSupplier.TypedData(
47+
data,
48+
DataType.INTEGER,
49+
"int"
50+
)
51+
),
52+
evaluatorName("Int", "i"),
53+
DataType.DENSE_VECTOR,
54+
equalTo(data.stream().map(Number::floatValue).toList())
55+
);
56+
}
5157
)
5258
);
5359

54-
// Multi-valued inputs
5560
suppliers.add(
5661
new TestCaseSupplier(
57-
"mv_long",
62+
"long",
5863
List.of(DataType.LONG),
59-
() -> new TestCaseSupplier.TestCase(
60-
List.of(
61-
new TestCaseSupplier.TypedData(
62-
List.of(1L, 2L, 3L),
63-
DataType.LONG,
64-
"mv_long"
65-
)
66-
),
67-
evaluatorName("Long", "l"),
68-
DataType.DENSE_VECTOR,
69-
equalTo(List.of(1.0f, 2.0f, 3.0f))
70-
)
64+
() -> {
65+
List<Long> data = Arrays.asList(randomArray(1, 10, Long[]::new, ESTestCase::randomLong));
66+
return new TestCaseSupplier.TestCase(
67+
List.of(
68+
new TestCaseSupplier.TypedData(
69+
data,
70+
DataType.LONG,
71+
"long"
72+
)
73+
),
74+
evaluatorName("Long", "l"),
75+
DataType.DENSE_VECTOR,
76+
equalTo(data.stream().map(Number::floatValue).toList())
77+
);
78+
}
7179
)
7280
);
73-
81+
7482
suppliers.add(
7583
new TestCaseSupplier(
7684
"mv_string",

0 commit comments

Comments
 (0)