Last active
June 5, 2019 19:14
-
-
Save dmateusp/aeae8d07a3964baa0fb089be9be21ffa to your computer and use it in GitHub Desktop.
DataFrame.transform - Spark Function Composition - Functions post refactor
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 sumAmounts(by: Column*): DataFrame => DataFrame = | |
df => df.groupBy(by: _*).agg(sum(col("amount"))) | |
def extractPayerBeneficiary(columnName: String): DataFrame => DataFrame = | |
df => | |
df.withColumn( | |
s"${columnName}_payer", | |
regexp_extract( | |
col(columnName), | |
"paid by ([A-Z])", | |
1 | |
) | |
).withColumn( | |
s"${columnName}_beneficiary", | |
regexp_extract( | |
col(columnName), | |
"to ([A-Z])", | |
1 | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment