We currently delegate to DataFusion when casting from string to decimal and there are some differences in behavior compared to Spark.
4e7 produces 40000000.00 in Spark, and null in DataFusion., -, + and empty string produce null in Spark, and 0.0 in DataFusion0 produces 0 in Spark, and null in DataFusionCannot cast string to decimal with negative scale). We could choose to fallback to Spark for this use case (or if SQLConf.LEGACY_ALLOW_NEGATIVE_SCALE_OF_DECIMAL_ENABLED is enabled)No response
I used the following test in CometCastSuite to explore this.
test("cast string to decimal") {
val values = generateStrings(numericPattern, 5).toDF("a")
castTest(values, DataTypes.createDecimalType(10, 2))
castTest(values, DataTypes.createDecimalType(10, 0))
withSQLConf((SQLConf.LEGACY_ALLOW_NEGATIVE_SCALE_OF_DECIMAL_ENABLED.key, "true")) {
castTest(values, DataTypes.createDecimalType(10, -2))
}
}
No response
No response