Raghava
Raghava

Reputation: 967

too many arguments for method apply: (i: Int)String in class Array

I have an RDD (r2Join1) which holds the following data

(100,(102|1001,201))
(100,(102|1001,200))
(100,(103|1002,201))
(100,(103|1002,200))
(150,(151|1003,204))

I want to transform this to the following

(102, (1001, 201))
(102, (1001, 200))
(103, (1002, 201))
(103, (1002, 200))
(151, (1003, 204))

i.e., I want to transform (k, (v1|v2, v3)) to (v1, (v2, v3)).

I did the following:

val m2 = r2Join1.map({case (k, (v1, v2)) => val p: Array[String] = v1.split("\\|") (p(0).toLong, (p(1).toLong, v2.toLong))})

I get the following error

error: too many arguments for method apply: (i: Int)String in class Array

I am new to Spark & Scala. Please let me know how this error can be resolved.

Upvotes: 0

Views: 4751

Answers (1)

Justin Pihony
Justin Pihony

Reputation: 67075

The code looks like it might be off in other areas, but without the rest I can't be sure, so at minimum this should get you moving you need either a semicolon after your split or to put the two separate statements on separate lines.

v1.split("\\|");(p(0).toLong, (p(1).toLong, v2.toLong))

Without the semicolon the compiler is interpreting it as:

v1.split("\\|").apply(p(0).toLong...)

where apply acts as an indexer of the array in this case.

Upvotes: 3

Related Questions