社内se × プログラマ × ビッグデータ

プログラミングなどITに興味があります。

(自分用) Apache Spark QUIZ 1

Q1. In spark-shell, How to specify multiple dependencies using --packages for spark-submit?
(spark-shell において、複数の依存パッケージをロードするには、--packages でどのように指定すれば良いか ?)

Q2. What is this warning meaning in spark streaming?
(spark-streaming においてこの warning は何を意味するか ?)

replicated to only 0 peer(s) instead of 1 peers

Q3. What is this warning meaning in spark ?
(spark においてこの warning は何を意味するか ?)

Initial job has not accepted any resources; check your cluster UI to ensure that workers are registered and have sufficient resources

Q4. What is "window length" and "slide interval" in spark-streaming?
(spark-streaming におけるウインドウ集計で、「ウインドウ幅」と「スライド幅」それぞれの意味は ?)

Q5. How to create pair-RDD(key, value) ?
(ペア RDD をどのように作成するか?)

val pairRdd = rdd.??? { r => {
(r, 1)
}}

Q6. What is the final response ?
(以下のコマンドの最終レスポンスは ?)

scala> rdd.collect
res1: Array[String] = Array(a, b, c, b)

scala> rdd.map { r => {
     | if (r != "b")(r,1)
     | }}.collect
res2: Array[Any] = ???

Q7. How to save as text from RDD ?
RDDのデータをテキストとして出力するには?)

Q8. What is the final response ?
(以下のコマンドの最終レスポンスは ?)

scala> rdd.collect
res1: Array[String] = Array(a, b, c, b)

scala> rdd.map { r => {
     | if (r != "b")(r,1)
     | else null
     | }}.collect
res2: Array[(String, Int)] = ???

Q9. What is the final response ?
(以下のコマンドの最終レスポンスは ?)

scala> pairRdd.collect
res1: Array[(String, Int)] = Array((a,1), (b,1), (c,1), (b,1))

scala> pairRdd.reduceByKey((x,y) => x+y).collect
res1: Array[(String, Int)] = ???

Q10. What are these commands meaning in spark-streaming ?
(spark-streaming におけるこれらのコマンドの意味は ?)

ssc.start()
ssc.awaitTermination()

(解答例)
=========================================-
A1. A list of packages should be separated using commas without whitespaces
(空白なしでコンマ区切りで指定すること)

--packages org.apache.bahir:spark-streaming-twitter_2.11:2.3.2,com.atilika.kuromoji:kuromoji-ipadic:0.9.0

A2. The warning in this case means that incoming data from stream are not replicated at all. The reason for that may be that you run the app with just one instance of Spark worker or running in local mode.
(このケースではデータのレプリカが作成されていない警告であると考えられる。Spark の Worker のインスタンスが1つだけしか起動していない場合に発生しうる)

A3. The error indicates that you cluster has insufficient resources for current job.Since you have not started the slaves i.e worker.
(Worker のインスタンスが存在していないため、そのジョブが開始できないことを意味していると考えられる)

A4. window length means "Scope of one window aggregation", slide interval means "Time difference until the next window tabulation starts".
(一回のウインドウ集計の集計範囲を「ウインドウ幅」、次のウインドウ集計が開始するまでの時間差を「スライド幅」)

A5.

val pairRdd = rdd.map { r => {
(r, 1)
}}

A6.

res2: Array[Any] = Array((a,1), (), (c,1), ())

A7.

rdd.saveAsTextFile("file:///share/outout/result")

※part-xxxx というファイル名で保存される

A8.

res2: Array[(String, Int)] = Array((a,1), null, (c,1), null)

A9.

res1: Array[(String, Int)] = Array((b,2), (a,1), (c,1))

A10.
ssc.start()
>Starts streaming calculation.
(計算処理を開始)

ssc.awaitTermination()
>Waits till closed context or thrown exception.
(stopメソッドによるcontextの終了や例外が発生するまで待つ)