8
8
using Microsoft . Spark . Interop ;
9
9
using Microsoft . Spark . Interop . Ipc ;
10
10
using Microsoft . Spark . Sql . Expressions ;
11
+ using Microsoft . Spark . Sql . Types ;
11
12
using Microsoft . Spark . Utils ;
12
13
13
14
namespace Microsoft . Spark . Sql
@@ -3797,6 +3798,189 @@ public static Func<Column, Column, Column, Column, Column, Column, Column, Colum
3797
3798
return CreateUdf < TResult > ( udf . Method . ToString ( ) , UdfUtils . CreateUdfWrapper ( udf ) ) . Apply10 ;
3798
3799
}
3799
3800
3801
+ /// <summary>Creates a UDF from the specified delegate.</summary>
3802
+ /// <param name="udf">The UDF function implementation.</param>
3803
+ /// <param name="returnType">Schema associated with this row</param>
3804
+ /// <returns>
3805
+ /// A delegate that returns a <see cref="Column"/> for the result of the UDF.
3806
+ /// </returns>
3807
+ public static Func < Column > Udf ( Func < GenericRow > udf , StructType returnType )
3808
+ {
3809
+ return CreateUdf ( udf . Method . ToString ( ) , UdfUtils . CreateUdfWrapper ( udf ) , returnType ) . Apply0 ;
3810
+ }
3811
+
3812
+ /// <summary>Creates a UDF from the specified delegate.</summary>
3813
+ /// <typeparam name="T">Specifies the type of the first argument to the UDF.</typeparam>
3814
+ /// <param name="udf">The UDF function implementation.</param>
3815
+ /// <param name="returnType">Schema associated with this row</param>
3816
+ /// <returns>
3817
+ /// A delegate that returns a <see cref="Column"/> for the result of the UDF.
3818
+ /// </returns>
3819
+ public static Func < Column , Column > Udf < T > ( Func < T , GenericRow > udf , StructType returnType )
3820
+ {
3821
+ return CreateUdf ( udf . Method . ToString ( ) , UdfUtils . CreateUdfWrapper ( udf ) , returnType ) . Apply1 ;
3822
+ }
3823
+
3824
+ /// <summary>Creates a UDF from the specified delegate.</summary>
3825
+ /// <typeparam name="T1">Specifies the type of the first argument to the UDF.</typeparam>
3826
+ /// <typeparam name="T2">Specifies the type of the second argument to the UDF.</typeparam>
3827
+ /// <param name="udf">The UDF function implementation.</param>
3828
+ /// <param name="returnType">Schema associated with this row</param>
3829
+ /// <returns>
3830
+ /// A delegate that returns a <see cref="Column"/> for the result of the UDF.
3831
+ /// </returns>
3832
+ public static Func < Column , Column , Column > Udf < T1 , T2 > (
3833
+ Func < T1 , T2 , GenericRow > udf , StructType returnType )
3834
+ {
3835
+ return CreateUdf ( udf . Method . ToString ( ) , UdfUtils . CreateUdfWrapper ( udf ) , returnType ) . Apply2 ;
3836
+ }
3837
+
3838
+ /// <summary>Creates a UDF from the specified delegate.</summary>
3839
+ /// <typeparam name="T1">Specifies the type of the first argument to the UDF.</typeparam>
3840
+ /// <typeparam name="T2">Specifies the type of the second argument to the UDF.</typeparam>
3841
+ /// <typeparam name="T3">Specifies the type of the third argument to the UDF.</typeparam>
3842
+ /// <param name="udf">The UDF function implementation.</param>
3843
+ /// <param name="returnType">Schema associated with this row</param>
3844
+ /// <returns>
3845
+ /// A delegate that returns a <see cref="Column"/> for the result of the UDF.
3846
+ /// </returns>
3847
+ public static Func < Column , Column , Column , Column > Udf < T1 , T2 , T3 > (
3848
+ Func < T1 , T2 , T3 , GenericRow > udf , StructType returnType )
3849
+ {
3850
+ return CreateUdf ( udf . Method . ToString ( ) , UdfUtils . CreateUdfWrapper ( udf ) , returnType ) . Apply3 ;
3851
+ }
3852
+
3853
+ /// <summary>Creates a UDF from the specified delegate.</summary>
3854
+ /// <typeparam name="T1">Specifies the type of the first argument to the UDF.</typeparam>
3855
+ /// <typeparam name="T2">Specifies the type of the second argument to the UDF.</typeparam>
3856
+ /// <typeparam name="T3">Specifies the type of the third argument to the UDF.</typeparam>
3857
+ /// <typeparam name="T4">Specifies the type of the fourth argument to the UDF.</typeparam>
3858
+ /// <param name="udf">The UDF function implementation.</param>
3859
+ /// <param name="returnType">Schema associated with this row</param>
3860
+ /// <returns>
3861
+ /// A delegate that returns a <see cref="Column"/> for the result of the UDF.
3862
+ /// </returns>
3863
+ public static Func < Column , Column , Column , Column , Column > Udf < T1 , T2 , T3 , T4 > (
3864
+ Func < T1 , T2 , T3 , T4 , GenericRow > udf , StructType returnType )
3865
+ {
3866
+ return CreateUdf ( udf . Method . ToString ( ) , UdfUtils . CreateUdfWrapper ( udf ) , returnType ) . Apply4 ;
3867
+ }
3868
+
3869
+ /// <summary>Creates a UDF from the specified delegate.</summary>
3870
+ /// <typeparam name="T1">Specifies the type of the first argument to the UDF.</typeparam>
3871
+ /// <typeparam name="T2">Specifies the type of the second argument to the UDF.</typeparam>
3872
+ /// <typeparam name="T3">Specifies the type of the third argument to the UDF.</typeparam>
3873
+ /// <typeparam name="T4">Specifies the type of the fourth argument to the UDF.</typeparam>
3874
+ /// <typeparam name="T5">Specifies the type of the fifth argument to the UDF.</typeparam>
3875
+ /// <param name="udf">The UDF function implementation.</param>
3876
+ /// <param name="returnType">Schema associated with this row</param>
3877
+ /// <returns>
3878
+ /// A delegate that returns a <see cref="Column"/> for the result of the UDF.
3879
+ /// </returns>
3880
+ public static Func < Column , Column , Column , Column , Column , Column > Udf < T1 , T2 , T3 , T4 , T5 > (
3881
+ Func < T1 , T2 , T3 , T4 , T5 , GenericRow > udf , StructType returnType )
3882
+ {
3883
+ return CreateUdf ( udf . Method . ToString ( ) , UdfUtils . CreateUdfWrapper ( udf ) , returnType ) . Apply5 ;
3884
+ }
3885
+
3886
+ /// <summary>Creates a UDF from the specified delegate.</summary>
3887
+ /// <typeparam name="T1">Specifies the type of the first argument to the UDF.</typeparam>
3888
+ /// <typeparam name="T2">Specifies the type of the second argument to the UDF.</typeparam>
3889
+ /// <typeparam name="T3">Specifies the type of the third argument to the UDF.</typeparam>
3890
+ /// <typeparam name="T4">Specifies the type of the fourth argument to the UDF.</typeparam>
3891
+ /// <typeparam name="T5">Specifies the type of the fifth argument to the UDF.</typeparam>
3892
+ /// <typeparam name="T6">Specifies the type of the sixth argument to the UDF.</typeparam>
3893
+ /// <param name="udf">The UDF function implementation.</param>
3894
+ /// <param name="returnType">Schema associated with this row</param>
3895
+ /// <returns>
3896
+ /// A delegate that returns a <see cref="Column"/> for the result of the UDF.
3897
+ /// </returns>
3898
+ public static Func < Column , Column , Column , Column , Column , Column , Column > Udf < T1 , T2 , T3 , T4 , T5 , T6 > (
3899
+ Func < T1 , T2 , T3 , T4 , T5 , T6 , GenericRow > udf , StructType returnType )
3900
+ {
3901
+ return CreateUdf ( udf . Method . ToString ( ) , UdfUtils . CreateUdfWrapper ( udf ) , returnType ) . Apply6 ;
3902
+ }
3903
+
3904
+ /// <summary>Creates a UDF from the specified delegate.</summary>
3905
+ /// <typeparam name="T1">Specifies the type of the first argument to the UDF.</typeparam>
3906
+ /// <typeparam name="T2">Specifies the type of the second argument to the UDF.</typeparam>
3907
+ /// <typeparam name="T3">Specifies the type of the third argument to the UDF.</typeparam>
3908
+ /// <typeparam name="T4">Specifies the type of the fourth argument to the UDF.</typeparam>
3909
+ /// <typeparam name="T5">Specifies the type of the fifth argument to the UDF.</typeparam>
3910
+ /// <typeparam name="T6">Specifies the type of the sixth argument to the UDF.</typeparam>
3911
+ /// <typeparam name="T7">Specifies the type of the seventh argument to the UDF.</typeparam>
3912
+ /// <param name="udf">The UDF function implementation.</param>
3913
+ /// <param name="returnType">Schema associated with this row</param>
3914
+ /// <returns>
3915
+ /// A delegate that returns a <see cref="Column"/> for the result of the UDF.
3916
+ /// </returns>
3917
+ public static Func < Column , Column , Column , Column , Column , Column , Column , Column > Udf < T1 , T2 , T3 , T4 , T5 , T6 , T7 > (
3918
+ Func < T1 , T2 , T3 , T4 , T5 , T6 , T7 , GenericRow > udf , StructType returnType )
3919
+ {
3920
+ return CreateUdf ( udf . Method . ToString ( ) , UdfUtils . CreateUdfWrapper ( udf ) , returnType ) . Apply7 ;
3921
+ }
3922
+
3923
+ /// <summary>Creates a UDF from the specified delegate.</summary>
3924
+ /// <typeparam name="T1">Specifies the type of the first argument to the UDF.</typeparam>
3925
+ /// <typeparam name="T2">Specifies the type of the second argument to the UDF.</typeparam>
3926
+ /// <typeparam name="T3">Specifies the type of the third argument to the UDF.</typeparam>
3927
+ /// <typeparam name="T4">Specifies the type of the fourth argument to the UDF.</typeparam>
3928
+ /// <typeparam name="T5">Specifies the type of the fifth argument to the UDF.</typeparam>
3929
+ /// <typeparam name="T6">Specifies the type of the sixth argument to the UDF.</typeparam>
3930
+ /// <typeparam name="T7">Specifies the type of the seventh argument to the UDF.</typeparam>
3931
+ /// <typeparam name="T8">Specifies the type of the eighth argument to the UDF.</typeparam>
3932
+ /// <param name="udf">The UDF function implementation.</param>
3933
+ /// <param name="returnType">Schema associated with this row</param>
3934
+ /// <returns>
3935
+ /// A delegate that returns a <see cref="Column"/> for the result of the UDF.
3936
+ /// </returns>
3937
+ public static Func < Column , Column , Column , Column , Column , Column , Column , Column , Column > Udf < T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 > (
3938
+ Func < T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 , GenericRow > udf , StructType returnType )
3939
+ {
3940
+ return CreateUdf ( udf . Method . ToString ( ) , UdfUtils . CreateUdfWrapper ( udf ) , returnType ) . Apply8 ;
3941
+ }
3942
+
3943
+ /// <summary>Creates a UDF from the specified delegate.</summary>
3944
+ /// <typeparam name="T1">Specifies the type of the first argument to the UDF.</typeparam>
3945
+ /// <typeparam name="T2">Specifies the type of the second argument to the UDF.</typeparam>
3946
+ /// <typeparam name="T3">Specifies the type of the third argument to the UDF.</typeparam>
3947
+ /// <typeparam name="T4">Specifies the type of the fourth argument to the UDF.</typeparam>
3948
+ /// <typeparam name="T5">Specifies the type of the fifth argument to the UDF.</typeparam>
3949
+ /// <typeparam name="T6">Specifies the type of the sixth argument to the UDF.</typeparam>
3950
+ /// <typeparam name="T7">Specifies the type of the seventh argument to the UDF.</typeparam>
3951
+ /// <typeparam name="T8">Specifies the type of the eighth argument to the UDF.</typeparam>
3952
+ /// <typeparam name="T9">Specifies the type of the ninth argument to the UDF.</typeparam>
3953
+ /// <param name="udf">The UDF function implementation.</param>
3954
+ /// <param name="returnType">Schema associated with this row</param>
3955
+ /// <returns>A delegate that when invoked will return a <see cref="Column"/> for the result of the UDF.</returns>
3956
+ public static Func < Column , Column , Column , Column , Column , Column , Column , Column , Column , Column > Udf < T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 > (
3957
+ Func < T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , GenericRow > udf , StructType returnType )
3958
+ {
3959
+ return CreateUdf ( udf . Method . ToString ( ) , UdfUtils . CreateUdfWrapper ( udf ) , returnType ) . Apply9 ;
3960
+ }
3961
+
3962
+ /// <summary>Creates a UDF from the specified delegate.</summary>
3963
+ /// <typeparam name="T1">Specifies the type of the first argument to the UDF.</typeparam>
3964
+ /// <typeparam name="T2">Specifies the type of the second argument to the UDF.</typeparam>
3965
+ /// <typeparam name="T3">Specifies the type of the third argument to the UDF.</typeparam>
3966
+ /// <typeparam name="T4">Specifies the type of the fourth argument to the UDF.</typeparam>
3967
+ /// <typeparam name="T5">Specifies the type of the fifth argument to the UDF.</typeparam>
3968
+ /// <typeparam name="T6">Specifies the type of the sixth argument to the UDF.</typeparam>
3969
+ /// <typeparam name="T7">Specifies the type of the seventh argument to the UDF.</typeparam>
3970
+ /// <typeparam name="T8">Specifies the type of the eighth argument to the UDF.</typeparam>
3971
+ /// <typeparam name="T9">Specifies the type of the ninth argument to the UDF.</typeparam>
3972
+ /// <typeparam name="T10">Specifies the type of the tenth argument to the UDF.</typeparam>
3973
+ /// <param name="udf">The UDF function implementation.</param>
3974
+ /// <param name="returnType">Schema associated with this row</param>
3975
+ /// <returns>
3976
+ /// A delegate that returns a <see cref="Column"/> for the result of the UDF.
3977
+ /// </returns>
3978
+ public static Func < Column , Column , Column , Column , Column , Column , Column , Column , Column , Column , Column > Udf < T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 > (
3979
+ Func < T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9 , T10 , GenericRow > udf , StructType returnType )
3980
+ {
3981
+ return CreateUdf ( udf . Method . ToString ( ) , UdfUtils . CreateUdfWrapper ( udf ) , returnType ) . Apply10 ;
3982
+ }
3983
+
3800
3984
/// <summary>Creates a Vector UDF from the specified delegate.</summary>
3801
3985
/// <typeparam name="T">Specifies the type of the first argument to the UDF.</typeparam>
3802
3986
/// <typeparam name="TResult">Specifies the return type of the UDF.</typeparam>
@@ -4071,6 +4255,11 @@ private static UserDefinedFunction CreateUdf<TResult>(string name, Delegate exec
4071
4255
return CreateUdf < TResult > ( name , execute , UdfUtils . PythonEvalType . SQL_BATCHED_UDF ) ;
4072
4256
}
4073
4257
4258
+ private static UserDefinedFunction CreateUdf ( string name , Delegate execute , StructType returnType )
4259
+ {
4260
+ return CreateUdf ( name , execute , UdfUtils . PythonEvalType . SQL_BATCHED_UDF , returnType ) ;
4261
+ }
4262
+
4074
4263
private static UserDefinedFunction CreateVectorUdf < TResult > ( string name , Delegate execute )
4075
4264
{
4076
4265
return CreateUdf < TResult > ( name , execute , UdfUtils . PythonEvalType . SQL_SCALAR_PANDAS_UDF ) ;
@@ -4079,7 +4268,21 @@ private static UserDefinedFunction CreateVectorUdf<TResult>(string name, Delegat
4079
4268
private static UserDefinedFunction CreateUdf < TResult > (
4080
4269
string name ,
4081
4270
Delegate execute ,
4082
- UdfUtils . PythonEvalType evalType )
4271
+ UdfUtils . PythonEvalType evalType ) =>
4272
+ CreateUdf ( name , execute , evalType , UdfUtils . GetReturnType ( typeof ( TResult ) ) ) ;
4273
+
4274
+ private static UserDefinedFunction CreateUdf (
4275
+ string name ,
4276
+ Delegate execute ,
4277
+ UdfUtils . PythonEvalType evalType ,
4278
+ StructType returnType ) =>
4279
+ CreateUdf ( name , execute , evalType , returnType . Json ) ;
4280
+
4281
+ private static UserDefinedFunction CreateUdf (
4282
+ string name ,
4283
+ Delegate execute ,
4284
+ UdfUtils . PythonEvalType evalType ,
4285
+ string returnType )
4083
4286
{
4084
4287
return UserDefinedFunction . Create (
4085
4288
name ,
@@ -4088,7 +4291,7 @@ private static UserDefinedFunction CreateUdf<TResult>(
4088
4291
CommandSerDe . SerializedMode . Row ,
4089
4292
CommandSerDe . SerializedMode . Row ) ,
4090
4293
evalType ,
4091
- UdfUtils . GetReturnType ( typeof ( TResult ) ) ) ;
4294
+ returnType ) ;
4092
4295
}
4093
4296
4094
4297
private static Column ApplyFunction ( string funcName )
0 commit comments