databricks / LearningSparkV2

This is the github repo for Learning Spark: Lightning-Fast Data Analytics [2nd Edition]
https://learning.oreilly.com/library/view/learning-spark-2nd/9781492050032/
Apache License 2.0
1.17k stars 723 forks source link

Error p138. Chapter 5 - Higher-Order Functions in DataFrames and Spark SQL #56

Closed raybellwaves closed 3 years ago

raybellwaves commented 4 years ago

Under Option 2: User-Defined Function the code is copied from the example above (Option 1: Explode and Collect). I believe it's missing a UDF that uses map

IMG_5158

dennyglee commented 3 years ago

Thanks, @raybellwaves - this has been submitted and will be addressed via the Learning Spark 2nd Edition Errata.

Quick note, the code in question should actually be:

// In Scala
def addOne(values: Seq[Int]): Seq[Int] = {
    values.map(value => value + 1)
}
val plusOneInt = spark.udf.register("plusOneInt", addOne(_: Seq[Int]): Seq[Int])

Thanks again!