scala when-otherwise for date iteration

Viewed 37

i'm trying to use a when-otherwise condition in scala for grabbing data for a particular date. If no data exists for a particular date, the code should look for data in the previous day. If it does not find any matching data for the previous day, it should go one day further back and look for data. This process should try fetching data every previous day for upto 30 days after which the code should terminate in case of no matching data found. Can you please help me code this? I'm looking at when-otherwise currently but need help with iteration. Any alternate approaches are also welcome, thank you.

[psuedoCode]

val df2 = df.withColumn("date", when(col("date") === 
"09-19-2022").otherwise("go one day back"))..
0 Answers
Related