2017-07-19 3 views

答えて

2

それは解決策の1つです(そして、最も効果的ではないでしょう)。

// using col function as the OP uses Java not Scala...unfortunatelly 
import org.apache.spark.sql.functions.col 
val q = spark. 
    read. 
    text("README.md"). 
    filter(length(col("value")) > 0). 
    withColumn("words", split(col("value"), "\\s+")). 
    select(explode(col("words")) as "word"). 
    groupBy("word"). 
    count. 
    orderBy(col("count").desc) 
scala> q.show 
+---------+-----+ 
|  word|count| 
+---------+-----+ 
|  the| 24| 
|  to| 17| 
| Spark| 16| 
|  for| 12| 
|  and| 9| 
|  ##| 9| 
|   | 8| 
|  a| 8| 
|  on| 7| 
|  can| 7| 
|  run| 7| 
|  in| 6| 
|  is| 6| 
|  of| 5| 
| using| 5| 
|  you| 4| 
|  an| 4| 
| build| 4| 
|including| 4| 
|  with| 4| 
+---------+-----+ 
only showing top 20 rows 
+0

私はスカラではないJavaベースのAPIを使用しています – sathiyarajan

+0

あなたが気づいた違いはありますか?私は好奇心が強いですが(自分自身をチェックするのが面倒すぎます)。 –

+0

col(String)メソッドが定義されていません – sathiyarajan

関連する問題