:)
I would like to refer the variable name (just the name, no the value) in a case class.
Next it is a very simplified example:
case class Person(name: String, age: Int)
val schema = Encoders.products[Person].schema
val jack = Person("name", 20)
override def method[Person](df: DataFrame) : DataFrame = {
df.withColumn("json", from_json(col("column_value"), schema))
.select("json.*")
.withColumn(jack.name, trim(col(jack.name)))
.withColumn(jack.age, col(jack.age) + 2)
}
Of course, jack.name will return the value, which is a String and works well to my propouse. But as you can already imagine, jack.age will give me the value, no "age".
So far, I get this, which I think is a really ugly and inefficient solution:
val onlyNames: Seq[String] = schema.map(_.name)
...
.withColumn(...)
.withColumn(onlyNames(2), col(onlyNames(2)) + 2)
Versions: Spark 2.3.0 // Scala 2.11.8