diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetRowConverter.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetRowConverter.scala index 9ffc2b5dd8a56..f53a226df999b 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetRowConverter.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetRowConverter.scala @@ -214,9 +214,22 @@ private[parquet] class ParquetRowConverter( updater: ParentContainerUpdater): Converter with HasParentContainerUpdater = { catalystType match { - case BooleanType | IntegerType | LongType | FloatType | DoubleType | BinaryType => + case BooleanType | IntegerType | FloatType | DoubleType | BinaryType => new ParquetPrimitiveConverter(updater) + /** + * [SPARK-17477] When reading a hive table of parquet files with schema evolution + * from Int to Long and if hive metastore has Long as its type while parquet files + * have Int, SparkSQL need to figure out the actual type in the parquet files. + * Otherwise, it will result in java.lang.ClassCastException: [[MutableLong]] cannot + * be cast to [[MutableInt]]. + */ + case LongType => + new ParquetPrimitiveConverter(updater) { + override def addInt(value: Int): Unit = + updater.setLong(value.asInstanceOf[Long]) + } + case ByteType => new ParquetPrimitiveConverter(updater) { override def addInt(value: Int): Unit =