Skip to content

Commit e13d6f1

Browse files
committed
Polishing.
Signed-off-by: Youssef Aouichaoui <[email protected]>
1 parent ebe9a8f commit e13d6f1

File tree

11 files changed

+6
-136
lines changed

11 files changed

+6
-136
lines changed

src/main/java/org/springframework/data/elasticsearch/client/elc/ElasticsearchTemplate.java

-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.springframework.data.elasticsearch.client.elc;
1717

1818
import static org.springframework.data.elasticsearch.client.elc.TypeUtils.*;
19-
import static org.springframework.data.elasticsearch.core.sql.types.ResponseFormat.json;
2019

2120
import co.elastic.clients.elasticsearch.ElasticsearchClient;
2221
import co.elastic.clients.elasticsearch._types.Time;
@@ -667,8 +666,6 @@ public boolean deleteScript(String name) {
667666
@Override
668667
public SqlResponse search(SqlQuery query) {
669668
Assert.notNull(query, "Query must not be null.");
670-
Assert.isTrue(query.getFormat() == null || json.equals(query.getFormat()),
671-
"The Elasticsearch Java Client only supports JSON format.");
672669

673670
try {
674671
QueryResponse response = sqlClient.query(requestConverter.sqlQueryRequest(query));

src/main/java/org/springframework/data/elasticsearch/client/elc/ReactiveElasticsearchTemplate.java

-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import static co.elastic.clients.util.ApiTypeHelper.*;
1919
import static org.springframework.data.elasticsearch.client.elc.TypeUtils.*;
20-
import static org.springframework.data.elasticsearch.core.sql.types.ResponseFormat.json;
2120

2221
import co.elastic.clients.elasticsearch._types.Result;
2322
import co.elastic.clients.elasticsearch.core.*;
@@ -654,8 +653,6 @@ public BaseQueryBuilder queryBuilderWithIds(List<String> ids) {
654653
@Override
655654
public Mono<SqlResponse> search(SqlQuery query) {
656655
Assert.notNull(query, "Query must not be null.");
657-
Assert.isTrue(query.getFormat() == null || json.equals(query.getFormat()),
658-
"The Elasticsearch Java Client only supports JSON format.");
659656

660657
co.elastic.clients.elasticsearch.sql.QueryRequest request = requestConverter.sqlQueryRequest(query);
661658
return sqlClient.query(request).onErrorMap(this::translateException).map(responseConverter::sqlResponse);

src/main/java/org/springframework/data/elasticsearch/client/elc/RequestConverter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ public co.elastic.clients.elasticsearch.sql.QueryRequest sqlQueryRequest(SqlQuer
541541
.keepOnCompletion(query.getKeepOnCompletion()).pageTimeout(time(query.getPageTimeout()))
542542
.requestTimeout(time(query.getRequestTimeout()))
543543
.waitForCompletionTimeout(time(query.getWaitForCompletionTimeout())).filter(getQuery(query.getFilter(), null))
544-
.timeZone(Objects.toString(query.getTimeZone(), null)).format(Objects.toString(query.getFormat(), null));
544+
.timeZone(Objects.toString(query.getTimeZone(), null)).format("json");
545545

546546
return sqb;
547547
});

src/main/java/org/springframework/data/elasticsearch/core/query/SqlQuery.java

-65
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,11 @@
1515
*/
1616
package org.springframework.data.elasticsearch.core.query;
1717

18-
import static org.springframework.data.elasticsearch.core.sql.types.ResponseFormat.cbor;
19-
import static org.springframework.data.elasticsearch.core.sql.types.ResponseFormat.csv;
20-
import static org.springframework.data.elasticsearch.core.sql.types.ResponseFormat.json;
21-
import static org.springframework.data.elasticsearch.core.sql.types.ResponseFormat.smile;
22-
import static org.springframework.data.elasticsearch.core.sql.types.ResponseFormat.yaml;
23-
2418
import java.time.Duration;
2519
import java.util.ArrayList;
2620
import java.util.List;
2721
import java.util.TimeZone;
2822

29-
import org.springframework.data.elasticsearch.core.sql.types.ResponseFormat;
3023
import org.springframework.lang.Nullable;
3124
import org.springframework.util.Assert;
3225

@@ -38,20 +31,6 @@
3831
* @since 5.4
3932
*/
4033
public class SqlQuery {
41-
/**
42-
* Separator for CSV results.
43-
* <p>
44-
* Default, this is set to {@code ,}.
45-
*/
46-
@Nullable private final String delimiter;
47-
48-
/**
49-
* The format for the response, such as csv, json, txt, can be viewed at the {@link ResponseFormat}. The java client
50-
* of Elasticsearch only supports JSON. See {@link co.elastic.clients.transport.JsonEndpoint}
51-
* <p>
52-
* Default, this is set to {@code json}.
53-
*/
54-
@Nullable private final ResponseFormat format;
5534

5635
/**
5736
* If true, returns partial results if there are shard request timeouts or shard failures.
@@ -157,9 +136,6 @@ public class SqlQuery {
157136
@Nullable private final Duration waitForCompletionTimeout;
158137

159138
private SqlQuery(Builder builder) {
160-
this.delimiter = builder.delimiter;
161-
this.format = builder.format;
162-
163139
this.allowPartialSearchResults = builder.allowPartialSearchResults;
164140

165141
this.catalog = builder.catalog;
@@ -185,16 +161,6 @@ private SqlQuery(Builder builder) {
185161
this.waitForCompletionTimeout = builder.waitForCompletionTimeout;
186162
}
187163

188-
@Nullable
189-
public String getDelimiter() {
190-
return delimiter;
191-
}
192-
193-
@Nullable
194-
public ResponseFormat getFormat() {
195-
return format;
196-
}
197-
198164
@Nullable
199165
public Boolean getAllowPartialSearchResults() {
200166
return allowPartialSearchResults;
@@ -279,9 +245,6 @@ public static Builder builder(String query) {
279245
}
280246

281247
public static class Builder {
282-
@Nullable private String delimiter;
283-
@Nullable private ResponseFormat format;
284-
285248
@Nullable private Boolean allowPartialSearchResults;
286249

287250
@Nullable private String catalog;
@@ -313,24 +276,6 @@ private Builder(String query) {
313276
this.query = query;
314277
}
315278

316-
/**
317-
* Separator for CSV results.
318-
*/
319-
public Builder withDelimiter(String delimiter) {
320-
this.delimiter = delimiter;
321-
322-
return this;
323-
}
324-
325-
/**
326-
* The format for the response, such as csv, json, txt, can be viewed at the {@link ResponseFormat}.
327-
*/
328-
public Builder withFormat(ResponseFormat format) {
329-
this.format = format;
330-
331-
return this;
332-
}
333-
334279
/**
335280
* If true, returns partial results if there are shard request timeouts or shard failures.
336281
*/
@@ -482,16 +427,6 @@ public Builder withWaitForCompletionTimeout(Duration waitForCompletionTimeout) {
482427
}
483428

484429
public SqlQuery build() {
485-
if (Boolean.TRUE.equals(columnar)) {
486-
if (!(cbor.equals(format) || json.equals(format) || smile.equals(format) || yaml.equals(format))) {
487-
throw new IllegalArgumentException("Columnar format support only YAML, CBOR, JSON and SMILE.");
488-
}
489-
}
490-
491-
if (delimiter != null && !csv.equals(format)) {
492-
throw new IllegalArgumentException("Delimiter support is only available for CSV responses.");
493-
}
494-
495430
return new SqlQuery(this);
496431
}
497432
}

src/main/java/org/springframework/data/elasticsearch/core/sql/ReactiveSqlOperations.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
public interface ReactiveSqlOperations {
3030
/**
31-
* Execute the criteria {@code query} against elasticsearch and return result as {@link SqlResponse}
31+
* Execute the sql {@code query} against elasticsearch and return result as {@link SqlResponse}
3232
*
3333
* @param query the query to execute
3434
* @return {@link SqlResponse} containing the list of found objects

src/main/java/org/springframework/data/elasticsearch/core/sql/SqlOperations.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
public interface SqlOperations {
2828
/**
29-
* Execute the criteria {@code query} against elasticsearch and return result as {@link SqlResponse}
29+
* Execute the sql {@code query} against elasticsearch and return result as {@link SqlResponse}
3030
*
3131
* @param query the query to execute
3232
* @return {@link SqlResponse} containing the list of found objects

src/main/java/org/springframework/data/elasticsearch/core/sql/SqlResponse.java

-12
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,6 @@ public JsonValue get(Column column) {
121121
return row.get(column);
122122
}
123123

124-
/**
125-
* This method should attempt to convert the SQL response into a document if the columns selected in an SQL query
126-
* correspond to the fields in the document.
127-
*
128-
* @param documentClass The class that represents the document.
129-
* @return an instance of Document {@link T}.
130-
* @param <T> Document type.
131-
*/
132-
public <T> T toDocument(Class<T> documentClass) {
133-
throw new UnsupportedOperationException("Not implemented yet.");
134-
}
135-
136124
public static class Builder {
137125
private final Map<Column, JsonValue> row = new HashMap<>();
138126

src/main/java/org/springframework/data/elasticsearch/core/sql/types/ResponseFormat.java

-29
This file was deleted.

src/main/java/org/springframework/data/elasticsearch/core/sql/types/package-info.java

-4
This file was deleted.

src/test/java/org/springframework/data/elasticsearch/core/sql/ReactiveSqlOperationsIntegrationTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void tearDown() {
7272
static class Config {}
7373
// end region
7474

75-
@Test
75+
@Test // #2683
7676
void when_search_with_an_sql_query() {
7777
// Given
7878
SqlQuery query = SqlQuery.builder("SELECT * FROM entity_for_sql WHERE views = 0").build();

src/test/java/org/springframework/data/elasticsearch/core/sql/SqlOperationsIntegrationTests.java

+2-16
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import static org.junit.jupiter.api.Assertions.assertEquals;
2020
import static org.junit.jupiter.api.Assertions.assertFalse;
2121
import static org.junit.jupiter.api.Assertions.assertNotNull;
22-
import static org.junit.jupiter.api.Assertions.assertThrows;
23-
import static org.springframework.data.elasticsearch.core.sql.types.ResponseFormat.yaml;
2422

2523
import org.junit.jupiter.api.AfterEach;
2624
import org.junit.jupiter.api.BeforeEach;
@@ -75,7 +73,7 @@ void tearDown() {
7573
static class Config {}
7674
// end region
7775

78-
@Test
76+
@Test // #2683
7977
void when_search_with_an_sql_query() {
8078
// Given
8179
SqlQuery query = SqlQuery.builder("SELECT * FROM entity_for_sql WHERE views = 0").build();
@@ -89,19 +87,7 @@ void when_search_with_an_sql_query() {
8987
assertEquals(1, response.getRows().size());
9088
}
9189

92-
@Test
93-
void when_search_with_an_sql_query_and_txt_format() {
94-
// Given
95-
SqlQuery query = SqlQuery.builder("SELECT * FROM entity_for_sql WHERE views = 0").withFormat(yaml).build();
96-
97-
// When
98-
99-
// Then
100-
assertThrows(IllegalArgumentException.class, () -> operations.search(query),
101-
"The Elasticsearch Java Client only supports JSON format.");
102-
}
103-
104-
@Test
90+
@Test // #2683
10591
void when_search_with_an_sql_query_that_has_aggregated_column() {
10692
// Given
10793
SqlQuery query = SqlQuery.builder("SELECT SUM(views) AS TOTAL FROM entity_for_sql").build();

0 commit comments

Comments
 (0)