title: Dataset Filter working in an unexpected way
body: <p>Scenario:
  I have read two XML files via specifying a schema on load.</p>
  
  <p>In the schema, One of the tags is mandatory. One XML is missing that mandatory tag.</p>
  
  <p>Now, when I do the following, I am expecting the XML with the missing mandatory tag to be filtered out.</p>
  
  <pre><code>dataset = dataset.filter(functions.col("mandatoryColumnNameInSchema").isNotNull());
  </code></pre>
  
  <p>In the code when I try to count the Rows of the dataset, I am getting the count as 2 (2 Input XMLS) but when I try to print the dataset via show() method, I am getting a NPE.</p>
  
  <p>When I debugged the above line and do the following, I get 0 as the count.</p>
  
  <pre><code>dataset.filter(functions.col("mandatoryColumnNameInSchema").isNotNull()).count();
  </code></pre>
  
  <p>Question:</p>
  
  <p>Can anyone please answer the questions/affirm my understanding below</p>
  
  <ol>
  <li>Why is spark Dataset not filtering the Row which does not have a mandatory column?</li>
  <li>Why there are no exception in the count but in show method?</li>
  </ol>
  
  <p>For 2, I believe the count is just counting no of Rows without looking into the contents.
  For show, the iterator actually goes through the Struct Fields to print their values and when it does not find the mandatory column, it errors out.</p>
  
  <p>P.S. If I make the mandatory column optional, all is working fine.</p>
  
  <p>Edit:</p>
  
  <p>Providing Reading options as requested</p>
  
  <p>For loading the data I am executing the following</p>
  
  <pre><code>Dataset&lt;Row&gt; dataset = sparkSession.read().format("com.databricks.spark.xml")
                  .option("header", "true")
                  .option("inferSchema", "false")
                  .option("rowTag", rowTag)//rowTag is "body" tag in the XML
                  .option("failFast", "true")
                  .option("mode", "FAILFAST")
                  .schema(schema)
                  .load(XMLfilePath);
  </code></pre>
  
  <p>Providing samples as requested</p>
  
  <p>Schema:</p>
  
  <pre><code>root
   |-- old: struct (nullable = true)
   |    |-- _beyond: string (nullable = true)
   |    |-- lot: struct (nullable = true)
   |    |    |-- _VALUE: string (nullable = true)
   |    |    |-- _chose: string (nullable = true)
   |    |-- real: struct (nullable = true)
   |    |    |-- _eat: string (nullable = true)
   |    |    |-- kill: struct (nullable = true)
   |    |    |    |-- _VALUE: double (nullable = true)
   |    |    |    |-- _top: string (nullable = true)
   |    |    |-- tool: struct (nullable = true)
   |    |    |    |-- _VALUE: string (nullable = true)
   |    |    |    |-- _affect: string (nullable = true)
   |-- porch: struct (nullable = true)
   |    |-- _account: string (nullable = true)
   |    |-- cast: string (nullable = true)
   |    |-- vegetable: struct (nullable = true)
   |    |    |-- leg: struct (nullable = true)
   |    |    |    |-- _VALUE: double (nullable = true)
   |    |    |    |-- _nose: string (nullable = true)
   |    |    |-- now: struct (nullable = true)
   |    |    |    |-- _gravity: string (nullable = true)
   |    |    |    |-- chief: struct (nullable = true)
   |    |    |    |    |-- _VALUE: long (nullable = true)
   |    |    |    |    |-- _further: string (nullable = true)
   |    |    |    |-- field: string (nullable = true)
  </code></pre>
  
  <p>Sample XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;root&gt;
      &lt;body&gt;
      &lt;porch account="something"&gt;
          &lt;vegetable&gt;
              &lt;now gravity="wide"&gt;
                  &lt;field&gt;box&lt;/field&gt;
                  &lt;chief further="satisfied"&gt;-1889614487&lt;/chief&gt;
              &lt;/now&gt;
              &lt;leg nose="angle"&gt;912658017.229279&lt;/leg&gt;
          &lt;/vegetable&gt;
          &lt;cast&gt;clear&lt;/cast&gt;
      &lt;/porch&gt;
      &lt;old beyond="continent"&gt;
          &lt;real eat="term"&gt;
              &lt;kill top="plates"&gt;-1623084908.8669372&lt;/kill&gt;
              &lt;tool affect="pond"&gt;today&lt;/tool&gt;
          &lt;/real&gt;
          &lt;lot chose="swung"&gt;promised&lt;/lot&gt;
      &lt;/old&gt;
      &lt;/body&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>Schema in JSON format:</p>
  
  <pre><code>{"type":"struct","fields":[{"name":"old","type":{"type":"struct","fields":[{"name":"_beyond","type":"string","nullable":true,"metadata":{}},{"name":"lot","type":{"type":"struct","fields":[{"name":"_VALUE","type":"string","nullable":true,"metadata":{}},{"name":"_chose","type":"string","nullable":true,"metadata":{}}]},"nullable":true,"metadata":{}},{"name":"real","type":{"type":"struct","fields":[{"name":"_eat","type":"string","nullable":true,"metadata":{}},{"name":"kill","type":{"type":"struct","fields":[{"name":"_VALUE","type":"double","nullable":true,"metadata":{}},{"name":"_top","type":"string","nullable":true,"metadata":{}}]},"nullable":true,"metadata":{}},{"name":"tool","type":{"type":"struct","fields":[{"name":"_VALUE","type":"string","nullable":true,"metadata":{}},{"name":"_affect","type":"string","nullable":true,"metadata":{}}]},"nullable":true,"metadata":{}}]},"nullable":true,"metadata":{}}]},"nullable":true,"metadata":{}},{"name":"porch","type":{"type":"struct","fields":[{"name":"_account","type":"string","nullable":true,"metadata":{}},{"name":"cast","type":"string","nullable":true,"metadata":{}},{"name":"vegetable","type":{"type":"struct","fields":[{"name":"leg","type":{"type":"struct","fields":[{"name":"_VALUE","type":"double","nullable":true,"metadata":{}},{"name":"_nose","type":"string","nullable":true,"metadata":{}}]},"nullable":true,"metadata":{}},{"name":"now","type":{"type":"struct","fields":[{"name":"_gravity","type":"string","nullable":true,"metadata":{}},{"name":"chief","type":{"type":"struct","fields":[{"name":"_VALUE","type":"long","nullable":true,"metadata":{}},{"name":"_further","type":"string","nullable":true,"metadata":{}}]},"nullable":true,"metadata":{}},{"name":"field","type":"string","nullable":true,"metadata":{}}]},"nullable":true,"metadata":{}}]},"nullable":true,"metadata":{}}]},"nullable":true,"metadata":{}}]}
  </code></pre>
  
  <p>My scenario can be reproduced by making the element "old" as nullable = false, and removing the tag from the XML</p>