2016-01-24 14 views
7

Poniższy przykładowy kod znajduje się w książce Advanced Analytics with Spark. Kiedy załadować go do zapłonowej-shell (wersja 1.4.1) daje następujący błąd, wskazując, że nie może znaleźć StatCounter:Dlaczego ten przykładowy kod Sparka nie zostanie załadowany w iskrze?

import org.apache.spark.util.StatCounter 
<console>:9: error: not found: type StatCounter 
     val stats: StatCounter = new StatCounter() 
       ^
<console>:9: error: not found: type StatCounter 
     val stats: StatCounter = new StatCounter() 
            ^
<console>:23: error: not found: type NAStatCounter 
     def apply(x: Double) = new NAStatCounter().add(x) 

Jeżeli po prostu wykonaj następujące czynności w zapłonowej-shell nie ma problemu :

scala> import org.apache.spark.util.StatCounter 
import org.apache.spark.util.StatCounter 

scala> val statsCounter: StatCounter = new StatCounter() 
statsCounter: org.apache.spark.util.StatCounter = (count: 0, mean: 0.000000, stdev: NaN, max: -Infinity, min: Infinity) 

Problem wydaje się być związany z komendą: load iskrzenia.

Oto kod:

import org.apache.spark.util.StatCounter 
class NAStatCounter extends Serializable { 
    val stats: StatCounter = new StatCounter() 
    var missing: Long = 0 

    def add(x: Double): NAStatCounter = { 
     if (java.lang.Double.isNaN(x)) { 
      missing += 1 
     } else { 
     stats.merge(x) 
     } 
     this 
    } 

    def merge(other: NAStatCounter): NAStatCounter = { 
     stats.merge(other.stats) 
     missing += other.missing 
     this 
    } 

    override def toString = { 
     "stats: " + stats.toString + " NaN: " + missing 
    } 
} 

object NAStatCounter extends Serializable { 
    def apply(x: Double) = new NAStatCounter().add(x) 
} 
+0

Czy biblioteka w klasie ścieżka? Czy możesz nam powiedzieć, gdzie znajduje się ta biblioteka i wydrukować ścieżkę do biblioteki? –

+4

Stwierdziłem, że muszę w pełni zakwalifikować StatCounter podczas deklarowania go, mimo że go zaimportowałem: 'val stats: org.apache.spark.util.StatCounter = new org.apache.spark.util.StatCounter()' –

+0

To jest w domyślnie ścieżka klas. Przykład dwóch linii z iskiernika w środkowym bloku kodu pokazuje to. Po załadowaniu pliku pojawia się problem. –

Odpowiedz

3

Mam dokładnie ten sam problem z wami.
go rozwiązać jak próbował,
ZMIANA

val stats: StatCounter = new StatCounter() 

INTO

val stats: org.apache.spark.util.StatCounter = new org.apache.spark.util.StatCounter() 

powodem jest być może system nie wiem ścieżkę StatCounter

+0

Dodaj kolorowanie składni do kodu źródłowego. – Robson

Powiązane problemy