Created
February 17, 2018 10:08
-
-
Save YordanGeorgiev/fcccaa2c17746fcc6a3b42bd7f3af9c4 to your computer and use it in GitHub Desktop.
[fold left usage in scala spark] how-to use fold left in scala on a dataframe obj
This file contains hidden or 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
// START foldLeft usage | |
val outDf: DataFrame = lstColumnsToIterate | |
.foldLeft(inDf)((tmpDf, iterableColToAdd) => { | |
tmpDf.withColumn(iterableColToAdd,expr(funcToApply).as(iterableColToAdd)) | |
}) | |
.groupBy(lstGroupByCols.distinct.head, lstGroupByCols.distinct.tail: _*) | |
.agg(lstAggregationCols.distinct.head, lstAggregationCols.distinct.tail: _*) | |
// STOP foldLeft usage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment