2222import co .elastic .clients .elasticsearch .ElasticsearchClient ;
2323import co .elastic .clients .elasticsearch ._helpers .esql .jdbc .ResultSetEsqlAdapter ;
2424import co .elastic .clients .elasticsearch ._helpers .esql .objects .ObjectsEsqlAdapter ;
25- import co .elastic .clients .elasticsearch .esql .EsqlFormat ;
2625import co .elastic .clients .json .JsonpMappingException ;
2726import co .elastic .clients .json .jackson .JacksonJsonpMapper ;
2827import co .elastic .clients .testkit .MockHttpClient ;
29- import co .elastic .clients .transport .endpoints .BinaryResponse ;
3028import org .junit .jupiter .api .Assertions ;
3129import org .junit .jupiter .api .Test ;
3230
3331import java .io .IOException ;
3432import java .sql .ResultSet ;
33+ import java .sql .SQLException ;
3534import java .sql .Types ;
35+ import java .util .List ;
3636
3737public class EsqlAdapterTest extends Assertions {
3838
@@ -120,11 +120,6 @@ public void testProfilingInfo() throws IOException {
120120 @ Test
121121 public void testObjectDeserializer () throws IOException {
122122
123- BinaryResponse response = esClient .esql ().query (q -> q
124- .query ("FROM foo" )
125- .format (EsqlFormat .Json )
126- );
127-
128123 Iterable <Data > data = esClient .esql ().query (
129124 new ObjectsEsqlAdapter <>(Data .class ),
130125 "FROM employees | STATS avg_salary = AVG(salary) by country"
@@ -151,4 +146,54 @@ public void testResultSetAdapter() throws Exception {
151146 System .out .println (resultSet .getDouble ("avg_salary" ) + " " + resultSet .getString (2 ));
152147 }
153148 }
149+
150+ @ Test
151+ public void testDenseVector () throws IOException , SQLException {
152+
153+ String jsonEmbeddings = "{\n " +
154+ " \" took\" : 8,\n " +
155+ " \" is_partial\" : false,\n " +
156+ " \" completion_time_in_millis\" : 1776348683193,\n " +
157+ " \" documents_found\" : 1,\n " +
158+ " \" values_loaded\" : 252725,\n " +
159+ " \" start_time_in_millis\" : 1776348683185,\n " +
160+ " \" expiration_time_in_millis\" : 1776780683134,\n " +
161+ " \" columns\" : [\n " +
162+ " {\n " +
163+ " \" name\" : \" content\" ,\n " +
164+ " \" type\" : \" text\" \n " +
165+ " },\n " +
166+ " {\n " +
167+ " \" name\" : \" content.keyword\" ,\n " +
168+ " \" type\" : \" keyword\" \n " +
169+ " },\n " +
170+ " {\n " +
171+ " \" name\" : \" embedding\" ,\n " +
172+ " \" type\" : \" dense_vector\" \n " +
173+ " }\n " +
174+ " ],\n " +
175+ " \" values\" : [\n " +
176+ "[\" some text\" ,\" id\" ,[0.1,0.2,0.3]]\n " +
177+ "]\n " +
178+ "}" ;
179+
180+ ElasticsearchClient esClient = new MockHttpClient ()
181+ .add ("/_query" , "application/json" , jsonEmbeddings )
182+ .client (new JacksonJsonpMapper ());
183+
184+ ResultSet resultSet = esClient .esql ().query (
185+ ResultSetEsqlAdapter .INSTANCE ,
186+ "FROM embeddings" );
187+
188+ assertEquals (3 , resultSet .getMetaData ().getColumnCount ());
189+ assertEquals (Types .VARCHAR , resultSet .getMetaData ().getColumnType (1 ));
190+ assertEquals (Types .VARCHAR , resultSet .getMetaData ().getColumnType (2 ));
191+ assertEquals (Types .ARRAY , resultSet .getMetaData ().getColumnType (3 ));
192+
193+ while (resultSet .next ()) {
194+ List vec = resultSet .getObject ("embedding" , List .class );
195+ assertEquals (3 ,vec .size ());
196+ System .out .println (resultSet .getString ("embedding" ));
197+ }
198+ }
154199}
0 commit comments