Github user ueshin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/21479#discussion_r192534591
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
 ---
    @@ -1206,6 +1206,41 @@ class AstBuilder(conf: SQLConf) extends 
SqlBaseBaseVisitor[AnyRef] with Logging
         new StringLocate(expression(ctx.substr), expression(ctx.str))
       }
     
    +  /**
    +   * 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 =>
    --- End diff --
    
    Do we need this try-catch?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to