title: How to validate DataFrame Row on the basis of priority validation rule?
body: <p>I want to validate <code>DataFrame</code> on the basis of certain rules consist in another  <code>DataFrame</code> named as Rule.
  What is the best way to validate input <code>DataFrame</code> on the basis of Rule <code>DataFrame</code>, if any row applicable for multiple rules check then get only highest priority validation and give data as below: </p>
  
  <p><strong>Input DataFrame:</strong></p>
  
  <pre><code>+---+----+----+-------+-------+-----+-----+-----+-----+
  | Id|Name|City|Country|Pincode|flatA|flagB|flagC|flagD|
  +---+----+----+-------+-------+-----+-----+-----+-----+
  |  1|   A| MUM|  INDIA| 100010| null|    Y|    Y| null|
  |  2|   B| MUM|  INDIA| 200020| null| null|    Y| null|
  |  3|   C| MUM|  INDIA| 100030| null| null| null|    Y|
  |  4|   D| MUM|  INDIA| 500050|    Y|    Y| null| null|
  |  5|   E| MUM|  INDIA|3078787| null| null|    Y|    Y|
  +---+----+----+-------+-------+-----+-----+-----+-----+
  </code></pre>
  
  <p><strong>Rule Dataframe:</strong></p>
  
  <pre><code>+------+----+-------+-----+-----+-----+-----+-------+--------+
  |Rules#|City|Country|flatA|flagB|flagC|flagD|Pincode|Priority|
  +------+----+-------+-----+-----+-----+-----+-------+--------+
  |     1| MUM|  INDIA| null|    Y| null| null| 100010|       3|
  |     2| MUM|  INDIA| null| null|    Y| null| 200020|       4|
  |     3| MUM|  INDIA| null| null| null|    Y| 300030|       6|
  |     4| MUM|  INDIA| null|    Y|    Y| null| 400040|       2|
  |     5| MUM|  INDIA|    Y|    Y| null| null| 500050|       1|
  |     6| MUM|  INDIA| null| null|    Y|    Y| 600060|       5|
  +------+----+-------+-----+-----+-----+-----+-------+--------+
  </code></pre>
  
  <p><strong>Expected Output:</strong></p>
  
  <pre><code>+---+----+----+-------+-------+-----+-----+-----+-----+--------------+-----------+
  | Id|Name|City|Country|Pincode|flatA|flagB|flagC|flagD|ValidationFlag|New_PinCode|
  +---+----+----+-------+-------+-----+-----+-----+-----+--------------+-----------+
  |  1|   A| MUM|  INDIA| 100010| null|    Y|    Y| null|         FALSE|     400040|
  |  2|   B| MUM|  INDIA| 200020| null| null|    Y| null|          TRUE|     200020|
  |  3|   C| MUM|  INDIA| 100030| null| null| null|    Y|         FALSE|     300030|
  |  4|   D| MUM|  INDIA| 500050|    Y|    Y| null| null|          TRUE|     500050|
  |  5|   E| MUM|  INDIA|3078787| null| null|    Y|    Y|         FALSE|     200020|
  +---+----+----+-------+-------+-----+-----+-----+-----+--------------+-----------+
  </code></pre>
  
  <p>As per example above, for <code>Id #1</code> in <code>Input Dataframe</code> <strong>rules 1,2 &amp; 4</strong> all are applicable but it has picked <strong>Rule#4</strong> as per priority. </p>
  
  <p>Rule check logic are as below:</p>
  
  <blockquote>
    <p><strong>Priority 2:</strong> Input.City == Rule.City AND Input.Country == Rule.Country
    AND Input.flagB == Y AND Input.flagC == Y</p>
    
    <p><strong>Priority 3:</strong> Input.City ==
    Rule.City AND Input.Country == Rule.Country AND  Input.flagB == Y</p>
    
    <p><strong>Priority 4:</strong> Input.City == Rule.City AND Input.Country == Rule.Country
    AND Input.flagC == Y</p>
    
    <p>Any  null Column in Rule DataFrame should be ignore in AND condition</p>
  </blockquote>
  
  <p>Value of new Column <code>ValidationFlag</code> in <code>Output DataFrame</code> will be <code>False</code> if <code>new_PinCode</code> does not match with <code>PinCode</code> column otherwise it will be <code>True</code>. Another new Column <code>new_PinCode</code> contain the <code>PinCode</code> which get from <code>Rule Dataframe</code> on the basis of priority.</p>