How to validate history data?

前端 未结 1 2015
情深已故
情深已故 2021-01-28 08:19

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

相关标签:
1条回答
  • 2021-01-28 08:36

    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

    0 讨论(0)
提交回复
热议问题