diff --git a/sql/api/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBaseParser.g4 b/sql/api/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBaseParser.g4 index 24a6fb7e6d988..d79131b1caf98 100644 --- a/sql/api/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBaseParser.g4 +++ b/sql/api/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBaseParser.g4 @@ -1436,8 +1436,8 @@ nonTrivialPrimitiveType | INTERVAL (fromYearMonth=(YEAR | MONTH) (TO to=MONTH)? | fromDayTime=(DAY | HOUR | MINUTE | SECOND) (TO to=(HOUR | MINUTE | SECOND))?)? - | TIMESTAMP (WITHOUT TIME ZONE)? - | TIME (LEFT_PAREN precision=integerValue RIGHT_PAREN)? (WITHOUT TIME ZONE)? + | TIMESTAMP (withLocalTimeZone | withoutTimeZone)? + | TIME (LEFT_PAREN precision=integerValue RIGHT_PAREN)? (withoutTimeZone)? | GEOGRAPHY LEFT_PAREN (srid=integerValue | any=ANY) RIGHT_PAREN | GEOMETRY LEFT_PAREN (srid=integerValue | any=ANY) RIGHT_PAREN ; @@ -1457,6 +1457,14 @@ trivialPrimitiveType | VARIANT ; +withLocalTimeZone + : WITH LOCAL TIME ZONE + ; + +withoutTimeZone + : WITHOUT TIME ZONE + ; + primitiveType : nonTrivialPrimitiveType | trivialPrimitiveType diff --git a/sql/api/src/main/scala/org/apache/spark/sql/catalyst/parser/DataTypeAstBuilder.scala b/sql/api/src/main/scala/org/apache/spark/sql/catalyst/parser/DataTypeAstBuilder.scala index 3be5cebae706f..43b93f8f3d060 100644 --- a/sql/api/src/main/scala/org/apache/spark/sql/catalyst/parser/DataTypeAstBuilder.scala +++ b/sql/api/src/main/scala/org/apache/spark/sql/catalyst/parser/DataTypeAstBuilder.scala @@ -349,10 +349,12 @@ class DataTypeAstBuilder extends SqlBaseParserBaseVisitor[AnyRef] with DataTypeE } else { CalendarIntervalType } + case TIMESTAMP if currentCtx.withLocalTimeZone() != null => + TimestampType + case TIMESTAMP if currentCtx.withoutTimeZone() != null => + TimestampNTZType case TIMESTAMP => - if (currentCtx.WITHOUT() == null) { - SqlApiConf.get.timestampType - } else TimestampNTZType + SqlApiConf.get.timestampType case TIME => val precision = if (currentCtx.precision == null) { TimeType.DEFAULT_PRECISION diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/DataTypeParserSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/DataTypeParserSuite.scala index 02a3814c65373..03dbf0a28663a 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/DataTypeParserSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/DataTypeParserSuite.scala @@ -64,6 +64,7 @@ class DataTypeParserSuite extends SparkFunSuite with SQLHelper { checkDataType("TIME(6)", TimeType(6)) checkDataType("TIME(6) WITHOUT TIME ZONE", TimeType(6)) checkDataType("timestamp", TimestampType) + checkDataType("TIMESTAMP WITH LOCAL TIME ZONE", TimestampType) checkDataType("TIMESTAMP WITHOUT TIME ZONE", TimestampNTZType) checkDataType("timestamp_ntz", TimestampNTZType) checkDataType("timestamp_ltz", TimestampType) @@ -158,9 +159,12 @@ class DataTypeParserSuite extends SparkFunSuite with SQLHelper { test("Set default timestamp type") { withSQLConf(SQLConf.TIMESTAMP_TYPE.key -> TimestampTypes.TIMESTAMP_NTZ.toString) { assert(parse("timestamp") === TimestampNTZType) + assert(parse("timestamp with local time zone") === TimestampType) + assert(parse("timestamp without time zone") === TimestampNTZType) } withSQLConf(SQLConf.TIMESTAMP_TYPE.key -> TimestampTypes.TIMESTAMP_LTZ.toString) { assert(parse("timestamp") === TimestampType) + assert(parse("timestamp with local time zone") === TimestampType) assert(parse("timestamp without time zone") === TimestampNTZType) } }