Currently we are reading date using calendar instance for picking last one month record using sparksql. Now we need: In case of extra events being added to previous day we must
You can use filter
function to select records in range like below
//Input df
+---+----------+----------+
| cd|start_date| end_date|
+---+----------+----------+
| M|2018-01-01|2018-01-31|
| D|2018-05-03|2018-05-03|
| D|2018-03-27|2018-03-27|
+---+----------+----------+
//Parameter startDate and endDate
val endDate="2018-05-03"
val endDate="2018-05-03"
//Filter condition
df.filter(s"start_date>='$startDate' and end_date<='$endDate'").show
//Sample Output:
+---+----------+----------+
| cd|start_date| end_date|
+---+----------+----------+
| D|2018-05-03|2018-05-03|
| D|2018-03-27|2018-03-27|
+---+----------+----------+
I hope this will help you, If you want to do any calculation on filtered records then you have to pass columns to udf