GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||
GeezerVison is showing github.com — Fix DECIMAL parameter cast size for exponent-notation and negative values by winklemad · Pull Request #952 · databricks/databricks-sql-python ConversationDescription
Exponent notation — cursor.execute("SELECT ?", [Decimal("1500").normalize()]) # infers DECIMAL(5,4) -- the "E+3" is counted as 4 fractional digits # but 1500 needs DECIMAL(4,0); DECIMAL(5,4) max is ±9.9999 -> overflow # -> error in ANSI mode, or silently NULL in legacy mode Negative values — the leading Decimal("-" + "9" * 38) # a valid DECIMAL(38,0) # infers DECIMAL(39,0), which exceeds Databricks' maximum DECIMAL precision of 38 # -> invalid cast, query fails Both the cast type and the bound literal come from the same value, so the server can't reconcile them — a perfectly valid FixDerive precision/scale from TestsThe six existing
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions…lues
DecimalParameter.calculate_decimal_cast_string inferred DECIMAL(precision,
scale) by string-splitting str(value) on ".", which miscounts two forms
that str(Decimal) legitimately produces:
- exponent notation (Decimal("1500").normalize() -> "1.5E+3"): the "E+3"
was counted as fractional digits, giving DECIMAL(5,4) for 1500, which
overflows (an error in ANSI mode, NULL in legacy mode).
- a leading minus sign: counted as an extra integer digit, so a negative
38-digit value produced DECIMAL(39,0), exceeding Databricks' max DECIMAL
precision of 38 and failing the cast.
Derive precision/scale from Decimal.as_tuple() (digits + exponent), ignoring
sign and display format. Existing cast-string tests are unchanged; added
regression cases for exponent notation and negative values.
Signed-off-by: Madan Kumar <[email protected]>
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Collaborator
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. Decimal("0E+38") has a single digit and exponent 38, which the integer
branch turned into DECIMAL(39,0). A zero only needs DECIMAL(1,0).
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
jay-xiao446
approved these changes
Collaborator
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. lgtm
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
3 of 4 tasks
This branch has not been deployedNo deployments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
None yet
ProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. Uh oh!
There was an error while loading. Please reload this page. 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. | ||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |