2017-06-19 3 views
0

je l'ai fait ce code sur l'environnement de databricks mais quand je l'essayer sur mon env local, il se casse ...UDF en utilisant des méthodes Java déferle sur étincelle

val _event_day_of_week = (event_date_of_event: String) => { 
    import java.time.LocalDate 
    import java.time.format.DateTimeFormatter 

    val formatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd") 
    val dayOfWeek: String = LocalDate.parse(event_date_of_event.substring(0,10), formatter).getDayOfWeek.toString 
    dayOfWeek 
    } 

    val event_day_of_weekUDF = udf(_event_day_of_week) 

df.select($"uuid", event_day_of_weekUDF($"event_date_of_event") as "event_day_of_week").first 

Erreur:

Exception in thread "main" java.lang.NullPointerException 
    at com.faniak.ml.eventBuzz$.delayedEndpoint$com$faniak$ml$eventBuzz$1(eventBuzz.scala:72) 
    at com.faniak.ml.eventBuzz$delayedInit$body.apply(eventBuzz.scala:17) 
    at scala.Function0$class.apply$mcV$sp(Function0.scala:34) 
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12) 
    at scala.App$$anonfun$main$1.apply(App.scala:76) 
    at scala.App$$anonfun$main$1.apply(App.scala:76) 
    at scala.collection.immutable.List.foreach(List.scala:381) 
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35) 
    at scala.App$class.main(App.scala:76) 
    at com.faniak.ml.eventBuzz$.main(eventBuzz.scala:17) 
    at com.faniak.ml.eventBuzz.main(eventBuzz.scala) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) 

version Spark 2.1

+0

Est-ce que votre classe Main étend l'application au lieu d'utiliser une méthode principale? C'est connu pour causer des problèmes avec étincelle. De plus, votre fonction ne vérifie nullement, assurez-vous que vous n'avez pas de null dans cette colonne. – puhlen

+0

Connexe: [Qu'est-ce qu'une exception NullPointerException, et comment puis-je la réparer?] (Https://stackoverflow.com/q/218384) – dorukayhan

+0

@puhlen Salut, oui, il étend App. Êtes-vous en train de dire que c'est le problème? En ce qui concerne les nulls, je n'en ai aucun. –

Répondre

1

Le problème n'a rien à voir avec les fonctions UDF. Lorsque le prototypage sur Apache Spark ne prolonge pas l'application de la classe scala car il ne fonctionne pas correctement avec spark.

object EventBuzzDataset extends App{ 

Afin de vous travailler devrait droite:

object EventBuzzDataset{ 

    def main(args: Array[String]) 

Le problème est bien détaillé ici: https://issues.apache.org/jira/browse/SPARK-4170 et https://github.com/apache/spark/pull/3497

thansk à @puhlen pour l'astuce!