-1

I am trying to make sense of the following code snippet. I think this more of a Scala than a Spark question...

    val links = sc.textFile("../../data/links.csv")

    val linksRDD: RDD[Edge[Connexion]] = links map {line => 
        val row = line split ','
        Edge(row(0).toInt, row(1).toInt, row(2))
    }

I am used to seeing the following type of idiom in regards to calling the Spark map() function on an RDD:

 links.map{line => val fields = line.split(","); val f1 = x._1; (f1, "stuff)}

My question is: that I cannot understand the construct:

 val row = line split ','

All the (very limited) Spark examples that I so far see following the pattern:

 val row = line.split(',')

I feel as though in rushing through my basic Spark tutorials in order to get to Scala, that I have missed something rather basic.

Can somebody please tell me what I have missed...?

Thanks

markthekoala
  • 1,065
  • 1
  • 11
  • 24
  • 1
    You are correct @pedrofurla this is a duplicate. The question that you linked to is probably more comprehensively framed and answered. – markthekoala Jun 11 '17 at 00:00

1 Answers1

1

Scala has a special punctuation-free syntax for invoking methods that take one argument which is called infix notations so:

line.split(',')

is equivalent to:

line split ','
tmucha
  • 689
  • 1
  • 4
  • 19
Ramesh Maharjan
  • 41,071
  • 6
  • 69
  • 97
  • Thanks heaps @Ramesh. So if a method takes more than 1 argument I have to use the second construct...? – markthekoala Jun 10 '17 at 10:08
  • yes you got it right. – Ramesh Maharjan Jun 10 '17 at 10:09
  • @markthekoala: I am quite surprised that you have never seen punctuation-free syntax in Scala before, e.g. something like `1 + 2`. – Jörg W Mittag Jun 10 '17 at 12:02
  • Thanks @JörgWMittag. I have not seen `line split ','` before but certainly have seen `line.split(',')` According to http://docs.scala-lang.org/style/method-invocation.html suggest that `line.split(',')` is preffered. And contrary to @Ramesh 's initial answer it also appears that the syntax `line.split(',')` can be used when the method accepts more than one parameter. – markthekoala Jun 10 '17 at 22:44