File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -129,6 +129,10 @@ def pyspark_types_to_proto_types(data_type: DataType) -> pb2.DataType:
129
129
ret = pb2 .DataType ()
130
130
if isinstance (data_type , NullType ):
131
131
ret .null .CopyFrom (pb2 .DataType .NULL ())
132
+ elif isinstance (data_type , CharType ):
133
+ ret .char .length = data_type .length
134
+ elif isinstance (data_type , VarcharType ):
135
+ ret .varchar .length = data_type .length
132
136
elif isinstance (data_type , StringType ):
133
137
ret .string .collation = data_type .collation
134
138
elif isinstance (data_type , BooleanType ):
Original file line number Diff line number Diff line change @@ -1402,6 +1402,36 @@ def my_udf(input_val):
1402
1402
result_type = df_result .schema ["result" ].dataType
1403
1403
self .assertEqual (result_type , StringType ("fr" ))
1404
1404
1405
+ def test_udf_with_char_varchar_return_type (self ):
1406
+ char_type = "char(10)"
1407
+ varchar_type = "varchar(8)"
1408
+ array_with_char_type = "array<char(5)>"
1409
+ array_with_varchar_type = "array<varchar(12)>"
1410
+ map_type = f"map<{ char_type } , { varchar_type } >"
1411
+ struct_type = f"struct<f1: { char_type } , f2: { varchar_type } >"
1412
+
1413
+ return_types = [
1414
+ char_type ,
1415
+ varchar_type ,
1416
+ array_with_char_type ,
1417
+ array_with_varchar_type ,
1418
+ map_type ,
1419
+ struct_type ,
1420
+ f"struct<f1: { array_with_char_type } , f2: { array_with_varchar_type } , f3: { map_type } >" ,
1421
+ f"map<{ array_with_char_type } , { array_with_varchar_type } >" ,
1422
+ f"array<{ struct_type } >"
1423
+ ]
1424
+
1425
+ for return_type in return_types :
1426
+ with self .assertRaisesRegex (
1427
+ AnalysisException ,
1428
+ "(Please use a different output data type for your UDF or DataFrame|"
1429
+ "Invalid return type with Arrow-optimized Python UDF)"
1430
+ ):
1431
+ @udf (return_type )
1432
+ def my_udf ():
1433
+ return return_type
1434
+
1405
1435
1406
1436
class UDFTests (BaseUDFTestsMixin , ReusedSQLTestCase ):
1407
1437
@classmethod
You can’t perform that action at this time.
0 commit comments