77
88package org .elasticsearch .xpack .esql .expression .function .scalar .convert ;
99
10- import org .apache .lucene .util .BytesRef ;
1110import org .elasticsearch .common .io .stream .NamedWriteableRegistry ;
1211import org .elasticsearch .common .io .stream .StreamInput ;
1312import org .elasticsearch .compute .ann .ConvertEvaluator ;
1413import org .elasticsearch .xpack .esql .core .expression .Expression ;
1514import org .elasticsearch .xpack .esql .core .tree .NodeInfo ;
1615import org .elasticsearch .xpack .esql .core .tree .Source ;
1716import org .elasticsearch .xpack .esql .core .type .DataType ;
17+ import org .elasticsearch .xpack .esql .expression .function .Example ;
1818import org .elasticsearch .xpack .esql .expression .function .FunctionInfo ;
1919import org .elasticsearch .xpack .esql .expression .function .Param ;
2020
2525import static org .elasticsearch .xpack .esql .core .type .DataType .DENSE_VECTOR ;
2626import static org .elasticsearch .xpack .esql .core .type .DataType .DOUBLE ;
2727import static org .elasticsearch .xpack .esql .core .type .DataType .INTEGER ;
28- import static org .elasticsearch .xpack .esql .core .type .DataType .KEYWORD ;
2928import static org .elasticsearch .xpack .esql .core .type .DataType .LONG ;
30- import static org .elasticsearch .xpack .esql .core .type .DataType .TEXT ;
31- import static org .elasticsearch .xpack .esql .type .EsqlDataTypeConverter .stringToDouble ;
3229
3330public class ToDenseVector extends AbstractConvertFunction {
3431 public static final NamedWriteableRegistry .Entry ENTRY = new NamedWriteableRegistry .Entry (
@@ -39,23 +36,22 @@ public class ToDenseVector extends AbstractConvertFunction {
3936
4037 private static final Map <DataType , BuildFactory > EVALUATORS = Map .ofEntries (
4138 Map .entry (DENSE_VECTOR , (source , fieldEval ) -> fieldEval ),
42- Map .entry (KEYWORD , ToDenseVectorFromStringEvaluator .Factory ::new ),
43- Map .entry (TEXT , ToDenseVectorFromStringEvaluator .Factory ::new ),
4439 Map .entry (LONG , ToDenseVectorFromLongEvaluator .Factory ::new ),
4540 Map .entry (INTEGER , ToDenseVectorFromIntEvaluator .Factory ::new ),
4641 Map .entry (DOUBLE , ToDenseVectorFromDoubleEvaluator .Factory ::new )
4742 );
4843
4944 @ FunctionInfo (
5045 returnType = "dense_vector" ,
51- description = "Converts a multi-valued input of numbers or strings to a dense_vector."
46+ description = "Converts a multi-valued input of numbers to a dense_vector." ,
47+ examples = @ Example (file = "dense_vector" , tag = "to_dense_vector-ints" )
5248 )
5349 public ToDenseVector (
5450 Source source ,
5551 @ Param (
5652 name = "field" ,
57- type = { "keyword" , "text" , " double" , "long" , "integer" },
58- description = "Input multi-valued column or an expression ."
53+ type = {" double" , "long" , "integer" },
54+ description = "multi-valued input of numbers to convert ."
5955 ) Expression field
6056 ) {
6157 super (source , field );
@@ -90,11 +86,6 @@ protected NodeInfo<? extends Expression> info() {
9086 return NodeInfo .create (this , ToDenseVector ::new , field ());
9187 }
9288
93- @ ConvertEvaluator (extraName = "FromString" , warnExceptions = { org .elasticsearch .xpack .esql .core .InvalidArgumentException .class })
94- static float fromString (BytesRef in ) {
95- return (float ) stringToDouble (in .utf8ToString ());
96- }
97-
9889 @ ConvertEvaluator (extraName = "FromLong" )
9990 static float fromLong (long l ) {
10091 return l ;
0 commit comments