Repository navigation
[SPARK-60045][SQL] Avoid per-value regex compilation when parsing decimals in CSV/JSON/XML - #59273
Open
dwsmith1983 wants to merge 1 commit into
Open
dwsmith1983 wants to merge 1 commit into
dwsmith1983 wants to merge 1 commit into
Conversation
…imals in CSV/JSON/XML
Contributor
Author
|
cc @MaxGekk @HyukjinKwon, a one-line change: |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
ExprUtils.getDecimalParserstrips grouping commas withs.replaceAll(",", "")for the defaulten-USlocale. This PR usess.replace(",", "")instead. The pattern is a literal comma, so the result is the same, butreplacedoes not compile a regex.Why are the changes needed?
Performance.
String.replaceAllcompiles ajava.util.regex.Patternon every call, and this parser runs once per decimal value in the CSV reader (UnivocityParser), the JSON reader (decimals given as strings), the XML reader and JSON/XML schema inference.On a 2M row CSV file with 5
DECIMAL(18,2)columns (local[1], JDK 17, best of 3):new BigDecimal(s.replaceAll/replace(",", "")))The DECIMAL read is 1.95x faster. Decimal parsing used to add about 1 s over reading the columns as strings and now adds about 0.17 s.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Existing tests already parse grouped values such as
1,000.01and158,058,049.001through this code with theen-USlocale. They pass:UnivocityParserSuite,CSVInferSchemaSuite,JsonInferSchemaSuite,JsonExpressionsSuite,XmlExpressionsSuite, and the decimal tests inCSVv1Suite,JsonV1SuiteandXmlSuite.The numbers above come from a local benchmark run before and after the change on the same commit.
Was this patch authored or co-authored using generative AI tooling?
No