Skip to content
Closed
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
Make the condition better
  • Loading branch information
HyukjinKwon committed Nov 5, 2016
commit c0667d1e31e6eed04bb0be1be0eef0f86fba1bb7
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ private[csv] object CSVTypeCast {
castType: DataType,
nullable: Boolean = true,
options: CSVOptions = CSVOptions()): Any = {

if (datum == null || nullable && datum == options.nullValue) {
val isNull = datum == options.nullValue || datum == null
if (nullable && isNull) {
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't this more clear if you do

// datum can be null if the number of fields found is less than the length of the schema
if (datum == options.nullValue || datum == null) {
  if (!nullable) {
    throw some exception saying field is not null but null value found
  }
  null
} else {
  ..
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd also add a null validation test.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, I will.

null
} else {
castType match {
Expand Down