Deegue commented on a change in pull request #23559: [SPARK-26630][SQL] Fix 
ClassCastException in TableReader while creating HadoopRDD
URL: https://github.com/apache/spark/pull/23559#discussion_r248571444
 
 

 ##########
 File path: sql/hive/src/main/scala/org/apache/spark/sql/hive/TableReader.scala
 ##########
 @@ -288,29 +285,119 @@ class HadoopTableReader(
     }
   }
 
+  /**
+   * The entry of creating a RDD.
+   */
+  private def getRDD(
+    inputClassName: String,
+    localTableDesc: TableDesc,
+    inputPathStr: String): RDD[Writable] = {
+    if (isCreateNewHadoopRDD(inputClassName)) {
+      createNewHadoopRdd(
+        localTableDesc,
+        inputPathStr,
+        inputClassName)
+    } else {
+      createHadoopRdd(
+        localTableDesc,
+        inputPathStr,
+        inputClassName)
+    }
+  }
+
   /**
    * Creates a HadoopRDD based on the broadcasted HiveConf and other job 
properties that will be
    * applied locally on each slave.
    */
   private def createHadoopRdd(
     tableDesc: TableDesc,
     path: String,
-    inputFormatClass: Class[InputFormat[Writable, Writable]]): RDD[Writable] = 
{
+    inputClassName: String): RDD[Writable] = {
 
     val initializeJobConfFunc = 
HadoopTableReader.initializeLocalJobConfFunc(path, tableDesc) _
 
     val rdd = new HadoopRDD(
       sparkSession.sparkContext,
       
_broadcastedHadoopConf.asInstanceOf[Broadcast[SerializableConfiguration]],
       Some(initializeJobConfFunc),
-      inputFormatClass,
+      getInputFormat(inputClassName),
       classOf[Writable],
       classOf[Writable],
       _minSplitsPerRDD)
 
     // Only take the value (skip the key) because Hive works only with values.
     rdd.map(_._2)
   }
+
+  /**
+   * Creates a HadoopRDD based on the broadcasted HiveConf and other job 
properties that will be
+   * applied locally on each slave.
+   */
+  private def createNewHadoopRdd(
+    tableDesc: TableDesc,
+    path: String,
+    inputClassName: String): RDD[Writable] = {
+
+    val initializeJobConfFunc = 
HadoopTableReader.initializeLocalJobConfFunc(path, tableDesc) _
+
+    val newJobConf = new JobConf(hadoopConf)
+    initializeJobConfFunc.apply(newJobConf)
+    val rdd = new NewHadoopRDD(
+      sparkSession.sparkContext,
+      getNewInputFormat(inputClassName),
+      classOf[Writable],
+      classOf[Writable],
+      newJobConf
+    )
+
+    // Only take the value (skip the key) because Hive works only with values.
+    rdd.map(_._2)
+  }
+
+  /**
+   * If `spark.sql.hive.fileInputFormat.enabled` is true, this function will 
optimize the input
+   * method while reading Hive tables.
+   * For old input format `org.apache.hadoop.mapred.InputFormat`.
+   */
+  private def getInputFormat(
+    inputClassName: String): 
Class[org.apache.hadoop.mapred.InputFormat[Writable, Writable]] = {
+
+    var ifc = Utils.classForName(inputClassName)
+      
.asInstanceOf[java.lang.Class[org.apache.hadoop.mapred.InputFormat[Writable, 
Writable]]]
+    if (conf.getConf(HiveUtils.HIVE_INPUT_FORMAT_OPTIMIZER_ENABLED) &&
+      "org.apache.hadoop.mapred.TextInputFormat".equals(inputClassName)) {
+        ifc = 
Utils.classForName("org.apache.hadoop.mapred.lib.CombineTextInputFormat")
 
 Review comment:
   You're right, I've removed this.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to