title: Spark loading ORC files does not use exact schema from Hive Metastore causing type casting errors
body: <p>I am trying to load some data from a Hive table where one of the columns is like this:</p>
  <pre><code>id - bigint
  </code></pre>
  <p>When I load the table into a dataframe and do a printSchema, I see that Spark agrees with the Hive Metastore that id is of type long.  However, when I try to do anything with the table, I get this error:</p>
  <pre><code>SparkException: Job aborted due to stage failure: Task 0 in stage 14.0 failed 4 times, most recent failure: Lost task 0.3 in stage 14.0 (TID 218, 10.139.64.41, executor 1): java.lang.ClassCastException: org.apache.hadoop.io.IntWritable cannot be cast to org.apache.hadoop.io.LongWritable
  at org.apache.spark.sql.execution.datasources.orc.OrcDeserializer$$anonfun$org$apache$spark$sql$execution$datasources$orc$OrcDeserializer$$newWriter$6.apply(OrcDeserializer.scala:94)
  at org.apache.spark.sql.execution.datasources.orc.OrcDeserializer$$anonfun$org$apache$spark$sql$execution$datasources$orc$OrcDeserializer$$newWriter$6.apply(OrcDeserializer.scala:93)
  at org.apache.spark.sql.execution.datasources.orc.OrcDeserializer$$anonfun$2$$anonfun$apply$1.apply(OrcDeserializer.scala:51)
  at org.apache.spark.sql.execution.datasources.orc.OrcDeserializer$$anonfun$2$$anonfun$apply$1.apply(OrcDeserializer.scala:51)
  at org.apache.spark.sql.execution.datasources.orc.OrcDeserializer.deserialize(OrcDeserializer.scala:64)
  at org.apache.spark.sql.execution.datasources.orc.OrcFileFormat$$anonfun$buildReaderWithPartitionValues$2$$anonfun$apply$8.apply(OrcFileFormat.scala:234)
  at org.apache.spark.sql.execution.datasources.orc.OrcFileFormat$$anonfun$buildReaderWithPartitionValues$2$$anonfun$apply$8.apply(OrcFileFormat.scala:233)
  at scala.collection.Iterator$$anon$11.next(Iterator.scala:410)
  at org.apache.spark.sql.execution.datasources.FileScanRDD$$anon$1$$anon$2.getNext(FileScanRDD.scala:283)
  at org.apache.spark.util.NextIterator.hasNext(NextIterator.scala:73)
  at org.apache.spark.sql.execution.datasources.FileScanRDD$$anon$1.nextIterator(FileScanRDD.scala:401)
  at org.apache.spark.sql.execution.datasources.FileScanRDD$$anon$1.hasNext(FileScanRDD.scala:249)
  at org.apache.spark.sql.catalyst.expressions.GeneratedClass$GeneratedIteratorForCodegenStage1.processNext(Unknown Source)
  at org.apache.spark.sql.execution.BufferedRowIterator.hasNext(BufferedRowIterator.java:43)
  at org.apache.spark.sql.execution.WholeStageCodegenExec$$anonfun$13$$anon$1.hasNext(WholeStageCodegenExec.scala:640)
  at org.apache.spark.sql.execution.collect.UnsafeRowBatchUtils$.encodeUnsafeRows(UnsafeRowBatchUtils.scala:62)
  at org.apache.spark.sql.execution.collect.Collector$$anonfun$2.apply(Collector.scala:159)
  at org.apache.spark.sql.execution.collect.Collector$$anonfun$2.apply(Collector.scala:158)
  at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:90)
  at org.apache.spark.scheduler.Task.doRunTask(Task.scala:140)
  at org.apache.spark.scheduler.Task.run(Task.scala:113)
  at org.apache.spark.executor.Executor$TaskRunner$$anonfun$13.apply(Executor.scala:528)
  at org.apache.spark.util.Utils$.tryWithSafeFinally(Utils.scala:1526)
  at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:534)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  at java.lang.Thread.run(Thread.java:748)
  </code></pre>
  <p>It seems that Spark reads the data, decides that an Integer is enough to hold the data, and then tries to reconcile with the Hive Metastore who expects a Long.  How do I go about solving this?</p>
  <p>EDIT:</p>
  <p>I have tried reading the data in two ways, although I suspect they are the same:</p>
  <pre><code>spark.sql(&quot;select * from databaseName.tableName&quot;)
  spark.table(&quot;databaseName.tableName&quot;)
  </code></pre>