dongjoon-hyun commented on code in PR #599:
URL: 
https://github.com/apache/spark-connect-swift/pull/599#discussion_r4299088360


##########
Tests/SparkConnectTests/UDFRegistrationTests.swift:
##########
@@ -0,0 +1,43 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//  http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#if canImport(FoundationEssentials)
+import FoundationEssentials
+#else
+import Foundation
+#endif
+import Testing
+
+@testable import SparkConnect
+
+/// A test suite for `UDFRegistration`
+@Suite(.serialized)
+struct UDFRegistrationTests {
+
+  @Test
+  func registerJavaWithUnknownClass() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    await #expect(throws: Error.self) {

Review Comment:
   Good catch, thanks. Updated in 1cdba24: the unknown-class test now asserts 
that the error mentions `NoSuchUDF`, and I added 
`registerJavaWithoutUDFInterface`, which registers `java.lang.String` and 
asserts `NO_UDF_INTERFACE`. I verified both against `apache/spark:4.2.0`.



##########
Tests/SparkConnectTests/UDFRegistrationTests.swift:
##########
@@ -0,0 +1,43 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//  http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#if canImport(FoundationEssentials)
+import FoundationEssentials
+#else
+import Foundation
+#endif
+import Testing
+
+@testable import SparkConnect
+
+/// A test suite for `UDFRegistration`
+@Suite(.serialized)
+struct UDFRegistrationTests {
+
+  @Test
+  func registerJavaWithUnknownClass() async throws {
+    let spark = try await SparkSession.builder.getOrCreate()
+    await #expect(throws: Error.self) {
+      try await spark.udf.registerJava("java_udf", 
"org.apache.spark.NoSuchUDF", .string)
+    }
+    await #expect(throws: Error.self) {

Review Comment:
   Agreed. The `nil` return type call failed at `loadClass` just like the first 
one, so it did not test anything. I dropped it. The `nil` path is only covered 
by the manual check described in the PR description (a `UDF2` jar uploaded via 
`addArtifact`), since a committed test would need a jar fixture.



##########
Sources/SparkConnect/UDFRegistration.swift:
##########
@@ -0,0 +1,46 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//  http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+/// Functions for registering user-defined functions. To access this, use 
``SparkSession/udf``.
+public actor UDFRegistration: Sendable {
+  var spark: SparkSession
+
+  init(spark: SparkSession) {
+    self.spark = spark
+  }
+
+  /// Register a Java user-defined function as a SQL function.
+  ///
+  /// The class must implement one of the `UDF1` ... `UDF22` interfaces and be 
available in the

Review Comment:
   Fixed in 1cdba24. The doc now says `UDF0` ... `UDF22`, that the interface 
must be implemented directly (an interface inherited from a superclass is not 
detected), and that the class needs a public no-arg constructor.



##########
Sources/SparkConnect/SparkConnectClient.swift:
##########
@@ -953,6 +953,26 @@ public actor SparkConnectClient {
     return plan
   }
 
+  /// Register a Java user-defined function as a SQL function.

Review Comment:
   Done in 1cdba24. The internal method now has a one-line summary.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to