Skip to content

Commit

Permalink
SPARK-2407: Added Parse of SQL SUBSTR()
Browse files Browse the repository at this point in the history
  • Loading branch information
chutium committed Jul 16, 2014
1 parent 632fb3d commit 1de83a7
Showing 1 changed file with 7 additions and 1 deletion.
Expand Up @@ -120,7 +120,7 @@ class SqlParser extends StandardTokenParsers with PackratParsers {
protected val WHERE = Keyword("WHERE")
protected val INTERSECT = Keyword("INTERSECT")
protected val EXCEPT = Keyword("EXCEPT")

protected val SUBSTR = Keyword("SUBSTR")

This comment has been minimized.

Copy link
@egraldlo

egraldlo Jul 16, 2014

do we need to add SUBSTRING keywords?

// Use reflection to find the reserved words defined in this class.
protected val reservedWords =
Expand Down Expand Up @@ -316,6 +316,12 @@ class SqlParser extends StandardTokenParsers with PackratParsers {
IF ~> "(" ~> expression ~ "," ~ expression ~ "," ~ expression <~ ")" ^^ {
case c ~ "," ~ t ~ "," ~ f => If(c,t,f)
} |
SUBSTR ~> "(" ~> expression ~ "," ~ expression <~ ")" ^^ {
case s ~ "," ~ p => Substring(s,p,Literal(Integer.MAX_VALUE))
} |
SUBSTR ~> "(" ~> expression ~ "," ~ expression ~ "," ~ expression <~ ")" ^^ {
case s ~ "," ~ p ~ "," ~ l => Substring(s,p,l)
} |
ident ~ "(" ~ repsep(expression, ",") <~ ")" ^^ {
case udfName ~ _ ~ exprs => UnresolvedFunction(udfName, exprs)
}
Expand Down

0 comments on commit 1de83a7

Please sign in to comment.