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 .query .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
@@ -118,11 +118,6 @@ public void testProfilingInfo() throws IOException {
118118 @ Test
119119 public void testObjectDeserializer () throws IOException {
120120
121- BinaryResponse response = esClient .esql ().query (q -> q
122- .query ("FROM foo" )
123- .format (EsqlFormat .Json )
124- );
125-
126121 Iterable <Data > data = esClient .esql ().query (
127122 new ObjectsEsqlAdapter <>(Data .class ),
128123 "FROM employees | STATS avg_salary = AVG(salary) by country"
@@ -149,4 +144,54 @@ public void testResultSetAdapter() throws Exception {
149144 System .out .println (resultSet .getDouble ("avg_salary" ) + " " + resultSet .getString (2 ));
150145 }
151146 }
147+
148+ @ Test
149+ public void testDenseVector () throws IOException , SQLException {
150+
151+ String jsonEmbeddings = "{\n " +
152+ " \" took\" : 8,\n " +
153+ " \" is_partial\" : false,\n " +
154+ " \" completion_time_in_millis\" : 1776348683193,\n " +
155+ " \" documents_found\" : 1,\n " +
156+ " \" values_loaded\" : 252725,\n " +
157+ " \" start_time_in_millis\" : 1776348683185,\n " +
158+ " \" expiration_time_in_millis\" : 1776780683134,\n " +
159+ " \" columns\" : [\n " +
160+ " {\n " +
161+ " \" name\" : \" content\" ,\n " +
162+ " \" type\" : \" text\" \n " +
163+ " },\n " +
164+ " {\n " +
165+ " \" name\" : \" content.keyword\" ,\n " +
166+ " \" type\" : \" keyword\" \n " +
167+ " },\n " +
168+ " {\n " +
169+ " \" name\" : \" embedding\" ,\n " +
170+ " \" type\" : \" dense_vector\" \n " +
171+ " }\n " +
172+ " ],\n " +
173+ " \" values\" : [\n " +
174+ "[\" some text\" ,\" id\" ,[0.1,0.2,0.3]]\n " +
175+ "]\n " +
176+ "}" ;
177+
178+ ElasticsearchClient esClient = new MockHttpClient ()
179+ .add ("/_query" , "application/json" , jsonEmbeddings )
180+ .client (new JacksonJsonpMapper ());
181+
182+ ResultSet resultSet = esClient .esql ().query (
183+ ResultSetEsqlAdapter .INSTANCE ,
184+ "FROM embeddings" );
185+
186+ assertEquals (3 , resultSet .getMetaData ().getColumnCount ());
187+ assertEquals (Types .VARCHAR , resultSet .getMetaData ().getColumnType (1 ));
188+ assertEquals (Types .VARCHAR , resultSet .getMetaData ().getColumnType (2 ));
189+ assertEquals (Types .ARRAY , resultSet .getMetaData ().getColumnType (3 ));
190+
191+ while (resultSet .next ()) {
192+ List vec = resultSet .getObject ("embedding" , List .class );
193+ assertEquals (3 ,vec .size ());
194+ System .out .println (resultSet .getString ("embedding" ));
195+ }
196+ }
152197}
0 commit comments