andygrove commented on code in PR #4459:
URL: https://github.com/apache/datafusion-comet/pull/4459#discussion_r3736235326


##########
spark/src/main/scala/org/apache/comet/udf/CometRustUdfRegistry.scala:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+
+package org.apache.comet.udf
+
+import java.util.concurrent.ConcurrentHashMap
+
+import org.apache.spark.sql.types.DataType
+
+/** Metadata for a registered Rust UDF. */
+case class RustUdfMetadata(
+    libraryPath: String,
+    inputTypes: Seq[DataType],
+    returnType: DataType,
+    deterministic: Boolean)
+
+/**
+ * Driver-side registry of Rust UDFs. Looked up by `QueryPlanSerde` to 
recognize names that should
+ * be emitted as `RustUdfCall` instead of attempted as JVM-evaluated 
`ScalaUDF`s.
+ */
+class CometRustUdfRegistry {
+  private val byName = new ConcurrentHashMap[String, RustUdfMetadata]()
+
+  /** Register or replace metadata for a name. */
+  def register(name: String, meta: RustUdfMetadata): Unit =
+    byName.put(name, meta)
+
+  /** Return metadata for a name, if registered. */
+  def get(name: String): Option[RustUdfMetadata] =
+    Option(byName.get(name))
+}
+
+object CometRustUdfRegistry {
+
+  /** Process-wide singleton. */
+  lazy val instance: CometRustUdfRegistry = new CometRustUdfRegistry

Review Comment:
   Agreed, and the guide is yours so I'll take it as the standard. Two parts to 
my answer.
   
   The part I fixed here: the `lazy val` now carries the justification the 
guide asks for. The state is bounded by the number of distinct UDF names an 
application registers, each entry is a library path plus a signature, nothing 
grows per query or per file, and there are no credentials in it. That much I'm 
comfortable with.
   
   The part I did not fix: the lifetime. Session scoping is the right answer 
and I don't want to hand-wave it — a name registered by one session being 
visible to the next is exactly the cross-job contamination case, and there's no 
unregister path. I'll file a follow-up for scoping registration to the session 
(or `SparkContext`) rather than do it in this PR, and the comment says so 
explicitly so it doesn't read as settled.
   
   Your next comment turned out to be the sharper half of this: because the 
registry is keyed by bare name *and* matched by bare name, the collision is not 
just a namespace question — it produces wrong answers. More there.



-- 
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