diff --git a/csharp/Adapter/Microsoft.Spark.CSharp/Adapter.csproj b/csharp/Adapter/Microsoft.Spark.CSharp/Adapter.csproj
index 4daf4aa..d887daf 100644
--- a/csharp/Adapter/Microsoft.Spark.CSharp/Adapter.csproj
+++ b/csharp/Adapter/Microsoft.Spark.CSharp/Adapter.csproj
@@ -157,6 +157,7 @@
+
diff --git a/csharp/Adapter/Microsoft.Spark.CSharp/Proxy/ISparkSessionProxy.cs b/csharp/Adapter/Microsoft.Spark.CSharp/Proxy/ISparkSessionProxy.cs
index 56f869c..11a58cd 100644
--- a/csharp/Adapter/Microsoft.Spark.CSharp/Proxy/ISparkSessionProxy.cs
+++ b/csharp/Adapter/Microsoft.Spark.CSharp/Proxy/ISparkSessionProxy.cs
@@ -10,12 +10,15 @@ using Microsoft.Spark.CSharp.Sql;
namespace Microsoft.Spark.CSharp.Proxy
{
- internal interface IUdfRegistration { }
+ internal interface IUdfRegistrationProxy
+ {
+ void RegisterFunction(string name, byte[] command, string returnType);
+ }
interface ISparkSessionProxy
{
ISqlContextProxy SqlContextProxy { get; }
- IUdfRegistration Udf { get; }
+ IUdfRegistrationProxy Udf { get; }
ICatalogProxy GetCatalog();
IDataFrameReaderProxy Read();
ISparkSessionProxy NewSession();
diff --git a/csharp/Adapter/Microsoft.Spark.CSharp/Proxy/Ipc/SparkSessionIpcProxy.cs b/csharp/Adapter/Microsoft.Spark.CSharp/Proxy/Ipc/SparkSessionIpcProxy.cs
index d134c08..febfd3b 100644
--- a/csharp/Adapter/Microsoft.Spark.CSharp/Proxy/Ipc/SparkSessionIpcProxy.cs
+++ b/csharp/Adapter/Microsoft.Spark.CSharp/Proxy/Ipc/SparkSessionIpcProxy.cs
@@ -17,18 +17,13 @@ namespace Microsoft.Spark.CSharp.Proxy.Ipc
private readonly JvmObjectReference jvmSparkSessionReference;
private readonly ISqlContextProxy sqlContextProxy;
- private readonly IUdfRegistration udfRegistration;
+ private readonly IUdfRegistrationProxy udfRegistrationProxy;
- public IUdfRegistration Udf
+ public IUdfRegistrationProxy Udf
{
get
{
- if (udfRegistration == null)
- {
- //TODO implementation needed
- }
-
- return udfRegistration;
+ return udfRegistrationProxy;
}
}
@@ -46,6 +41,7 @@ namespace Microsoft.Spark.CSharp.Proxy.Ipc
{
this.jvmSparkSessionReference = jvmSparkSessionReference;
sqlContextProxy = new SqlContextIpcProxy(GetSqlContextReference());
+ udfRegistrationProxy = new UdfRegistrationIpcProxy(sqlContextProxy);
}
private JvmObjectReference GetSqlContextReference()
@@ -98,4 +94,19 @@ namespace Microsoft.Spark.CSharp.Proxy.Ipc
SparkCLRIpcProxy.JvmBridge.CallNonStaticJavaMethod(jvmSparkSessionReference, "stop");
}
}
+
+ [ExcludeFromCodeCoverage] //IPC calls to JVM validated using validation-enabled samples - unit test coverage not reqiured
+ internal class UdfRegistrationIpcProxy : IUdfRegistrationProxy
+ {
+ private readonly ISqlContextProxy sqlContextProxy;
+ internal UdfRegistrationIpcProxy(ISqlContextProxy sqlContextProxy)
+ {
+ this.sqlContextProxy = sqlContextProxy;
+ }
+
+ public void RegisterFunction(string name, byte[] command, string returnType)
+ {
+ sqlContextProxy.RegisterFunction(name, command, returnType);
+ }
+ }
}
diff --git a/csharp/Adapter/Microsoft.Spark.CSharp/Sql/SparkSession.cs b/csharp/Adapter/Microsoft.Spark.CSharp/Sql/SparkSession.cs
index 3ff8a8a..55b5846 100644
--- a/csharp/Adapter/Microsoft.Spark.CSharp/Sql/SparkSession.cs
+++ b/csharp/Adapter/Microsoft.Spark.CSharp/Sql/SparkSession.cs
@@ -48,6 +48,11 @@ namespace Microsoft.Spark.CSharp.Sql
get { return sparkContext; }
}
+ public UdfRegistration Udf
+ {
+ get { return new UdfRegistration(sparkSessionProxy.Udf); }
+ }
+
///
/// Builder for SparkSession
///
diff --git a/csharp/Adapter/Microsoft.Spark.CSharp/Sql/UdfRegistration.cs b/csharp/Adapter/Microsoft.Spark.CSharp/Sql/UdfRegistration.cs
new file mode 100644
index 0000000..b9c5008
--- /dev/null
+++ b/csharp/Adapter/Microsoft.Spark.CSharp/Sql/UdfRegistration.cs
@@ -0,0 +1,254 @@
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.Spark.CSharp.Core;
+using Microsoft.Spark.CSharp.Proxy;
+using Microsoft.Spark.CSharp.Services;
+
+namespace Microsoft.Spark.CSharp.Sql
+{
+ ///
+ /// Used for registering User Defined Functions. SparkSession.Udf is used to access instance of this type.
+ ///
+ public class UdfRegistration
+ {
+ private readonly ILoggerService logger = LoggerServiceFactory.GetLogger(typeof(UdfRegistration));
+
+ private IUdfRegistrationProxy udfRegistrationProxy;
+
+ internal UdfRegistration(IUdfRegistrationProxy udfRegistrationProxy)
+ {
+ this.udfRegistrationProxy = udfRegistrationProxy;
+ }
+
+ //TODO - the following section is a copy of the same functionality in SQLContext..refactoring needed
+ #region UDF Registration
+ ///
+ /// Register UDF with no input argument, e.g:
+ /// SqlContext.RegisterFunction<bool>("MyFilter", () => true);
+ /// sqlContext.Sql("SELECT * FROM MyTable where MyFilter()");
+ ///
+ ///
+ ///
+ ///
+ public void RegisterFunction