title: spark - nvl function data type mismatch error
body: <p>Using JDBC datasource in Spark sql we try to run below query</p>
  
  <pre><code>select nvl( columnName , 1.0) from tablename
  </code></pre>
  
  <p>gives error as</p>
  
  <pre><code>cannot resolve 'nvl(tablename.`columnname`, 1.0BD)' due to data type mismatch: input to function coalesce should all be the same type, but it's [decimal(38,10), decimal(2,1)]
  </code></pre>
  
  <p>I know we can solve this with </p>
  
  <pre><code>select nvl( columnname , CAST( 1.0 as decimal(38,10))) from tablename
  </code></pre>
  
  <p>looks like i need to find the datatype of each and every column and cast to it. </p>
  
  <ol>
  <li>Is there any other way to handle it?</li>
  <li>Can i give schema definition upfront while loading the dataframe like csv format. [<a href="https://issues.apache.org/jira/browse/SPARK-16848]" rel="nofollow noreferrer">https://issues.apache.org/jira/browse/SPARK-16848]</a></li>
  <li>How to convert loaded Dataframe data types for each column.</li>
  </ol>