-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-21263][SQL] Do not allow partially parsing double and floats via NumberFormat in CSV #18532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| case options.nanValue => Float.NaN | ||
| case options.negativeInf => Float.NegativeInfinity | ||
| case options.positiveInf => Float.PositiveInfinity | ||
| case datum => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, it looks we are not using NumberFormat.parse in schema inference -
spark/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVInferSchema.scala
Line 141 in 7e5359b
| if ((allCatch opt field.toDouble).isDefined || isInfOrNan(field, options)) { |
| } | ||
| } | ||
|
|
||
| test("Do not partially lose data when parsing float and double") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest a better description for this test and please include the JIRA number. E.g.,
SPARK-21263: Invalid float and double are handled correctly in different modes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, thanks.
|
Test build #79168 has finished for PR 18532 at commit
|
|
Test build #79167 has finished for PR 18532 at commit
|
|
Test build #79169 has finished for PR 18532 at commit
|
falaki
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor suggestions. Otherwise LGTM
| var message = intercept[NumberFormatException] { | ||
| parser.makeConverter("_1", FloatType, options = options).apply("10u000") | ||
| }.getMessage | ||
| assert(message.contains("10u000")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there some more specific error we could check for?
| message = intercept[NumberFormatException] { | ||
| parser.makeConverter("_1", DoubleType, options = options).apply("10u000") | ||
| }.getMessage | ||
| assert(message.contains("10u000")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dito
| .csv(Seq("10u12").toDS()) | ||
| .collect() | ||
| } | ||
| assert(exception.getMessage.contains("10u12")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we check for more specific error message?
|
Thank you @falaki. I just updated. |
|
Test build #79256 has finished for PR 18532 at commit
|
|
Merged to master |
What changes were proposed in this pull request?
This PR proposes to remove
NumberFormat.parseuse to disallow a case of partially parsed data. For example,How was this patch tested?
Unit tests added in
UnivocityParserSuiteandCSVSuite.