diff --git a/build.sbt b/build.sbt index b04aad2ee..ef1f2c0b9 100644 --- a/build.sbt +++ b/build.sbt @@ -127,6 +127,8 @@ lazy val pplSparkIntegration = (project in file("ppl-spark-integration")) "org.scalatest" %% "scalatest" % "3.2.15" % "test", "org.scalatest" %% "scalatest-flatspec" % "3.2.15" % "test", "org.scalatestplus" %% "mockito-4-6" % "3.2.15.0" % "test", + "org.junit.jupiter" % "junit-jupiter-api" % "5.9.0" % "test", + "org.junit.jupiter" % "junit-jupiter-engine" % "5.9.0" % "test", "com.stephenn" %% "scalatest-json-jsonassert" % "0.2.5" % "test", "com.github.sbt" % "junit-interface" % "0.13.3" % "test"), libraryDependencies ++= deps(sparkVersion), diff --git a/ppl-spark-integration/src/main/java/org/opensearch/sql/common/utils/StringUtils.java b/ppl-spark-integration/src/main/java/org/opensearch/sql/common/utils/StringUtils.java index 914bb1dfc..074c5a48e 100644 --- a/ppl-spark-integration/src/main/java/org/opensearch/sql/common/utils/StringUtils.java +++ b/ppl-spark-integration/src/main/java/org/opensearch/sql/common/utils/StringUtils.java @@ -67,8 +67,8 @@ public static String unquoteText(String text) { /** * Unquote Identifier which has ` as mark. * - * @param identifier identifier that possibly enclosed by double quotes or back ticks - * @return An unquoted string whose outer pair of (double/back-tick) quotes have been removed + * @param identifier identifier that possibly enclosed by backticks + * @return An unquoted string whose outer pair of backticks have been removed */ public static String unquoteIdentifier(String identifier) { if (isQuoted(identifier, "`")) { diff --git a/ppl-spark-integration/src/test/java/org/opensearch/sql/common/utils/StringUtilsTest.java b/ppl-spark-integration/src/test/java/org/opensearch/sql/common/utils/StringUtilsTest.java new file mode 100644 index 000000000..258397f46 --- /dev/null +++ b/ppl-spark-integration/src/test/java/org/opensearch/sql/common/utils/StringUtilsTest.java @@ -0,0 +1,54 @@ +package org.opensearch.sql.common.utils; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.opensearch.sql.common.utils.StringUtils.unquoteIdentifier; +import static org.opensearch.sql.common.utils.StringUtils.unquoteText; + +import org.junit.Test; + +public class StringUtilsTest { + @Test + public void unquoteIdentifierTest() { + assertEquals("test", unquoteIdentifier("test")); + assertEquals("test", unquoteIdentifier("`test`")); + + assertEquals("\"test\"", unquoteIdentifier("\"test\"")); + assertEquals("\'test\'", unquoteIdentifier("\'test\'")); + } + + @Test + public void unquoteTextTest() { + assertEquals("test", unquoteText("test")); + assertEquals("test", unquoteText("'test'")); + + assertEquals("test'", unquoteText("'test'''")); + assertEquals("test\"", unquoteText("\"test\"\"\"")); + + assertEquals("te``st", unquoteText("'te``st'")); + assertEquals("te``st", unquoteText("\"te``st\"")); + + assertEquals("te'st", unquoteText("'te''st'")); + assertEquals("te''st", unquoteText("\"te''st\"")); + + assertEquals("te\"\"st", unquoteText("'te\"\"st'")); + assertEquals("te\"st", unquoteText("\"te\"\"st\"")); + + assertEquals("''", unquoteText("''''''")); + assertEquals("\"\"", unquoteText("\"\"\"\"\"\"")); + + assertEquals("test'", unquoteText("'test''")); + + assertEquals("", unquoteText("")); + assertEquals("'", unquoteText("'")); + assertEquals("\"", unquoteText("\"")); + + assertEquals("hello'", unquoteText("'hello''")); + assertEquals("don't", unquoteText("'don't'")); + assertEquals("don\"t", unquoteText("\"don\"t\"")); + + assertEquals("hel\\lo'", unquoteText("'hel\\lo''")); + assertEquals("hel'lo", unquoteText("'hel'lo'")); + assertEquals("hel\"lo", unquoteText("\"hel\"lo\"")); + assertEquals("hel\\'\\lo", unquoteText("'hel\\\\''\\\\lo'")); + } +}