cloud-fan commented on code in PR #51335:
URL: https://github.com/apache/spark/pull/51335#discussion_r2191574777


##########
sql/api/src/main/scala/org/apache/spark/sql/catalyst/parser/DataTypeAstBuilder.scala:
##########
@@ -65,74 +65,91 @@ class DataTypeAstBuilder extends 
SqlBaseParserBaseVisitor[AnyRef] {
       ctx.parts.asScala.map(_.getText).toSeq
     }
 
-  /**
-   * Resolve/create the TIME primitive type.
-   */
-  override def visitTimeDataType(ctx: TimeDataTypeContext): DataType = 
withOrigin(ctx) {
-    val precision = if (ctx.precision == null) {
-      TimeType.DEFAULT_PRECISION
-    } else {
-      ctx.precision.getText.toInt
-    }
-    TimeType(precision)
-  }
-
-  /**
-   * Create the TIMESTAMP_NTZ primitive type.
-   */
-  override def visitTimestampNtzDataType(ctx: TimestampNtzDataTypeContext): 
DataType = {
-    withOrigin(ctx)(TimestampNTZType)
-  }
-
   /**
    * Resolve/create a primitive type.
    */
   override def visitPrimitiveDataType(ctx: PrimitiveDataTypeContext): DataType 
= withOrigin(ctx) {
-    val typeCtx = ctx.`type`
-    (typeCtx.start.getType, ctx.INTEGER_VALUE().asScala.toList) match {
-      case (BOOLEAN, Nil) => BooleanType
-      case (TINYINT | BYTE, Nil) => ByteType
-      case (SMALLINT | SHORT, Nil) => ShortType
-      case (INT | INTEGER, Nil) => IntegerType
-      case (BIGINT | LONG, Nil) => LongType
-      case (FLOAT | REAL, Nil) => FloatType
-      case (DOUBLE, Nil) => DoubleType
-      case (DATE, Nil) => DateType
-      case (TIMESTAMP, Nil) => SqlApiConf.get.timestampType
-      case (TIMESTAMP_LTZ, Nil) => TimestampType
-      case (STRING, Nil) =>
-        typeCtx.children.asScala.toSeq match {
-          case Seq(_) => StringType
-          case Seq(_, ctx: CollateClauseContext) =>
-            val collationNameParts = visitCollateClause(ctx).toArray
-            val collationId = CollationFactory.collationNameToId(
-              CollationFactory.resolveFullyQualifiedName(collationNameParts))
-            StringType(collationId)
-        }
-      case (CHARACTER | CHAR, length :: Nil) => CharType(length.getText.toInt)
-      case (VARCHAR, length :: Nil) => VarcharType(length.getText.toInt)
-      case (BINARY, Nil) => BinaryType
-      case (DECIMAL | DEC | NUMERIC, Nil) => DecimalType.USER_DEFAULT
-      case (DECIMAL | DEC | NUMERIC, precision :: Nil) =>
-        DecimalType(precision.getText.toInt, 0)
-      case (DECIMAL | DEC | NUMERIC, precision :: scale :: Nil) =>
-        DecimalType(precision.getText.toInt, scale.getText.toInt)
-      case (VOID, Nil) => NullType
-      case (INTERVAL, Nil) => CalendarIntervalType
-      case (VARIANT, Nil) => VariantType
-      case (CHARACTER | CHAR | VARCHAR, Nil) =>
-        throw 
QueryParsingErrors.charTypeMissingLengthError(ctx.`type`.getText, ctx)
-      case (ARRAY | STRUCT | MAP, Nil) =>
-        throw 
QueryParsingErrors.nestedTypeMissingElementTypeError(ctx.`type`.getText, ctx)
-      case (_, params) =>
-        val badType = ctx.`type`.getText
-        val dtStr = if (params.nonEmpty) s"$badType(${params.mkString(",")})" 
else badType
-        throw QueryParsingErrors.dataTypeUnsupportedError(dtStr, ctx)
+    val typeCtx = ctx.`primitiveType`

Review Comment:
   `primitiveType` is not a keyword in Scala, no need to quote



##########
sql/api/src/main/scala/org/apache/spark/sql/catalyst/parser/DataTypeAstBuilder.scala:
##########
@@ -65,74 +65,91 @@ class DataTypeAstBuilder extends 
SqlBaseParserBaseVisitor[AnyRef] {
       ctx.parts.asScala.map(_.getText).toSeq
     }
 
-  /**
-   * Resolve/create the TIME primitive type.
-   */
-  override def visitTimeDataType(ctx: TimeDataTypeContext): DataType = 
withOrigin(ctx) {
-    val precision = if (ctx.precision == null) {
-      TimeType.DEFAULT_PRECISION
-    } else {
-      ctx.precision.getText.toInt
-    }
-    TimeType(precision)
-  }
-
-  /**
-   * Create the TIMESTAMP_NTZ primitive type.
-   */
-  override def visitTimestampNtzDataType(ctx: TimestampNtzDataTypeContext): 
DataType = {
-    withOrigin(ctx)(TimestampNTZType)
-  }
-
   /**
    * Resolve/create a primitive type.
    */
   override def visitPrimitiveDataType(ctx: PrimitiveDataTypeContext): DataType 
= withOrigin(ctx) {
-    val typeCtx = ctx.`type`
-    (typeCtx.start.getType, ctx.INTEGER_VALUE().asScala.toList) match {
-      case (BOOLEAN, Nil) => BooleanType
-      case (TINYINT | BYTE, Nil) => ByteType
-      case (SMALLINT | SHORT, Nil) => ShortType
-      case (INT | INTEGER, Nil) => IntegerType
-      case (BIGINT | LONG, Nil) => LongType
-      case (FLOAT | REAL, Nil) => FloatType
-      case (DOUBLE, Nil) => DoubleType
-      case (DATE, Nil) => DateType
-      case (TIMESTAMP, Nil) => SqlApiConf.get.timestampType
-      case (TIMESTAMP_LTZ, Nil) => TimestampType
-      case (STRING, Nil) =>
-        typeCtx.children.asScala.toSeq match {
-          case Seq(_) => StringType
-          case Seq(_, ctx: CollateClauseContext) =>
-            val collationNameParts = visitCollateClause(ctx).toArray
-            val collationId = CollationFactory.collationNameToId(
-              CollationFactory.resolveFullyQualifiedName(collationNameParts))
-            StringType(collationId)
-        }
-      case (CHARACTER | CHAR, length :: Nil) => CharType(length.getText.toInt)
-      case (VARCHAR, length :: Nil) => VarcharType(length.getText.toInt)
-      case (BINARY, Nil) => BinaryType
-      case (DECIMAL | DEC | NUMERIC, Nil) => DecimalType.USER_DEFAULT
-      case (DECIMAL | DEC | NUMERIC, precision :: Nil) =>
-        DecimalType(precision.getText.toInt, 0)
-      case (DECIMAL | DEC | NUMERIC, precision :: scale :: Nil) =>
-        DecimalType(precision.getText.toInt, scale.getText.toInt)
-      case (VOID, Nil) => NullType
-      case (INTERVAL, Nil) => CalendarIntervalType
-      case (VARIANT, Nil) => VariantType
-      case (CHARACTER | CHAR | VARCHAR, Nil) =>
-        throw 
QueryParsingErrors.charTypeMissingLengthError(ctx.`type`.getText, ctx)
-      case (ARRAY | STRUCT | MAP, Nil) =>
-        throw 
QueryParsingErrors.nestedTypeMissingElementTypeError(ctx.`type`.getText, ctx)
-      case (_, params) =>
-        val badType = ctx.`type`.getText
-        val dtStr = if (params.nonEmpty) s"$badType(${params.mkString(",")})" 
else badType
-        throw QueryParsingErrors.dataTypeUnsupportedError(dtStr, ctx)
+    val typeCtx = ctx.`primitiveType`
+    if (typeCtx.`nonTrivialPrimitiveType` != null) {

Review Comment:
   ditto



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to