Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
address comments
  • Loading branch information
cloud-fan committed Mar 20, 2017
commit 20ac52f249477d17b0b07ff81bddeef444d5b546
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import org.apache.spark.sql.types.StructType
import org.apache.spark.unsafe.types.UTF8String

class FailureSafeParser[IN](
func: IN => Seq[InternalRow],
rawParser: IN => Seq[InternalRow],
mode: String,
schema: StructType,
columnNameOfCorruptRecord: String) {
Expand All @@ -50,13 +50,13 @@ class FailureSafeParser[IN](
resultRow
}
} else {
(row, badRecord) => row.getOrElse(nullResult)
(row, _) => row.getOrElse(nullResult)
}
}

def parse(input: IN): Iterator[InternalRow] = {
try {
func(input).toIterator.map(row => toResultRow(Some(row), () => null))
rawParser.apply(input).toIterator.map(row => toResultRow(Some(row), () => null))
} catch {
case e: BadRecordException if ParseModes.isPermissiveMode(mode) =>
Iterator(toResultRow(e.partialResult(), e.record))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,11 @@ class UnivocityParser(
new RuntimeException("Malformed CSV record"))
Copy link
Member

@HyukjinKwon HyukjinKwon Mar 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. So, BadRecordException contains the information about which record is malformed so that users can access to and check this. Did I understand correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

} else {
try {
for (i <- requiredSchema.indices) {
var i = 0
while (i < requiredSchema.length) {
val from = tokenIndexArr(i)
row(i) = valueConverters(from).apply(tokens(from))
i += 1
}
row
} catch {
Expand Down