Skip to content

Commit

Permalink
Simplify visitInterval()
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGekk committed Apr 16, 2021
1 parent 8a3271c commit 9ebc83b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2315,14 +2315,11 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
override def visitInterval(ctx: IntervalContext): Literal = withOrigin(ctx) {
val calendarInterval = parseIntervalLiteral(ctx)
if (ctx.errorCapturingUnitToUnitInterval != null && !conf.legacyIntervalEnabled) {
if (calendarInterval.months != 0) {
if (calendarInterval.days != 0 || calendarInterval.microseconds != 0) {
throw QueryParsingErrors.mixedIntervalError(ctx)
}
Literal(calendarInterval.months, YearMonthIntervalType)
} else {
if (calendarInterval.months == 0) {
val micros = IntervalUtils.getDuration(calendarInterval, TimeUnit.MICROSECONDS)
Literal(micros, DayTimeIntervalType)
} else {
Literal(calendarInterval.months, YearMonthIntervalType)
}
} else {
Literal(calendarInterval, CalendarIntervalType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import org.antlr.v4.runtime.ParserRuleContext
import org.apache.spark.sql.catalyst.parser.ParseException
import org.apache.spark.sql.catalyst.parser.SqlBaseParser._
import org.apache.spark.sql.catalyst.trees.Origin
import org.apache.spark.sql.internal.SQLConf

/**
* Object for grouping all error messages of the query parsing.
Expand Down Expand Up @@ -368,10 +367,4 @@ object QueryParsingErrors {
new ParseException("LOCAL is supported only with file: scheme", ctx)
}

def mixedIntervalError(ctx: ParserRuleContext): Throwable = {
new ParseException(
"Mixing of year-month and day-time fields is not allowed. " +
s"Set '${SQLConf.LEGACY_INTERVAL_ENABLED.key}' to true to enable the legacy interval type " +
"which supports mixed fields.", ctx)
}
}

0 comments on commit 9ebc83b

Please sign in to comment.