From 0814fc48f552456da98d0472daa6007063aae1cb Mon Sep 17 00:00:00 2001 From: Kent Yao Date: Wed, 13 Nov 2019 23:27:18 +0800 Subject: [PATCH] fix '.111' --- .../spark/sql/catalyst/util/IntervalUtils.scala | 17 +++++++++++------ .../sql/execution/command/DDLParserSuite.scala | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/IntervalUtils.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/IntervalUtils.scala index f9560743d0a25..574e230222270 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/IntervalUtils.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/IntervalUtils.scala @@ -427,6 +427,12 @@ object IntervalUtils { state = TRIM_BEFORE_SIGN case TRIM_BEFORE_SIGN => trimToNextState(b, SIGN) case SIGN => + currentValue = 0 + fraction = 0 + // Sets the scale to an invalid value to track fraction presence + // in the BEGIN_UNIT_NAME state + fractionScale = -1 + state = TRIM_BEFORE_VALUE b match { case '-' => isNegative = true @@ -436,14 +442,13 @@ object IntervalUtils { i += 1 case _ if '0' <= b && b <= '9' => isNegative = false + case '.' => + isNegative = false + i += 1 + fractionScale = (NANOS_PER_SECOND / 10).toInt + state = VALUE_FRACTIONAL_PART case _ => exceptionWithState( s"Unrecognized sign '$nextWord'") } - currentValue = 0 - fraction = 0 - // Sets the scale to an invalid value to track fraction presence - // in the BEGIN_UNIT_NAME state - fractionScale = -1 - state = TRIM_BEFORE_VALUE case TRIM_BEFORE_VALUE => trimToNextState(b, VALUE) case VALUE => b match { diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLParserSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLParserSuite.scala index 5c3ddd3317d67..06d5e41078f5c 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLParserSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLParserSuite.scala @@ -789,7 +789,7 @@ class DDLParserSuite extends AnalysisTest with SharedSparkSession { assertError("select interval '23:61:15' hour to second", "minute 61 outside range [0, 59]") assertError("select interval '.1111111111' second", - "Invalid interval string") + "invalid value fractional part '1111111111'") } test("use native json_tuple instead of hive's UDTF in LATERAL VIEW") {