Does anyone if there is a way to dynamically build a pyspark command from config input?
I'm trying to end up with a command that ends up something like;
newDF = df.select('*', when(df.a == 1,'1').when(df.a == 2, '2').alias('new_col') )
The when expressions are variable in number, and content. So could be something like;
conditions =
[
"when(df.a == 'something')",
"when(df.a >= 'something else')"
]
I can design the structure of the conditions, so that part is to be decided. It's more how I could build a command using this approach, without spark thinking I am trying to pass it a string. My first attempt looked like;
command = ".when(df.a == '1', 'something').when(df.a == '2', 'somethingelse')"
newDF = df.select("*", command)
However, the error I get, is Spark doesn't like that I'm passing a string.
Any help appreciated!