Skip to content

Commit 1de83a7

Browse files
committed
SPARK-2407: Added Parse of SQL SUBSTR()
1 parent 632fb3d commit 1de83a7

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/SqlParser.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class SqlParser extends StandardTokenParsers with PackratParsers {
120120
protected val WHERE = Keyword("WHERE")
121121
protected val INTERSECT = Keyword("INTERSECT")
122122
protected val EXCEPT = Keyword("EXCEPT")
123-
123+
protected val SUBSTR = Keyword("SUBSTR")
124124

125125
// Use reflection to find the reserved words defined in this class.
126126
protected val reservedWords =
@@ -316,6 +316,12 @@ class SqlParser extends StandardTokenParsers with PackratParsers {
316316
IF ~> "(" ~> expression ~ "," ~ expression ~ "," ~ expression <~ ")" ^^ {
317317
case c ~ "," ~ t ~ "," ~ f => If(c,t,f)
318318
} |
319+
SUBSTR ~> "(" ~> expression ~ "," ~ expression <~ ")" ^^ {
320+
case s ~ "," ~ p => Substring(s,p,Literal(Integer.MAX_VALUE))
321+
} |
322+
SUBSTR ~> "(" ~> expression ~ "," ~ expression ~ "," ~ expression <~ ")" ^^ {
323+
case s ~ "," ~ p ~ "," ~ l => Substring(s,p,l)
324+
} |
319325
ident ~ "(" ~ repsep(expression, ",") <~ ")" ^^ {
320326
case udfName ~ _ ~ exprs => UnresolvedFunction(udfName, exprs)
321327
}

0 commit comments

Comments
 (0)