forked from opendistro-for-elasticsearch/sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CSV formatter in new engine (opendistro-for-elasticsearch#870)
* support csv format in new engine * skipped some IT cases that are not applicable in new engine * udpate * added escape option * added test for Format * update * update * added IT for ppl * added IT for ppl * added IT for ppl * added license header * added test for sql * added example in protocol doc * addressed comments * added responseParams override method to sql and ppl stats actions * added unit test cases * update * addressed comment * addressed comments
- Loading branch information
1 parent
6990732
commit 3dd9069
Showing
27 changed files
with
1,004 additions
and
39 deletions.
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
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
58 changes: 58 additions & 0 deletions
58
integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/ppl/CsvFormatIT.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,58 @@ | ||
/* | ||
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amazon.opendistroforelasticsearch.sql.ppl; | ||
|
||
import static com.amazon.opendistroforelasticsearch.sql.legacy.TestsConstants.TEST_INDEX_BANK_CSV_SANITIZE; | ||
|
||
import java.io.IOException; | ||
import java.util.Locale; | ||
import org.junit.Test; | ||
|
||
public class CsvFormatIT extends PPLIntegTestCase { | ||
|
||
@Override | ||
public void init() throws IOException { | ||
loadIndex(Index.BANK_CSV_SANITIZE); | ||
} | ||
|
||
@Test | ||
public void sanitizeTest() throws IOException { | ||
String result = executeCsvQuery( | ||
String.format(Locale.ROOT, "source=%s | fields firstname, lastname", TEST_INDEX_BANK_CSV_SANITIZE)); | ||
assertEquals( | ||
"firstname,lastname\n" | ||
+ "'+Amber JOHnny,Duke Willmington+\n" | ||
+ "'-Hattie,Bond-\n" | ||
+ "'=Nanette,Bates=\n" | ||
+ "'@Dale,Adams@\n" | ||
+ "\",Elinor\",\"Ratliff,,,\"\n", | ||
result); | ||
} | ||
|
||
@Test | ||
public void escapeSanitizeTest() throws IOException { | ||
String result = executeCsvQuery( | ||
String.format(Locale.ROOT, "source=%s | fields firstname, lastname", TEST_INDEX_BANK_CSV_SANITIZE), false); | ||
assertEquals( | ||
"firstname,lastname\n" | ||
+ "+Amber JOHnny,Duke Willmington+\n" | ||
+ "-Hattie,Bond-\n" | ||
+ "=Nanette,Bates=\n" | ||
+ "@Dale,Adams@\n" | ||
+ ",Elinor,Ratliff,,,\n", | ||
result); | ||
} | ||
} |
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
61 changes: 61 additions & 0 deletions
61
integ-test/src/test/java/com/amazon/opendistroforelasticsearch/sql/sql/CsvFormatIT.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,61 @@ | ||
/* | ||
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.amazon.opendistroforelasticsearch.sql.sql; | ||
|
||
import static com.amazon.opendistroforelasticsearch.sql.legacy.TestsConstants.TEST_INDEX_BANK_CSV_SANITIZE; | ||
|
||
import com.amazon.opendistroforelasticsearch.sql.legacy.SQLIntegTestCase; | ||
import java.io.IOException; | ||
import java.util.Locale; | ||
import org.junit.Test; | ||
|
||
public class CsvFormatIT extends SQLIntegTestCase { | ||
|
||
@Override | ||
public void init() throws IOException { | ||
loadIndex(Index.BANK_CSV_SANITIZE); | ||
} | ||
|
||
@Test | ||
public void sanitizeTest() { | ||
String result = executeQuery( | ||
String.format(Locale.ROOT, "SELECT firstname, lastname FROM %s", TEST_INDEX_BANK_CSV_SANITIZE), "csv"); | ||
assertEquals( | ||
"firstname,lastname\n" | ||
+ "'+Amber JOHnny,Duke Willmington+\n" | ||
+ "'-Hattie,Bond-\n" | ||
+ "'=Nanette,Bates=\n" | ||
+ "'@Dale,Adams@\n" | ||
+ "\",Elinor\",\"Ratliff,,,\"\n", | ||
result); | ||
} | ||
|
||
@Test | ||
public void escapeSanitizeTest() { | ||
String result = executeQuery( | ||
String.format(Locale.ROOT, "SELECT firstname, lastname FROM %s", TEST_INDEX_BANK_CSV_SANITIZE), | ||
"csv&sanitize=false"); | ||
assertEquals( | ||
"firstname,lastname\n" | ||
+ "+Amber JOHnny,Duke Willmington+\n" | ||
+ "-Hattie,Bond-\n" | ||
+ "=Nanette,Bates=\n" | ||
+ "@Dale,Adams@\n" | ||
+ ",Elinor,Ratliff,,,\n", | ||
result); | ||
} | ||
} |
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,10 @@ | ||
{"index":{"_id":"1"}} | ||
{"account_number":1,"balance":39225,"firstname":"+Amber JOHnny","lastname":"Duke Willmington+","age":32,"gender":"M","address":"880 Holmes Lane","employer":"Pyrami","email":"amberduke@pyrami.com","city":"Brogan","state":"IL", "male" : true, "birthdate" : "2017-10-23"} | ||
{"index":{"_id":"6"}} | ||
{"account_number":6,"balance":5686,"firstname":"-Hattie","lastname":"Bond-","age":36,"gender":"M","address":"671 Bristol Street","employer":"Netagy","email":"hattiebond@netagy.com","city":"Dante","state":"TN", "male" : true, "birthdate" : "2017-11-20"} | ||
{"index":{"_id":"13"}} | ||
{"account_number":13,"balance":32838,"firstname":"=Nanette","lastname":"Bates=","age":28,"gender":"F","address":"789 Madison Street","employer":"Quility","email":"nanettebates@quility.com","city":"Nogal","state":"VA", "male" : false, "birthdate" : "2018-06-23"} | ||
{"index":{"_id":"18"}} | ||
{"account_number":18,"balance":4180,"firstname":"@Dale","lastname":"Adams@","age":33,"gender":"M","address":"467 Hutchinson Court","employer":"Boink","email":"daleadams@boink.com","city":"Orick","state":"MD","male" : true, "birthdate" : 1542152000000} | ||
{"index":{"_id":"20"}} | ||
{"account_number":20,"balance":16418,"firstname":",Elinor","lastname":"Ratliff,,,","age":36,"gender":"M","address":"282 Kings Place","employer":"Scentric","email":"elinorratliff@scentric.com","city":"Ribera","state":"WA", "male" : true, "birthdate" : "2018-06-27"} |
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.