0

I am not able to fetch values for given dynamic columns. Any help ?

var dynamicColumns = "col(\"one\"),col(\"two\"),col(\"three\")"

dataFrame.select(dynamicColumns)

1 Answer 1

1

Just use names alone:

val dynamicColumns = Seq("one", "two", "three")
dataFrame.select(dynamicColumns map col: _*)

and if you don't have control over the format, use regexp to extract names first

val dynamicColumns = "col(\"one\"),col(\"two\"),col(\"three\")"
val p = """(?<=col\(").+?(?="\))""".r

dataFrame.select(p.findAllIn(dynamicColumns) map col toSeq: _*)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.