title: Row with schema returns null for row.schema
body: <p>I know that you would expect code for this, but the code looks fine and I am unable to understand what's going wrong though. I would explain the problem and let's see if you could tell me if I am missing something obvious.</p>
  
  <p>I have written an implicit class for <code>Row</code>, a function in which uses the <code>row.schema</code> to get the schema. What's funny though that <code>row.schema</code> always returns <code>null</code> in the implicit class whether the row object has a schema or not, whereas the same returns the actual schema, in the class containing the unit test (I use <code>FlatSpec with Matchers</code> for unit testing). This is how the row is constructed in the unit test.</p>
  
  <pre><code>val schema = StructType(
    StructField("col1", StringType) ::
    StructField("col2", DoubleType) ::
    StructField("col3", IntegerType) ::
    Nil)
  val values = Array("value1", 1.0, 1)
  val row: Row = new GenericRowWithSchema(values, schema)
  </code></pre>
  
  <p>I check the source in the Spark code base and this is how the <code>schema</code> function is implemented.</p>
  
  <pre><code>def schema: StructType = null
  </code></pre>
  
  <p>which confused me even further. Any pointers?</p>
  
  <p><strong>Edit:</strong> I should have known no code doesn't really help. So here's the code. Check the <code>getAsOpt[T](i)</code> (<a href="https://github.com/aa8y/spark/blob/getAsOpt/sql/catalyst/src/main/scala/org/apache/spark/sql/Row.scala#L323" rel="nofollow">here</a>) and <code>getAsOpt[T](fieldName)</code> (<a href="https://github.com/aa8y/spark/blob/getAsOpt/sql/catalyst/src/main/scala/org/apache/spark/sql/Row.scala#L346" rel="nofollow">here</a>) functions in <a href="https://github.com/aa8y/spark/blob/getAsOpt/sql/catalyst/src/main/scala/org/apache/spark/sql/Row.scala" rel="nofollow">this code</a> for <code>Row</code> and the corresponding tests <a href="https://github.com/aa8y/spark/blob/getAsOpt/sql/catalyst/src/test/scala/org/apache/spark/sql/RowTest.scala" rel="nofollow">here</a>.</p>
  
  <p>Here's how the ones which fail, fail,</p>
  
  <pre><code>[info] - getAsOpt[T]() can get values using field names. *** FAILED *** (8 milliseconds)
  [info]   None was not equal to Some("value1") (RowTest.scala:85)
  ...
  [info] - getAsOpt[T] retrieves an Optional value if the fieldName exists  else returns None *** FAILED *** (1 millisecond)
  [info]   None was not equal to Some("value1") (RowTest.scala:91)
  ...
  [info] - getAsOpt[T] retrieves an Optional value if class cast is successful else returns None *** FAILED *** (0 milliseconds)
  [info]   None was not equal to Some("value1") (RowTest.scala:97)
  </code></pre>