|
15 | 15 | */
|
16 | 16 | package org.springframework.data.elasticsearch.client.elc;
|
17 | 17 |
|
18 |
| -import static org.springframework.data.elasticsearch.client.elc.JsonUtils.*; |
19 |
| -import static org.springframework.data.elasticsearch.client.elc.TypeUtils.*; |
20 |
| - |
21 |
| -import co.elastic.clients.elasticsearch._types.BulkIndexByScrollFailure; |
22 |
| -import co.elastic.clients.elasticsearch._types.ErrorCause; |
23 |
| -import co.elastic.clients.elasticsearch._types.Time; |
24 |
| -import co.elastic.clients.elasticsearch._types.query_dsl.Query; |
25 |
| -import co.elastic.clients.elasticsearch.cluster.ComponentTemplateSummary; |
26 |
| -import co.elastic.clients.elasticsearch.cluster.GetComponentTemplateResponse; |
27 |
| -import co.elastic.clients.elasticsearch.cluster.HealthResponse; |
28 |
| -import co.elastic.clients.elasticsearch.core.DeleteByQueryResponse; |
29 |
| -import co.elastic.clients.elasticsearch.core.GetScriptResponse; |
30 |
| -import co.elastic.clients.elasticsearch.core.UpdateByQueryResponse; |
31 |
| -import co.elastic.clients.elasticsearch.core.mget.MultiGetError; |
32 |
| -import co.elastic.clients.elasticsearch.core.mget.MultiGetResponseItem; |
33 |
| -import co.elastic.clients.elasticsearch.indices.*; |
34 |
| -import co.elastic.clients.elasticsearch.indices.get_index_template.IndexTemplateItem; |
35 |
| -import co.elastic.clients.elasticsearch.indices.get_mapping.IndexMappingRecord; |
36 |
| -import co.elastic.clients.json.JsonpMapper; |
| 18 | +import static org.springframework.data.elasticsearch.client.elc.JsonUtils.toJson; |
| 19 | +import static org.springframework.data.elasticsearch.client.elc.TypeUtils.removePrefixFromJson; |
| 20 | +import static org.springframework.data.elasticsearch.client.elc.TypeUtils.typeMapping; |
37 | 21 |
|
38 | 22 | import java.util.ArrayList;
|
39 | 23 | import java.util.HashMap;
|
|
61 | 45 | import org.springframework.data.elasticsearch.core.query.StringQuery;
|
62 | 46 | import org.springframework.data.elasticsearch.core.reindex.ReindexResponse;
|
63 | 47 | import org.springframework.data.elasticsearch.core.script.Script;
|
| 48 | +import org.springframework.data.elasticsearch.core.sql.SqlResponse; |
64 | 49 | import org.springframework.data.elasticsearch.support.DefaultStringObjectMap;
|
65 | 50 | import org.springframework.lang.Nullable;
|
66 | 51 | import org.springframework.util.Assert;
|
67 | 52 |
|
| 53 | +import co.elastic.clients.elasticsearch._types.BulkIndexByScrollFailure; |
| 54 | +import co.elastic.clients.elasticsearch._types.ErrorCause; |
| 55 | +import co.elastic.clients.elasticsearch._types.Time; |
| 56 | +import co.elastic.clients.elasticsearch._types.query_dsl.Query; |
| 57 | +import co.elastic.clients.elasticsearch.cluster.ComponentTemplateSummary; |
| 58 | +import co.elastic.clients.elasticsearch.cluster.GetComponentTemplateResponse; |
| 59 | +import co.elastic.clients.elasticsearch.cluster.HealthResponse; |
| 60 | +import co.elastic.clients.elasticsearch.core.DeleteByQueryResponse; |
| 61 | +import co.elastic.clients.elasticsearch.core.GetScriptResponse; |
| 62 | +import co.elastic.clients.elasticsearch.core.UpdateByQueryResponse; |
| 63 | +import co.elastic.clients.elasticsearch.core.mget.MultiGetError; |
| 64 | +import co.elastic.clients.elasticsearch.core.mget.MultiGetResponseItem; |
| 65 | +import co.elastic.clients.elasticsearch.indices.Alias; |
| 66 | +import co.elastic.clients.elasticsearch.indices.AliasDefinition; |
| 67 | +import co.elastic.clients.elasticsearch.indices.GetAliasResponse; |
| 68 | +import co.elastic.clients.elasticsearch.indices.GetIndexResponse; |
| 69 | +import co.elastic.clients.elasticsearch.indices.GetIndexTemplateResponse; |
| 70 | +import co.elastic.clients.elasticsearch.indices.GetIndicesSettingsResponse; |
| 71 | +import co.elastic.clients.elasticsearch.indices.GetMappingResponse; |
| 72 | +import co.elastic.clients.elasticsearch.indices.GetTemplateResponse; |
| 73 | +import co.elastic.clients.elasticsearch.indices.IndexSettings; |
| 74 | +import co.elastic.clients.elasticsearch.indices.IndexState; |
| 75 | +import co.elastic.clients.elasticsearch.indices.IndexTemplateSummary; |
| 76 | +import co.elastic.clients.elasticsearch.indices.TemplateMapping; |
| 77 | +import co.elastic.clients.elasticsearch.indices.get_index_template.IndexTemplateItem; |
| 78 | +import co.elastic.clients.elasticsearch.indices.get_mapping.IndexMappingRecord; |
| 79 | +import co.elastic.clients.elasticsearch.sql.QueryResponse; |
| 80 | +import co.elastic.clients.json.JsonData; |
| 81 | +import co.elastic.clients.json.JsonpMapper; |
| 82 | + |
68 | 83 | /**
|
69 | 84 | * Class to convert Elasticsearch responses into Spring Data Elasticsearch classes.
|
70 | 85 | *
|
@@ -536,6 +551,29 @@ public Script scriptResponse(GetScriptResponse response) {
|
536 | 551 | }
|
537 | 552 | // endregion
|
538 | 553 |
|
| 554 | + // region sql |
| 555 | + public SqlResponse sqlResponse(QueryResponse response) { |
| 556 | + SqlResponse.Builder builder = SqlResponse.builder(); |
| 557 | + builder.withRunning(Boolean.TRUE.equals(response.isRunning())) |
| 558 | + .withPartial(Boolean.TRUE.equals(response.isPartial())).withCursor(response.cursor()); |
| 559 | + |
| 560 | + final List<SqlResponse.Column> columns = response.columns().stream() |
| 561 | + .map(column -> new SqlResponse.Column(column.name(), column.type())).toList(); |
| 562 | + builder.withColumns(columns); |
| 563 | + |
| 564 | + for (List<JsonData> rowValues : response.rows()) { |
| 565 | + SqlResponse.Row.Builder rowBuilder = SqlResponse.Row.builder(); |
| 566 | + for (int idx = 0; idx < rowValues.size(); idx++) { |
| 567 | + rowBuilder.withValue(columns.get(idx), rowValues.get(idx).toJson()); |
| 568 | + } |
| 569 | + |
| 570 | + builder.withRow(rowBuilder.build()); |
| 571 | + } |
| 572 | + |
| 573 | + return builder.build(); |
| 574 | + } |
| 575 | + // end region |
| 576 | + |
539 | 577 | // region helper functions
|
540 | 578 |
|
541 | 579 | private long timeToLong(Time time) {
|
|
0 commit comments