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

    https://github.com/apache/spark/pull/16928#discussion_r101894442
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/UnivocityParser.scala
 ---
    @@ -173,25 +185,41 @@ private[csv] class UnivocityParser(
        */
       def parse(input: String): Option[InternalRow] = {
         convertWithParseMode(parser.parseLine(input)) { tokens =>
    -      var i: Int = 0
    -      while (i < indexArr.length) {
    -        val pos = indexArr(i)
    -        // It anyway needs to try to parse since it decides if this row is 
malformed
    -        // or not after trying to cast in `DROPMALFORMED` mode even if the 
casted
    -        // value is not stored in the row.
    -        val value = valueConverters(pos).apply(tokens(pos))
    -        if (i < requiredSchema.length) {
    -          row(i) = value
    +      var foundMalformed: Boolean = false
    +      indexArr.foreach { case (pos, i) =>
    +        try {
    +          // It anyway needs to try to parse since it decides if this row 
is malformed
    +          // or not after trying to cast in `DROPMALFORMED` mode even if 
the casted
    +          // value is not stored in the row.
    +          val value = valueConverters(pos).apply(tokens(pos))
    +          if (i < requiredSchema.length) {
    +            row(i) = value
    +          }
    +        } catch {
    +          case _: NumberFormatException | _: IllegalArgumentException
    --- End diff --
    
    Could we maybe decouple this parsing handling logics into 
`convertWithParseMode`?


---
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