dongjoon-hyun commented on a change in pull request #24752: 
[SPARK-27893][SQL][PYTHON] Create an integrated test base for Python, Scalar 
Pandas, Scala UDF by sql files
URL: https://github.com/apache/spark/pull/24752#discussion_r292764404
 
 

 ##########
 File path: 
sql/core/src/test/scala/org/apache/spark/sql/IntegratedUDFTestUtils.scala
 ##########
 @@ -0,0 +1,251 @@
+/*
+ * 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.spark.sql
+
+import java.nio.file.{Files, Paths}
+
+import scala.collection.JavaConverters._
+import scala.util.Try
+
+import org.apache.spark.TestUtils
+import org.apache.spark.api.python.{PythonBroadcast, PythonEvalType, 
PythonFunction}
+import org.apache.spark.broadcast.Broadcast
+import org.apache.spark.internal.config.Tests
+import org.apache.spark.sql.catalyst.plans.SQLHelper
+import org.apache.spark.sql.execution.python.UserDefinedPythonFunction
+import org.apache.spark.sql.expressions.SparkUserDefinedFunction
+import org.apache.spark.sql.types.StringType
+
+/**
+ * This object targets to integrate various UDF test cases so that Scalar UDF, 
Python UDF and
+ * Scalar Pandas UDFs can be tested in SBT & Maven tests.
+ *
+ * The available UDFs cast input to strings, which take one column as input 
and return a string
+ * type column as output.
+ *
+ * To register Scala UDF in SQL:
+ * {{{
+ *   registerTestUDF(TestScalaUDF(name = "udf_name"), spark)
+ * }}}
+ *
+ * To register Python UDF in SQL:
+ * {{{
+ *   registerTestUDF(TestPythonUDF(name = "udf_name"), spark)
+ * }}}
+ *
+ * To register Scalar Pandas UDF in SQL:
+ * {{{
+ *   registerTestUDF(TestScalarPandasUDF(name = "udf_name"), spark)
+ * }}}
+ *
+ * To use it in Scala API and SQL:
+ * {{{
+ *   sql("SELECT udf_name(1)")
+ *   spark.select(expr("udf_name(1)")
+ * }}}
+ */
+object IntegratedUDFTestUtils extends SQLHelper {
+  import scala.sys.process._
+
+  private lazy val pythonPath = sys.env.getOrElse("PYTHONPATH", "")
+  private lazy val sparkHome = if (sys.props.contains(Tests.IS_TESTING.key)) {
+    assert(sys.props.contains("spark.test.home"), "spark.test.home is not 
set.")
+    sys.props("spark.test.home")
+  } else {
+    assert(sys.env.contains("SPARK_HOME"), "SPARK_HOME is not set.")
+    sys.env("SPARK_HOME")
+  }
+  // Note that we will directly refer pyspark's source, not the zip from a 
regular build.
+  // It is possible the test is being ran without the build.
+  private lazy val sourcePath = Paths.get(sparkHome, "python").toAbsolutePath
+  private lazy val py4jPath = Paths.get(
+    sparkHome, "python", "lib", "py4j-0.10.8.1-src.zip").toAbsolutePath
 
 Review comment:
   Yes. @cloud-fan . And, it's already replaced with `PY4J_ZIP_NAME` at 
8b18ef5c7b6 .

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to