Skip to content

Commit ea5b5a4

Browse files
committed
[SPARK-29941][SQL] Add ansi type aliases for char and decimal
1 parent 50f6d93 commit ea5b5a4

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,12 +2153,12 @@ class AstBuilder(conf: SQLConf) extends SqlBaseBaseVisitor[AnyRef] with Logging
21532153
case ("date", Nil) => DateType
21542154
case ("timestamp", Nil) => TimestampType
21552155
case ("string", Nil) => StringType
2156-
case ("char", length :: Nil) => CharType(length.getText.toInt)
2156+
case ("character" | "char", length :: Nil) => CharType(length.getText.toInt)
21572157
case ("varchar", length :: Nil) => VarcharType(length.getText.toInt)
21582158
case ("binary", Nil) => BinaryType
2159-
case ("decimal", Nil) => DecimalType.USER_DEFAULT
2160-
case ("decimal", precision :: Nil) => DecimalType(precision.getText.toInt, 0)
2161-
case ("decimal", precision :: scale :: Nil) =>
2159+
case ("decimal" | "dec", Nil) => DecimalType.USER_DEFAULT
2160+
case ("decimal" | "dec", precision :: Nil) => DecimalType(precision.getText.toInt, 0)
2161+
case ("decimal" | "dec", precision :: scale :: Nil) =>
21622162
DecimalType(precision.getText.toInt, scale.getText.toInt)
21632163
case ("interval", Nil) => CalendarIntervalType
21642164
case (dt, params) =>

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/DataTypeParserSuite.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,13 @@ class DataTypeParserSuite extends SparkFunSuite {
5151
checkDataType("dOUBle", DoubleType)
5252
checkDataType("decimal(10, 5)", DecimalType(10, 5))
5353
checkDataType("decimal", DecimalType.USER_DEFAULT)
54+
checkDataType("Dec(10, 5)", DecimalType(10, 5))
55+
checkDataType("deC", DecimalType.USER_DEFAULT)
5456
checkDataType("DATE", DateType)
5557
checkDataType("timestamp", TimestampType)
5658
checkDataType("string", StringType)
5759
checkDataType("ChaR(5)", StringType)
60+
checkDataType("ChaRacter(5)", StringType)
5861
checkDataType("varchAr(20)", StringType)
5962
checkDataType("cHaR(27)", StringType)
6063
checkDataType("BINARY", BinaryType)

0 commit comments

Comments
 (0)