@@ -34,6 +34,7 @@ import org.apache.spark.sql.catalyst.catalog.ExternalCatalogUtils
34
34
import org .apache .spark .sql .catalyst .types .DataTypeUtils
35
35
import org .apache .spark .sql .catalyst .util .{DateFormatter , DateTimeUtils , TimeFormatter , TimestampFormatter }
36
36
import org .apache .spark .sql .catalyst .util .DateTimeUtils .localDateTimeToMicros
37
+ import org .apache .spark .sql .errors .QueryExecutionErrors
37
38
import org .apache .spark .sql .execution .datasources ._
38
39
import org .apache .spark .sql .execution .datasources .{PartitionPath => Partition }
39
40
import org .apache .spark .sql .execution .datasources .v2 .{DataSourceV2Relation , FileTable }
@@ -1405,6 +1406,28 @@ class ParquetV2PartitionDiscoverySuite extends ParquetPartitionDiscoverySuite {
1405
1406
assert(" p_int=10/p_float=1.0" === path)
1406
1407
}
1407
1408
1409
+ test(" SPARK-51830 handle exception and validate partition column as true" ) {
1410
+ SQLConf .get.setConf(SQLConf .VALIDATE_PARTITION_COLUMNS , true )
1411
+ val spec = Map (" p_int" -> " not_a_number" )
1412
+ val schema = new StructType ().add(" p_int" , " int" )
1413
+ val exception = intercept[Exception ] {
1414
+ PartitioningUtils .getPathFragment(spec, schema)
1415
+ }
1416
+ assert(
1417
+ exception.isInstanceOf [
1418
+ QueryExecutionErrors .FailedToCastValueToDataTypeForPartitionColumnError
1419
+ ]
1420
+ )
1421
+ }
1422
+
1423
+ test(" SPARK-51830 handle exception and validate partition column as false" ) {
1424
+ SQLConf .get.setConf(SQLConf .VALIDATE_PARTITION_COLUMNS , false )
1425
+ val spec = Map (" p_int" -> " not_a_number" )
1426
+ val schema = new StructType ().add(" p_int" , " int" )
1427
+ val path = PartitioningUtils .getPathFragment(spec, schema)
1428
+ assert(" p_int=not_a_number" === path)
1429
+ }
1430
+
1408
1431
test(" SPARK-39417: Null partition value" ) {
1409
1432
// null partition value is replaced by DEFAULT_PARTITION_NAME before hitting getPathFragment.
1410
1433
val spec = Map (" p_int" -> ExternalCatalogUtils .DEFAULT_PARTITION_NAME )
0 commit comments