comphead commented on code in PR #4233: URL: https://github.com/apache/datafusion-comet/pull/4233#discussion_r3192112297
########## spark/src/test/scala/org/apache/comet/CometUserUdfSuite.scala: ########## @@ -0,0 +1,103 @@ +/* + * 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 + +import org.apache.spark.sql.CometTestBase +import org.apache.spark.sql.execution.adaptive.AdaptiveSparkPlanHelper +import org.apache.spark.sql.types.LongType + +import org.apache.comet.udf.CometUdfRegistry + +class CometUserUdfSuite extends CometTestBase with AdaptiveSparkPlanHelper { + + override def afterEach(): Unit = { + CometUdfRegistry.clear() + super.afterEach() + } + + test("user CometUDF - basic integer doubling") { + CometUdfRegistry.register( + "double_int", + "org.apache.comet.udf.DoubleIntUdf", + LongType, + nullable = true) + spark.udf.register("double_int", (x: Int) => x.toLong * 2L) + + withTable("t") { + sql("CREATE TABLE t (x INT) USING parquet") + sql("INSERT INTO t VALUES (1), (2), (3), (NULL), (100)") + checkSparkAnswerAndOperator(sql("SELECT double_int(x) FROM t")) + } + } + + test("user CometUDF - unregistered UDF falls back to Spark") { + spark.udf.register("triple_int", (x: Int) => x * 3) + + withTable("t") { + sql("CREATE TABLE t (x INT) USING parquet") + sql("INSERT INTO t VALUES (1), (2), (3)") + // Should still produce correct results via Spark fallback + checkSparkAnswer(sql("SELECT triple_int(x) FROM t")) Review Comment: should we check fallback msg? -- 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]
