Skip to content

Commit

Permalink
Fixed format bug
Browse files Browse the repository at this point in the history
Signed-off-by: Vamsi Manohar <[email protected]>
  • Loading branch information
vamsimanohar committed Mar 2, 2023
1 parent ac01ad5 commit 24e345a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.IOException;
import java.util.Locale;
import org.junit.Test;
import org.opensearch.sql.common.utils.StringUtils;

public class CsvFormatIT extends PPLIntegTestCase {

Expand All @@ -23,27 +24,27 @@ public void init() throws IOException {
public void sanitizeTest() throws IOException {
String result = executeCsvQuery(
String.format(Locale.ROOT, "source=%s | fields firstname, lastname", TEST_INDEX_BANK_CSV_SANITIZE));
assertEquals(
assertEquals(StringUtils.format(
"firstname,lastname%n"
+ "'+Amber JOHnny,Duke Willmington+%n"
+ "'-Hattie,Bond-%n"
+ "'=Nanette,Bates=%n"
+ "'@Dale,Adams@%n"
+ "\",Elinor\",\"Ratliff,,,\"%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(
assertEquals(StringUtils.format(
"firstname,lastname%n"
+ "+Amber JOHnny,Duke Willmington+%n"
+ "-Hattie,Bond-%n"
+ "=Nanette,Bates=%n"
+ "@Dale,Adams@%n"
+ "\",Elinor\",\"Ratliff,,,\"%n",
+ "\",Elinor\",\"Ratliff,,,\"%n"),
result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.IOException;
import java.util.Locale;
import org.junit.Test;
import org.opensearch.sql.common.utils.StringUtils;
import org.opensearch.sql.legacy.SQLIntegTestCase;

public class CsvFormatIT extends SQLIntegTestCase {
Expand All @@ -24,13 +25,13 @@ public void init() throws IOException {
public void sanitizeTest() {
String result = executeQuery(
String.format(Locale.ROOT, "SELECT firstname, lastname FROM %s", TEST_INDEX_BANK_CSV_SANITIZE), "csv");
assertEquals(
assertEquals(StringUtils.format(
"firstname,lastname%n"
+ "'+Amber JOHnny,Duke Willmington+%n"
+ "'-Hattie,Bond-%n"
+ "'=Nanette,Bates=%n"
+ "'@Dale,Adams@%n"
+ "\",Elinor\",\"Ratliff,,,\"%n",
+ "\",Elinor\",\"Ratliff,,,\"%n"),
result);
}

Expand All @@ -39,13 +40,13 @@ public void escapeSanitizeTest() {
String result = executeQuery(
String.format(Locale.ROOT, "SELECT firstname, lastname FROM %s", TEST_INDEX_BANK_CSV_SANITIZE),
"csv&sanitize=false");
assertEquals(
assertEquals(StringUtils.format(
"firstname,lastname%n"
+ "+Amber JOHnny,Duke Willmington+%n"
+ "-Hattie,Bond-%n"
+ "=Nanette,Bates=%n"
+ "@Dale,Adams@%n"
+ "\",Elinor\",\"Ratliff,,,\"%n",
+ "\",Elinor\",\"Ratliff,,,\"%n"),
result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.IOException;
import java.util.Locale;
import org.junit.Test;
import org.opensearch.sql.common.utils.StringUtils;
import org.opensearch.sql.legacy.SQLIntegTestCase;

public class RawFormatIT extends SQLIntegTestCase {
Expand All @@ -24,13 +25,13 @@ public void init() throws IOException {
public void rawFormatWithPipeFieldTest() {
String result = executeQuery(
String.format(Locale.ROOT, "SELECT firstname, lastname FROM %s", TEST_INDEX_BANK_RAW_SANITIZE), "raw");
assertEquals(
assertEquals(StringUtils.format(
"firstname|lastname%n"
+ "+Amber JOHnny|Duke Willmington+%n"
+ "-Hattie|Bond-%n"
+ "=Nanette|Bates=%n"
+ "@Dale|Adams@%n"
+ "@Elinor|\"Ratliff|||\"%n",
+ "@Elinor|\"Ratliff|||\"%n"),
result);
}

Expand Down

0 comments on commit 24e345a

Please sign in to comment.