Github user gatorsmile commented on a diff in the pull request: https://github.com/apache/spark/pull/17406#discussion_r108042411 --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/types/DataTypeSuite.scala --- @@ -169,30 +169,45 @@ class DataTypeSuite extends SparkFunSuite { assert(!arrayType.existsRecursively(_.isInstanceOf[IntegerType])) } - def checkDataTypeJsonRepr(dataType: DataType): Unit = { - test(s"JSON - $dataType") { + def checkDataTypeFromJson(dataType: DataType): Unit = { + test(s"from Json - $dataType") { assert(DataType.fromJson(dataType.json) === dataType) } } - checkDataTypeJsonRepr(NullType) - checkDataTypeJsonRepr(BooleanType) - checkDataTypeJsonRepr(ByteType) - checkDataTypeJsonRepr(ShortType) - checkDataTypeJsonRepr(IntegerType) - checkDataTypeJsonRepr(LongType) - checkDataTypeJsonRepr(FloatType) - checkDataTypeJsonRepr(DoubleType) - checkDataTypeJsonRepr(DecimalType(10, 5)) - checkDataTypeJsonRepr(DecimalType.SYSTEM_DEFAULT) - checkDataTypeJsonRepr(DateType) - checkDataTypeJsonRepr(TimestampType) - checkDataTypeJsonRepr(StringType) - checkDataTypeJsonRepr(BinaryType) - checkDataTypeJsonRepr(ArrayType(DoubleType, true)) - checkDataTypeJsonRepr(ArrayType(StringType, false)) - checkDataTypeJsonRepr(MapType(IntegerType, StringType, true)) - checkDataTypeJsonRepr(MapType(IntegerType, ArrayType(DoubleType), false)) + def checkDataTypeFromDDL(dataType: DataType): Unit = { + test(s"from DDL - $dataType") { + assert(DataType.fromDDL(s"a ${dataType.sql}") === new StructType().add("a", dataType)) + } + } + + def checkDataTypeFromText(dataType: DataType): Unit = { + checkDataTypeFromJson(dataType) + checkDataTypeFromDDL(dataType) + } + + // In some types, check json formats only because the types do not support DDL formats. + checkDataTypeFromJson(NullType) + + checkDataTypeFromText(BooleanType) + checkDataTypeFromText(ByteType) + checkDataTypeFromText(ShortType) + checkDataTypeFromText(IntegerType) + checkDataTypeFromText(LongType) + checkDataTypeFromText(FloatType) + checkDataTypeFromText(DoubleType) + checkDataTypeFromText(DecimalType(10, 5)) + checkDataTypeFromText(DecimalType.SYSTEM_DEFAULT) + checkDataTypeFromText(DateType) + checkDataTypeFromText(TimestampType) + checkDataTypeFromText(StringType) + checkDataTypeFromText(BinaryType) + + checkDataTypeFromText(ArrayType(DoubleType, true)) + checkDataTypeFromJson(ArrayType(StringType, false)) + + checkDataTypeFromText(MapType(IntegerType, StringType, true)) + checkDataTypeFromJson(MapType(IntegerType, ArrayType(DoubleType), false)) --- End diff -- You can keep both, but add an extra one for `checkDataTypeFromJson ` when the nullability is `false`. ``` checkDataTypeFromText(MapType(IntegerType, ArrayType(DoubleType), true)) checkDataTypeFromJson(MapType(IntegerType, ArrayType(DoubleType), false)) ```
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org