Github user wzhfy commented on a diff in the pull request: https://github.com/apache/spark/pull/12646#discussion_r120816635 --- Diff: sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala --- @@ -2651,4 +2652,28 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext { val e = intercept[AnalysisException](sql("SELECT nvl(1, 2, 3)")) assert(e.message.contains("Invalid number of arguments")) } + + test("TRIM function") { + val ae1 = intercept[ParseException]{ + sql("select LTRIM(BOTH 'S' FROM 'SS abc S')").head + } + assert(ae1.getMessage contains + "The specified function LTRIM doesn't support with option BOTH") + val ae2 = intercept[ParseException]{ + sql("select RTRIM(TRAILING 'S' FROM 'SS abc S')").head + } + assert(ae2.getMessage contains + "The specified function RTRIM doesn't support with option TRAILING") + val ae3 = intercept[ParseException]{ + sql("select TRIM(OVER 'S' AND 'SS abc S')").head + } + assert(ae3.getMessage contains + "Literals of type 'OVER' are currently not supported") + checkAnswer( + sql("SELECT TRIM(BOTH '@$%&( )abc' FROM '@ $ % & ()abc ' )"), Row("") :: Nil) + checkAnswer( + sql("SELECT TRIM(LEADING 'c []' FROM '[ ccccbcc ')"), Row("bcc ") :: Nil) + checkAnswer( + sql("SELECT TRIM(TRAILING 'c&^,.' FROM 'bc...,,,&&&ccc' )"), Row("b") :: Nil) --- End diff -- I just notice we should also be able to use ltrim in sql, It's equivalent to trim(leading ...). Can we also add test for it in sql query?
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org