Skip to content

Commit 8013e47

Browse files
committed
Add support for dense_vector in PositionToXContent and EsqlQueryResponseTests
1 parent 6bb8e62 commit 8013e47

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/PositionToXContent.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected XContentBuilder valueToXContent(XContentBuilder builder, ToXContent.Pa
7676
return builder.value(((IntBlock) block).getInt(valueIndex));
7777
}
7878
};
79-
case DOUBLE, COUNTER_DOUBLE -> new PositionToXContent(block) {
79+
case DOUBLE, COUNTER_DOUBLE, DENSE_VECTOR -> new PositionToXContent(block) {
8080
@Override
8181
protected XContentBuilder valueToXContent(XContentBuilder builder, ToXContent.Params params, int valueIndex)
8282
throws IOException {
@@ -182,13 +182,6 @@ protected XContentBuilder valueToXContent(XContentBuilder builder, ToXContent.Pa
182182
}
183183
}
184184
};
185-
case DENSE_VECTOR -> new PositionToXContent(block) {
186-
@Override
187-
protected XContentBuilder valueToXContent(XContentBuilder builder, ToXContent.Params params, int valueIndex)
188-
throws IOException {
189-
return builder.value(((DoubleBlock) block).getDouble(valueIndex));
190-
}
191-
};
192185
case DATE_PERIOD, TIME_DURATION, DOC_DATA_TYPE, TSID_DATA_TYPE, SHORT, BYTE, OBJECT, FLOAT, HALF_FLOAT, SCALED_FLOAT,
193186
PARTIAL_AGG -> throw new IllegalArgumentException("can't convert values of type [" + columnInfo.type() + "]");
194187
};

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/action/EsqlQueryResponseTests.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,10 +993,19 @@ static Page valuesToPage(BlockFactory blockFactory, List<ColumnInfoImpl> columns
993993
aggBuilder.sum().appendDouble(((Number) value).doubleValue());
994994
aggBuilder.count().appendInt(((Number) value).intValue());
995995
}
996+
case DENSE_VECTOR -> {
997+
DoubleBlock.Builder doubleBuilder = (DoubleBlock.Builder) builder;
998+
@SuppressWarnings("unchecked")
999+
List<Double> vector = (List<Double>) value;
1000+
doubleBuilder.beginPositionEntry();
1001+
for (Double v : vector) {
1002+
doubleBuilder.appendDouble(v);
1003+
}
1004+
doubleBuilder.endPositionEntry();
1005+
}
9961006
}
9971007
}
9981008
}
9991009
return new Page(results.stream().map(Block.Builder::build).toArray(Block[]::new));
10001010
}
1001-
10021011
}

0 commit comments

Comments
 (0)