cloud-fan commented on a change in pull request #26973: [SPARK-30323][SQL] Support filters pushdown in CSV datasource URL: https://github.com/apache/spark/pull/26973#discussion_r365699520
########## File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/csv/UnivocityParser.scala ########## @@ -242,24 +272,48 @@ class UnivocityParser( new RuntimeException("Malformed CSV record")) } else { // When the length of the returned tokens is identical to the length of the parsed schema, - // we just need to convert the tokens that correspond to the required columns. - var badRecordException: Option[Throwable] = None + // we just need to: + // 1. Convert the tokens that correspond to the parsed schema. + // 2. Apply the pushdown filters to `parsedRow`. + // 3. Convert `parsedRow` to `requiredRow` by stripping non-required fields. var i = 0 + val requiredSingleRow = requiredRow.head while (i < requiredSchema.length) { + requiredSingleRow.setNullAt(i) + i += 1 + } + + var skipValueConversion = false + var badRecordException: Option[Throwable] = None + i = 0 + while (!skipValueConversion && i < parsedSchema.length) { try { - row(i) = valueConverters(i).apply(getToken(tokens, i)) + val convertedValue = valueConverters(i).apply(getToken(tokens, i)) + parsedRow(i) = convertedValue + if (csvFilters.skipRow(parsedRow, i)) { + skipValueConversion = true + } else { + val requiredIndex = parsedToRequiredIndex(i) + if (requiredIndex != -1) { + requiredSingleRow(requiredIndex) = convertedValue + } + } } catch { case NonFatal(e) => - badRecordException = badRecordException.orElse(Some(e)) - row.setNullAt(i) + badRecordException = Some(e) + skipValueConversion = true } i += 1 } - - if (badRecordException.isEmpty) { - row + if (skipValueConversion) { + if (badRecordException.isDefined) { Review comment: how can we hit exception if `skipValueConversion` becomes true? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to 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