-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-3930] [SPARK-3933] Support fixed-precision decimal in SQL, and some optimizations #2983
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ec0a947
Make the result of AVG on Decimals be Decimal, not Double
mateiz 7af0c3b
Add optional precision and scale to DecimalType, but use Unlimited fo…
mateiz 81db9cb
Added mutable Decimal that will be more efficient for small precisions
mateiz 2118c0d
Some test and bug fixes
mateiz b28933d
Support decimal precision/scale in Hive metastore
mateiz d1d9d68
Fix compile error and test issues after rebase
mateiz 4dc6bae
Fix decimal support in PySpark
mateiz eb84820
Support reading/writing decimals as fixed-length binary in Parquet
mateiz 31f915e
Implement Davies's suggestions in Python
mateiz 227f24a
Review comments
mateiz 35e6b02
Fix issues after merge
mateiz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix decimal support in PySpark
- Loading branch information
commit 4dc6bae2304d82888d556607206a11f60dcb9ec7
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ | |
| import keyword | ||
| import warnings | ||
| import json | ||
| import re | ||
| from array import array | ||
| from operator import itemgetter | ||
| from itertools import imap | ||
|
|
@@ -148,13 +149,35 @@ class TimestampType(PrimitiveType): | |
| """ | ||
|
|
||
|
|
||
| class DecimalType(PrimitiveType): | ||
| class DecimalType(DataType): | ||
|
|
||
| """Spark SQL DecimalType | ||
|
|
||
| The data type representing decimal.Decimal values. | ||
| """ | ||
|
|
||
| def __init__(self, precision=None, scale=None): | ||
| if precision is None: | ||
| self.hasPrecisionInfo = False | ||
| self.precision = None | ||
| self.scale = None | ||
| else: | ||
| self.hasPrecisionInfo = True | ||
| self.precision = precision | ||
| self.scale = scale | ||
|
|
||
| def jsonValue(self): | ||
| if self.hasPrecisionInfo: | ||
| return "decimal(%d,%d)" % (self.precision, self.scale) | ||
| else: | ||
| return "decimal" | ||
|
|
||
| def __repr__(self): | ||
| if self.hasPrecisionInfo: | ||
| return "DecimalType(%d,%d)" % (self.precision, self.scale) | ||
| else: | ||
| return "DecimalType()" | ||
|
|
||
|
|
||
| class DoubleType(PrimitiveType): | ||
|
|
||
|
|
@@ -446,9 +469,17 @@ def _parse_datatype_json_string(json_string): | |
| return _parse_datatype_json_value(json.loads(json_string)) | ||
|
|
||
|
|
||
| _FIXED_DECIMAL = re.compile("decimal\\((\\d+),(\\d+)\\)") | ||
|
|
||
|
|
||
| def _parse_datatype_json_value(json_value): | ||
| if type(json_value) is unicode and json_value in _all_primitive_types.keys(): | ||
| return _all_primitive_types[json_value]() | ||
| elif type(json_value) is unicode and json_value == u'decimal': | ||
| return DecimalType() | ||
| elif type(json_value) is unicode and _FIXED_DECIMAL.match(json_value): | ||
| m = _FIXED_DECIMAL.match(json_value) | ||
| return DecimalType(int(m.group(1)), int(m.group(2))) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you change these into two levels and raise exception if json_value is unicode but can not recognize the value? |
||
| else: | ||
| return _all_complex_types[json_value["type"]].fromJson(json_value) | ||
|
|
||
|
|
||
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
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.
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.
nit: these lines could be simplified as:
Maybe we could remove
hasPrecisionInfo