Created
December 20, 2021 11:42
-
-
Save 1ambda/41014a26c0dc15e59ee1998c8150880c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def camelToUnderscores(name: String) = "[A-Z\\d]".r.replaceAllIn(name, {m => | |
"_" + m.group(0).toLowerCase() | |
}) | |
def underscoresToCamel(name: String) = { | |
val splitted = name.split("_") | |
val converted = splitted.head.toLowerCase() +: splitted.tail.map(_.capitalize) | |
converted.mkString | |
} | |
val columnsLower = df.columns.map(x => col(x).as(x.toLowerCase)) | |
val columnsCamel = df.columns.map(x => col(x).as(underscoresToCamel(x))) | |
val dfLower = df.select(columnsLower: _*) | |
val dfCamel = df.select(columnsCamel: _*) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment