Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save YordanGeorgiev/fcccaa2c17746fcc6a3b42bd7f3af9c4 to your computer and use it in GitHub Desktop.
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
// 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