Shankar Shankar - 1 month ago 11
Scala Question

How does $ symbol working when selecting columns from DataFrame?

when we try to select Columns from DataFrame, one can use

$"columnname"
or
col("columnname")
or just
"columnname"
.

My question is how
$ symbol
[which returns ColumnName] is working, i can understand i need to
import sqlContext.implicits._
to use $ symbol on
df.select


I dont see
$ method
on
SQLImplicits
class as well. I can see one method with the name
symbolToColumn(scala.Symbol s)
.

Can someone explain more on this?

Answer

It comes from StringToColumn implicit inner class in SQLImplicits (which is implemented by the implicits object).

StringContext is the way that f / s and other string interpolators are written in Scala.