-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new protocol for visualization response format (#251)
* added viz protocol, added tests and updated user manual Signed-off-by: chloe-zh <[email protected]> * changed version back to 1.1 Signed-off-by: chloe-zh <[email protected]> * update Signed-off-by: chloe-zh <[email protected]> * update Signed-off-by: chloe-zh <[email protected]>
- Loading branch information
Showing
8 changed files
with
618 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -382,3 +382,146 @@ Result set:: | |
|
||
'+firstname|'=lastname|address | ||
'Hattie|@Bond|"671 Bristol Street|, Dente, TN" | ||
|
||
|
||
Visualization Format | ||
==================== | ||
|
||
To support the Observability visualizations we also provide a new protocol that formats the data in columns for PPL. You can specify the format as "viz" to apply this format to your response, the response is formatted as compact json by default, for example:: | ||
|
||
>> curl -H 'Content-Type: application/json -X POST localhost:9200/_plugins/_ppl?format=viz' -d '{ | ||
"query": "source=accounts" | ||
}' | ||
|
||
Result set:: | ||
|
||
{"data":{"account_number":[1,6,13,18],"firstname":["Amber","Hattie","Nanette","Dale"],"address":["880 Holmes Lane","671 Bristol Street","789 Madison Street","467 Hutchinson Court"],"balance":[39225,5686,32838,4180],"gender":["M","M","F","M"],"city":["Brogan","Dante","Nogal","Orick"],"employer":["Pyrami","Netagy","Quility",null],"state":["IL","TN","VA","MD"],"age":[32,36,28,33],"email":["[email protected]","[email protected]","[email protected]","[email protected]"],"lastname":["Duke","Bond","Bates","Adams"]},"fields":[{"name":"account_number","type":"long"},{"name":"firstname","type":"text"},{"name":"address","type":"text"},{"name":"balance","type":"long"},{"name":"gender","type":"text"},{"name":"city","type":"text"},{"name":"employer","type":"text"},{"name":"state","type":"text"},{"name":"age","type":"long"},{"name":"email","type":"text"},{"name":"lastname","type":"text"}],"size":4,"status":200} | ||
|
||
|
||
You can also shape the format to pretty json by adding additional param ``pretty`` set it to true ``pretty=true``, for example:: | ||
|
||
>> curl -H 'Content-Type: application/json -X POST localhost:9200/_plugins/_ppl?format=viz&pretty' -d '{ | ||
"query": "source=accounts" | ||
}' | ||
|
||
Result set:: | ||
|
||
{ | ||
"data": { | ||
"account_number": [ | ||
1, | ||
6, | ||
13, | ||
18 | ||
], | ||
"firstname": [ | ||
"Amber", | ||
"Hattie", | ||
"Nanette", | ||
"Dale" | ||
], | ||
"address": [ | ||
"880 Holmes Lane", | ||
"671 Bristol Street", | ||
"789 Madison Street", | ||
"467 Hutchinson Court" | ||
], | ||
"balance": [ | ||
39225, | ||
5686, | ||
32838, | ||
4180 | ||
], | ||
"gender": [ | ||
"M", | ||
"M", | ||
"F", | ||
"M" | ||
], | ||
"city": [ | ||
"Brogan", | ||
"Dante", | ||
"Nogal", | ||
"Orick" | ||
], | ||
"employer": [ | ||
"Pyrami", | ||
"Netagy", | ||
"Quility", | ||
null | ||
], | ||
"state": [ | ||
"IL", | ||
"TN", | ||
"VA", | ||
"MD" | ||
], | ||
"age": [ | ||
32, | ||
36, | ||
28, | ||
33 | ||
], | ||
"email": [ | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]" | ||
], | ||
"lastname": [ | ||
"Duke", | ||
"Bond", | ||
"Bates", | ||
"Adams" | ||
] | ||
}, | ||
"fields": [ | ||
{ | ||
"name": "account_number", | ||
"type": "long" | ||
}, | ||
{ | ||
"name": "firstname", | ||
"type": "text" | ||
}, | ||
{ | ||
"name": "address", | ||
"type": "text" | ||
}, | ||
{ | ||
"name": "balance", | ||
"type": "long" | ||
}, | ||
{ | ||
"name": "gender", | ||
"type": "text" | ||
}, | ||
{ | ||
"name": "city", | ||
"type": "text" | ||
}, | ||
{ | ||
"name": "employer", | ||
"type": "text" | ||
}, | ||
{ | ||
"name": "state", | ||
"type": "text" | ||
}, | ||
{ | ||
"name": "age", | ||
"type": "long" | ||
}, | ||
{ | ||
"name": "email", | ||
"type": "text" | ||
}, | ||
{ | ||
"name": "lastname", | ||
"type": "text" | ||
} | ||
], | ||
"size": 4, | ||
"status": 200 | ||
} | ||
|
83 changes: 83 additions & 0 deletions
83
integ-test/src/test/java/org/opensearch/sql/ppl/VisualizationFormatIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
* | ||
*/ | ||
|
||
package org.opensearch.sql.ppl; | ||
|
||
import static org.opensearch.sql.legacy.TestUtils.getResponseBody; | ||
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BANK; | ||
import static org.opensearch.sql.plugin.rest.RestPPLQueryAction.QUERY_API_ENDPOINT; | ||
|
||
import java.io.IOException; | ||
import java.util.Locale; | ||
import org.junit.Assert; | ||
import org.junit.jupiter.api.Test; | ||
import org.opensearch.client.Request; | ||
import org.opensearch.client.Response; | ||
|
||
public class VisualizationFormatIT extends PPLIntegTestCase { | ||
@Override | ||
public void init() throws IOException { | ||
loadIndex(Index.BANK); | ||
} | ||
|
||
@Test | ||
void format() throws IOException { | ||
String result = executeVizQuery( | ||
String.format(Locale.ROOT, "source=%s | fields firstname, age", TEST_INDEX_BANK), true); | ||
assertEquals( | ||
"{\n" | ||
+ " \"data\": {\n" | ||
+ " \"firstname\": [\n" | ||
+ " \"Amber JOHnny\",\n" | ||
+ " \"Hattie\",\n" | ||
+ " \"Nanette\",\n" | ||
+ " \"Dale\",\n" | ||
+ " \"Elinor\",\n" | ||
+ " \"Virginia\",\n" | ||
+ " \"Dillard\"\n" | ||
+ " ],\n" | ||
+ " \"age\": [\n" | ||
+ " 32,\n" | ||
+ " 36,\n" | ||
+ " 28,\n" | ||
+ " 33,\n" | ||
+ " 36,\n" | ||
+ " 39,\n" | ||
+ " 34\n" | ||
+ " ]\n" | ||
+ " },\n" | ||
+ " \"metadata\": {\n" | ||
+ " \"fields\": [\n" | ||
+ " {\n" | ||
+ " \"name\": \"firstname\",\n" | ||
+ " \"type\": \"keyword\"\n" | ||
+ " },\n" | ||
+ " {\n" | ||
+ " \"name\": \"age\",\n" | ||
+ " \"type\": \"integer\"\n" | ||
+ " }\n" | ||
+ " ]\n" | ||
+ " },\n" | ||
+ " \"size\": 7,\n" | ||
+ " \"status\": 200\n" | ||
+ "}", | ||
result); | ||
} | ||
|
||
private String executeVizQuery(String query, boolean pretty) throws IOException { | ||
Request request = buildRequest(query, | ||
QUERY_API_ENDPOINT + String.format(Locale.ROOT, "?format=csv&pretty=%b", pretty)); | ||
Response response = client().performRequest(request); | ||
Assert.assertEquals(200, response.getStatusLine().getStatusCode()); | ||
return getResponseBody(response, true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.