Skip to content

Commit fb2a3c7

Browse files
committed
Add CSV tests and necessary infra for dense_vector field type
1 parent 891f4fc commit fb2a3c7

File tree

6 files changed

+38
-1
lines changed

6 files changed

+38
-1
lines changed

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvAssert.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import static org.elasticsearch.common.logging.LoggerMessageFormat.format;
3636
import static org.elasticsearch.xpack.esql.CsvTestUtils.ExpectedResults;
3737
import static org.elasticsearch.xpack.esql.CsvTestUtils.Type;
38+
import static org.elasticsearch.xpack.esql.CsvTestUtils.Type.DENSE_VECTOR;
3839
import static org.elasticsearch.xpack.esql.CsvTestUtils.Type.UNSIGNED_LONG;
3940
import static org.elasticsearch.xpack.esql.CsvTestUtils.logMetaData;
4041
import static org.elasticsearch.xpack.esql.core.util.DateUtils.UTC_DATE_TIME_FORMATTER;
@@ -145,6 +146,10 @@ private static void assertMetadata(
145146
// Type.asType translates all bytes references into keywords
146147
continue;
147148
}
149+
if (blockType == Type.DOUBLE && expectedType == DENSE_VECTOR) {
150+
// DENSE_VECTOR is internally represented as a double block
151+
continue;
152+
}
148153
if (blockType == Type.NULL) {
149154
// Null pages don't have any real type information beyond "it's all null, man"
150155
continue;

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvTestUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ public enum Type {
486486
x -> x == null ? null : stringToAggregateMetricDoubleLiteral(x),
487487
AggregateMetricDoubleBlockBuilder.AggregateMetricDoubleLiteral.class
488488
),
489+
DENSE_VECTOR(Double::parseDouble, Double.class),
489490
UNSUPPORTED(Type::convertUnsupported, Void.class);
490491

491492
private static Void convertUnsupported(String s) {
@@ -528,6 +529,8 @@ private static Void convertUnsupported(String s) {
528529
LOOKUP.put("DATE", DATETIME);
529530
LOOKUP.put("DT", DATETIME);
530531
LOOKUP.put("V", VERSION);
532+
533+
LOOKUP.put("DENSE_VECTOR", DENSE_VECTOR);
531534
}
532535

533536
private final Function<String, Object> converter;

x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvTestsDataLoader.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ public class CsvTestsDataLoader {
140140
private static final TestDataset SEMANTIC_TEXT = new TestDataset("semantic_text").withInferenceEndpoint(true);
141141
private static final TestDataset LOGS = new TestDataset("logs");
142142
private static final TestDataset MV_TEXT = new TestDataset("mv_text");
143+
private static final TestDataset DENSE_VECTOR = new TestDataset("dense_vector");
143144

144145
public static final Map<String, TestDataset> CSV_DATASET_MAP = Map.ofEntries(
145146
Map.entry(EMPLOYEES.indexName, EMPLOYEES),
@@ -198,7 +199,8 @@ public class CsvTestsDataLoader {
198199
Map.entry(BOOKS.indexName, BOOKS),
199200
Map.entry(SEMANTIC_TEXT.indexName, SEMANTIC_TEXT),
200201
Map.entry(LOGS.indexName, LOGS),
201-
Map.entry(MV_TEXT.indexName, MV_TEXT)
202+
Map.entry(MV_TEXT.indexName, MV_TEXT),
203+
Map.entry(DENSE_VECTOR.indexName, DENSE_VECTOR)
202204
);
203205

204206
private static final EnrichConfig LANGUAGES_ENRICH = new EnrichConfig("languages_policy", "enrich-policy-languages.json");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
id:l, vector:dense_vector
2+
0, [1.0, 2.0, 3.0]
3+
1, [4.0, 5.0, 6.0]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
retrieveDenseVectorData
3+
required_capability: dense_vector_field_type
4+
5+
FROM dense_vector
6+
| KEEP id, vector
7+
| SORT id
8+
;
9+
10+
id:l | vector:dense_vector
11+
0 | [1.0, 2.0, 3.0]
12+
1 | [4.0, 5.0, 6.0]
13+
;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"properties": {
3+
"id": {
4+
"type": "long"
5+
},
6+
"vector": {
7+
"type": "dense_vector",
8+
"similarity": "l2_norm"
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)