Github user rdblue commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22009#discussion_r208637663
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceRDD.scala
 ---
    @@ -51,18 +58,19 @@ class DataSourceRDD[T: ClassTag](
             valuePrepared
           }
     
    -      override def next(): T = {
    +      override def next(): Any = {
             if (!hasNext) {
               throw new java.util.NoSuchElementException("End of stream")
             }
             valuePrepared = false
             reader.get()
           }
         }
    -    new InterruptibleIterator(context, iter)
    +    // TODO: get rid of this type hack.
    +    new InterruptibleIterator(context, 
iter.asInstanceOf[Iterator[InternalRow]])
       }
     
       override def getPreferredLocations(split: Partition): Seq[String] = {
    -    
split.asInstanceOf[DataSourceRDDPartition[T]].inputPartition.preferredLocations()
    +    
split.asInstanceOf[DataSourceRDDPartition].inputPartition.preferredLocations()
    --- End diff --
    
    Makes sense. If it's a bug, then the error message should indicate that 
it's a bug to users instead of throwing a `ClassCastException`. Even if someone 
goes to the code here, it there's no comment to indicate that it's a Spark bug.
    
    I'd prefer something like this:
    ```scala
    override def getPreferredLocations(split: Partition): Seq[String] = {
      split match {
        case dsp: DataSourceRDDPartition => 
dsp.inputPartition.preferredLocations
        case _ => throw new SparkException(s"[BUG] Not a 
DataSourceRDDPartition: $split")
      }
    }
    ```


---

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

Reply via email to