'udf No TypeTag available for type string

I don't understand a behavior of spark.

I create an udf which returns an Integer like below

import org.apache.spark.sql.SQLContext
import org.apache.spark.{SparkConf, SparkContext}

object Show {

  def main(args: Array[String]): Unit = {


    val (sc,sqlContext) = iniSparkConf("test")
    val testInt_udf = sqlContext.udf.register("testInt_udf", testInt _)

  }

  def iniSparkConf(appName: String): (SparkContext, SQLContext) = {
    val conf = new SparkConf().setAppName(appName)//.setExecutorEnv("spark.ui.port", "4046")
    val sc = new SparkContext(conf)
    sc.setLogLevel("WARN")
    val sqlContext = new SQLContext(sc)

    (sc, sqlContext)
  }
  def testInt() : Int= {
    return 2
  }
}

I work perfectly but if I change the return type of method test from Int to String

val testString_udf = sqlContext.udf.register("testString_udf", testString _)
def testString() : String = {
  return "myString"
}

I get the following error

Error:(34, 43) No TypeTag available for String
    val testString_udf = sqlContext.udf.register("testString_udf", testString _)
Error:(34, 43) not enough arguments for method register: (implicit evidence$1: reflect.runtime.universe.TypeTag[String])org.apache.spark.sql.UserDefinedFunction.
Unspecified value parameter evidence$1.
    val testString_udf = sqlContext.udf.register("testString_udf", testString _)

here are my embedded jars:

datanucleus-api-jdo-3.2.6
datanucleus-core-3.2.10
datanucleus-rdbms-3.2.9
spark-1.6.1-yarn-shuffle
spark-assembly-1.6.1-hadoop2.6.0
spark-examples-1.6.1-hadoop2.6.0

I am a little bit lost... Do you have any idea?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source