From ecaaeb8aea30b56b71e40e28a142c992b53704bf Mon Sep 17 00:00:00 2001 From: Hongze Zhang Date: Tue, 25 May 2021 16:05:19 +0800 Subject: [PATCH] [NSE-337] UDF: Add test case for validating basic row-based udf (#338) Closes #337 --- .../test/scala/com/intel/oap/tpc/ds/TPCDSSuite.scala | 11 ++++++++++- .../test/scala/com/intel/oap/tpc/h/TPCHSuite.scala | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/native-sql-engine/core/src/test/scala/com/intel/oap/tpc/ds/TPCDSSuite.scala b/native-sql-engine/core/src/test/scala/com/intel/oap/tpc/ds/TPCDSSuite.scala index 128f68bb7..cf753fc93 100644 --- a/native-sql-engine/core/src/test/scala/com/intel/oap/tpc/ds/TPCDSSuite.scala +++ b/native-sql-engine/core/src/test/scala/com/intel/oap/tpc/ds/TPCDSSuite.scala @@ -26,7 +26,7 @@ import org.apache.spark.sql.test.SharedSparkSession class TPCDSSuite extends QueryTest with SharedSparkSession { private val MAX_DIRECT_MEMORY = "6g" - private val TPCDS_QUERIES_RESOURCE = "tpcds-queries" + private val TPCDS_QUERIES_RESOURCE = "tpcds" private val TPCDS_WRITE_PATH = "/tmp/tpcds-generated" private var runner: TPCRunner = _ @@ -136,6 +136,15 @@ class TPCDSSuite extends QueryTest with SharedSparkSession { df.explain() df.show() } + + test("simple UDF") { + spark.udf.register("strLenScala", + (s: String) => Option(s).map(_.length).orElse(Option(0)).get) + val df = spark.sql("SELECT i_item_sk, i_item_desc, strLenScala(i_item_desc) FROM " + + "item LIMIT 100") + df.explain() + df.show() + } } object TPCDSSuite { diff --git a/native-sql-engine/core/src/test/scala/com/intel/oap/tpc/h/TPCHSuite.scala b/native-sql-engine/core/src/test/scala/com/intel/oap/tpc/h/TPCHSuite.scala index a8fc06e86..82ac63e46 100644 --- a/native-sql-engine/core/src/test/scala/com/intel/oap/tpc/h/TPCHSuite.scala +++ b/native-sql-engine/core/src/test/scala/com/intel/oap/tpc/h/TPCHSuite.scala @@ -41,7 +41,7 @@ import scala.collection.mutable.ArrayBuffer class TPCHSuite extends QueryTest with SharedSparkSession { private val MAX_DIRECT_MEMORY = "6g" - private val TPCH_QUERIES_RESOURCE = "tpch-queries" + private val TPCH_QUERIES_RESOURCE = "tpch" private val TPCH_WRITE_PATH = "/tmp/tpch-generated" private var runner: TPCRunner = _