Skip to content

Commit

Permalink
Change to POSITION '(' substr=valueExpression IN str=valueExpression ')'
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyum committed Jun 14, 2017
1 parent 8cce02b commit d068604
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ primaryExpression
| CAST '(' expression AS dataType ')' #cast
| FIRST '(' expression (IGNORE NULLS)? ')' #first
| LAST '(' expression (IGNORE NULLS)? ')' #last
| POSITION '(' substr=valueExpression IN str=valueExpression ')' #position
| constant #constantDefault
| ASTERISK #star
| qualifiedName '.' ASTERISK #star
Expand All @@ -574,7 +575,6 @@ primaryExpression
| identifier #columnReference
| base=primaryExpression '.' fieldName=identifier #dereference
| '(' expression ')' #parenthesizedExpression
| POSITION '(' valueExpression IN valueExpression ')' #position
;

constant
Expand Down Expand Up @@ -852,7 +852,6 @@ MACRO: 'MACRO';
IGNORE: 'IGNORE';

IF: 'IF';

POSITION: 'POSITION';

EQ : '=' | '==';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ case class SubstringIndex(strExpr: Expression, delimExpr: Expression, countExpr:
4
> SELECT _FUNC_('bar', 'foobarbar', 5);
7
> SELECT POSITION('bar' in 'foobarbar');
> SELECT POSITION('bar' IN 'foobarbar');
4
""")
// scalastyle:on line.size.limit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ class AstBuilder(conf: SQLConf) extends SqlBaseBaseVisitor[AnyRef] with Logging
* Create a Position expression.
*/
override def visitPosition(ctx: PositionContext): Expression = withOrigin(ctx) {
StringLocate(expression(ctx.valueExpression(0)), expression(ctx.valueExpression(1)), Literal(1))
new StringLocate(expression(ctx.substr), expression(ctx.str))
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class TableIdentifierParserSuite extends SparkFunSuite {
"rollup", "row", "rows", "set", "smallint", "table", "timestamp", "to", "trigger",
"true", "truncate", "update", "user", "values", "with", "regexp", "rlike",
"bigint", "binary", "boolean", "current_date", "current_timestamp", "date", "double", "float",
"int", "smallint", "timestamp", "at")
"int", "smallint", "timestamp", "at", "position")

val hiveStrictNonReservedKeyword = Seq("anti", "full", "inner", "left", "semi", "right",
"natural", "union", "intersect", "except", "database", "on", "join", "cross", "select", "from",
Expand Down

0 comments on commit d068604

Please sign in to comment.