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

    https://github.com/apache/spark/pull/12708#discussion_r61793288
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/Row.scala ---
    @@ -335,6 +358,19 @@ trait Row extends Serializable {
       def getAs[T](fieldName: String): T = getAs[T](fieldIndex(fieldName))
     
       /**
    +   * Returns the value of a given fieldName as a scala.util.Try object.
    +   */
    +  def attempt[T](fieldName: String): Try[T] = 
Try(getAs[T](fieldIndex(fieldName)))
    --- End diff --
    
    I am not sure what you mean by an _external_ row. But I don't understand 
why it's not possible that when a file is being read, a few bad rows might 
creep in. My understanding is data interpretation is done lazily in Spark. So I 
can totally do this.
    ```
    scala> :paste
    // Entering paste mode (ctrl-D to finish)
    
    import org.apache.spark.sql.types._
    import org.apache.spark.sql._
    import org.apache.spark.sql.catalyst.expressions.{GenericRow, 
GenericRowWithSchema}
    
    val schema = StructType(
      StructField("col1", StringType) ::
      StructField("col2", DoubleType) ::
      StructField("col3", IntegerType) ::
      Nil)
    val values = Array(1.0, "value2", 1)
    val sampleRow: Row = new GenericRowWithSchema(values, schema)
    
    // Exiting paste mode, now interpreting.
    
    import org.apache.spark.sql.types._
    import org.apache.spark.sql._
    import org.apache.spark.sql.catalyst.expressions.{GenericRow, 
GenericRowWithSchema}
    schema: org.apache.spark.sql.types.StructType = 
StructType(StructField(col1,StringType,true), 
StructField(col2,DoubleType,true), StructField(col3,IntegerType,true))
    values: Array[Any] = Array(1.0, value2, 1)
    sampleRow: org.apache.spark.sql.Row = [1.0,value2,1]
    
    scala> sampleRow.getAs[String](0)
    java.lang.ClassCastException: java.lang.Double cannot be cast to 
java.lang.String
    ...
    ```
    And when the value accessed it will fail with due to a wrong cast.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to