Skip to content

Commit

Permalink
[SPARK-29941][SQL] Add ansi type aliases for char and decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
yaooqinn committed Nov 18, 2019
1 parent 50f6d93 commit ea5b5a4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Expand Up @@ -2153,12 +2153,12 @@ class AstBuilder(conf: SQLConf) extends SqlBaseBaseVisitor[AnyRef] with Logging
case ("date", Nil) => DateType
case ("timestamp", Nil) => TimestampType
case ("string", Nil) => StringType
case ("char", length :: Nil) => CharType(length.getText.toInt)
case ("character" | "char", length :: Nil) => CharType(length.getText.toInt)
case ("varchar", length :: Nil) => VarcharType(length.getText.toInt)
case ("binary", Nil) => BinaryType
case ("decimal", Nil) => DecimalType.USER_DEFAULT
case ("decimal", precision :: Nil) => DecimalType(precision.getText.toInt, 0)
case ("decimal", precision :: scale :: Nil) =>
case ("decimal" | "dec", Nil) => DecimalType.USER_DEFAULT
case ("decimal" | "dec", precision :: Nil) => DecimalType(precision.getText.toInt, 0)
case ("decimal" | "dec", precision :: scale :: Nil) =>
DecimalType(precision.getText.toInt, scale.getText.toInt)
case ("interval", Nil) => CalendarIntervalType
case (dt, params) =>
Expand Down
Expand Up @@ -51,10 +51,13 @@ class DataTypeParserSuite extends SparkFunSuite {
checkDataType("dOUBle", DoubleType)
checkDataType("decimal(10, 5)", DecimalType(10, 5))
checkDataType("decimal", DecimalType.USER_DEFAULT)
checkDataType("Dec(10, 5)", DecimalType(10, 5))
checkDataType("deC", DecimalType.USER_DEFAULT)
checkDataType("DATE", DateType)
checkDataType("timestamp", TimestampType)
checkDataType("string", StringType)
checkDataType("ChaR(5)", StringType)
checkDataType("ChaRacter(5)", StringType)
checkDataType("varchAr(20)", StringType)
checkDataType("cHaR(27)", StringType)
checkDataType("BINARY", BinaryType)
Expand Down

0 comments on commit ea5b5a4

Please sign in to comment.