Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
dow -> dayofweek
  • Loading branch information
wangyum committed Jun 2, 2018
commit 0ad3dd75bc1a74ca88c9ace8899fd2729aaa16b5
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ nonReserved
| VIEW | REPLACE
| IF
| POSITION
| EXTRACT | YEAR | QUARTER | MONTH | WEEK | DAY | DOW | HOUR | MINUTE | SECOND
| EXTRACT
| NO | DATA
| START | TRANSACTION | COMMIT | ROLLBACK | IGNORE
| SORT | CLUSTER | DISTRIBUTE | UNSET | TBLPROPERTIES | SKEWED | STORED | DIRECTORIES | LOCATION
Expand Down Expand Up @@ -881,15 +881,6 @@ TRAILING: 'TRAILING';
IF: 'IF';
POSITION: 'POSITION';
EXTRACT: 'EXTRACT';
YEAR: 'YEAR';
QUARTER: 'QUARTER';
MONTH: 'MONTH';
WEEK: 'WEEK';
DAY: 'DAY';
DOW: 'DOW';
HOUR: 'HOUR';
MINUTE: 'MINUTE';
SECOND: 'SECOND';

EQ : '=' | '==';
NSEQ: '<=>';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1210,34 +1210,27 @@ class AstBuilder(conf: SQLConf) extends SqlBaseBaseVisitor[AnyRef] with Logging
* Create a Extract expression.
*/
override def visitExtract(ctx: ExtractContext): Expression = withOrigin(ctx) {
val extractType = ctx.field.getText.toUpperCase(Locale.ROOT)
try {
extractType match {
case "YEAR" =>
Year(expression(ctx.source))
case "QUARTER" =>
Quarter(expression(ctx.source))
case "MONTH" =>
Month(expression(ctx.source))
case "WEEK" =>
WeekOfYear(expression(ctx.source))
case "DAY" =>
DayOfMonth(expression(ctx.source))
case "DOW" =>
DayOfWeek(expression(ctx.source))
case "HOUR" =>
Hour(expression(ctx.source))
case "MINUTE" =>
Minute(expression(ctx.source))
case "SECOND" =>
Second(expression(ctx.source))
case other =>
throw new ParseException(s"Literals of type '$other' are currently not supported.", ctx)
}
} catch {
case e: IllegalArgumentException =>
val message = Option(e.getMessage).getOrElse(s"Exception parsing $extractType")
throw new ParseException(message, ctx)
ctx.field.getText.toUpperCase(Locale.ROOT) match {
case "YEAR" =>
Year(expression(ctx.source))
case "QUARTER" =>
Quarter(expression(ctx.source))
case "MONTH" =>
Month(expression(ctx.source))
case "WEEK" =>
WeekOfYear(expression(ctx.source))
case "DAY" =>
DayOfMonth(expression(ctx.source))
case "DAYOFWEEK" =>
DayOfWeek(expression(ctx.source))
case "HOUR" =>
Hour(expression(ctx.source))
case "MINUTE" =>
Minute(expression(ctx.source))
case "SECOND" =>
Second(expression(ctx.source))
case other =>
throw new ParseException(s"Literals of type '$other' are currently not supported.", ctx)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +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", "position", "both", "leading", "trailing",
"extract", "year", "quarter", "month", "week", "day", "dow", "hour", "minute", "second")
"int", "smallint", "timestamp", "at", "position", "both", "leading", "trailing", "extract")

val hiveStrictNonReservedKeyword = Seq("anti", "full", "inner", "left", "semi", "right",
"natural", "union", "intersect", "except", "database", "on", "join", "cross", "select", "from",
Expand Down
2 changes: 1 addition & 1 deletion sql/core/src/test/resources/sql-tests/inputs/extract.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ select extract(week from c) from t;

select extract(day from c) from t;

select extract(dow from c) from t;
select extract(dayofweek from c) from t;

select extract(hour from c) from t;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct<dayofmonth(CAST(c AS DATE)):int>


-- !query 6
select extract(dow from c) from t
select extract(dayofweek from c) from t
-- !query 6 schema
struct<dayofweek(CAST(c AS DATE)):int>
-- !query 6 output
Expand Down