nerdexam
Huawei

H13-723_V2.0 · Question #138

In Spark application development, which of the following codes can correctly count words?

The correct answer is B. val counts = textFile.flatMap (line=>line.split (" ")).map (word => (word, 1)).reduceByKey(_ +_). See the full explanation below for the reasoning.

Question

In Spark application development, which of the following codes can correctly count words?

Options

  • Aval counts = textFile.map (line => line.split ("')).map (-rd => (word, 1)).reduceByKey(_ +_)
  • Bval counts = textFile.flatMap (line=>line.split (" ")).map (word => (word, 1)).reduceByKey(_ +_)
  • Cval counts = textFile.map (line=>line.split (" ")).map (word => (word, 1)).groupByKey ()
  • Dval counts = textFile.flatMap (line=>line.split (" ")).map (word => (word, 1)).groupByKey ()

How the community answered

(49 responses)
  • A
    4% (2)
  • B
    71% (35)
  • C
    8% (4)
  • D
    16% (8)

Community Discussion

No community discussion yet for this question.

Full H13-723_V2.0 Practice