Skip to content

Commit

Permalink
Added constructor for empty rawResponse
Browse files Browse the repository at this point in the history
Signed-off-by: Guian Gumpac <guian.gumpac@improving.com>
  • Loading branch information
GumpacG committed Mar 13, 2023
1 parent 682110f commit 5b6f36e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,31 @@ class QueryResponse {
private final Schema schema;
private final List<ExprValue> results;
private final String rawResponse;

/**
* Constructor for Query Response.
*
* @param schema schema of the query
* @param results list of expressions
* @param rawResponse raw response from OpenSearch server
*/
public QueryResponse(Schema schema, List<ExprValue> results, String rawResponse) {
this.schema = schema;
this.results = results;
this.rawResponse = rawResponse;
}

/**
* Constructor for Query Response.
*
* @param schema schema of the query
* @param results list of expressions
*/
public QueryResponse(Schema schema, List<ExprValue> results) {
this.schema = schema;
this.results = results;
this.rawResponse = "";
}
}

@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void execute(
while (plan.hasNext()) {
result.add(plan.next());
}
QueryResponse response = new QueryResponse(new Schema(new ArrayList<>()), new ArrayList<>(), "");
QueryResponse response = new QueryResponse(new Schema(new ArrayList<>()), new ArrayList<>());
listener.onResponse(response);
} catch (Exception e) {
listener.onFailure(e);
Expand Down
6 changes: 3 additions & 3 deletions ppl/src/test/java/org/opensearch/sql/ppl/PPLServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void cleanup() throws InterruptedException {
public void testExecuteShouldPass() {
doAnswer(invocation -> {
ResponseListener<QueryResponse> listener = invocation.getArgument(1);
listener.onResponse(new QueryResponse(schema, Collections.emptyList(), ""));
listener.onResponse(new QueryResponse(schema, Collections.emptyList()));
return null;
}).when(queryService).execute(any(), any());

Expand All @@ -87,7 +87,7 @@ public void onFailure(Exception e) {
public void testExecuteCsvFormatShouldPass() {
doAnswer(invocation -> {
ResponseListener<QueryResponse> listener = invocation.getArgument(1);
listener.onResponse(new QueryResponse(schema, Collections.emptyList(), ""));
listener.onResponse(new QueryResponse(schema, Collections.emptyList()));
return null;
}).when(queryService).execute(any(), any());

Expand Down Expand Up @@ -161,7 +161,7 @@ public void onFailure(Exception e) {
public void testPrometheusQuery() {
doAnswer(invocation -> {
ResponseListener<QueryResponse> listener = invocation.getArgument(1);
listener.onResponse(new QueryResponse(schema, Collections.emptyList(), ""));
listener.onResponse(new QueryResponse(schema, Collections.emptyList()));
return null;
}).when(queryService).execute(any(), any());

Expand Down
4 changes: 2 additions & 2 deletions sql/src/test/java/org/opensearch/sql/sql/SQLServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void cleanup() throws InterruptedException {
public void canExecuteSqlQuery() {
doAnswer(invocation -> {
ResponseListener<QueryResponse> listener = invocation.getArgument(1);
listener.onResponse(new QueryResponse(schema, Collections.emptyList(), ""));
listener.onResponse(new QueryResponse(schema, Collections.emptyList()));
return null;
}).when(queryService).execute(any(), any());

Expand All @@ -87,7 +87,7 @@ public void onFailure(Exception e) {
public void canExecuteCsvFormatRequest() {
doAnswer(invocation -> {
ResponseListener<QueryResponse> listener = invocation.getArgument(1);
listener.onResponse(new QueryResponse(schema, Collections.emptyList(), ""));
listener.onResponse(new QueryResponse(schema, Collections.emptyList()));
return null;
}).when(queryService).execute(any(), any());

Expand Down

0 comments on commit 5b6f36e

Please sign in to comment.