Skip to content

Support default precision and scale toCAST <EXPR> AS DECIMAL - #2680

Merged
alamb merged 4 commits into
apache:masterfrom
cube-js:default_precision_and_scale_for_decimal
Jun 14, 2022
Merged

Support default precision and scale toCAST <EXPR> AS DECIMAL#2680
alamb merged 4 commits into
apache:masterfrom
cube-js:default_precision_and_scale_for_decimal

Conversation

@gandronchik

@gandronchikgandronchik commented Jun 2, 2022

Copy link
Copy Markdown
Contributor

Hello! I am an employee of Cube.js. We use cast to0 decimal with default params. Thank you!

Which issue does this PR close?

Not exists

Rationale for this change

Postgres allow to cast to decimal in the following ways:

  • CAST(10 as Decimal(38, 10))
  • CAST(10 as Decimal(38))
  • CAST(10 as Decimal)

What changes are included in this PR?

  • Cast to decimal with default params

Are there any user-facing changes?

Ability to cast to decimal with default params

Comment threaddatafusion/sql/src/utils.rs Outdated
@gandronchik
gandronchik marked this pull request as draft June 2, 2022 17:37
@gandronchik
gandronchik marked this pull request as ready for review June 6, 2022 10:29
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

Merging #2680 (12b3faf) into master (49e072a) will increase coverage by 0.03%.
The diff coverage is 83.33%.

@@ Coverage Diff @@## master #2680 +/- ##
==========================================
+ Coverage 84.63% 84.66% +0.03% 
==========================================
Files 267 270 +3 Lines 46867 46921 +54 ==========================================
+ Hits 39665 39726 +61 + Misses 7202 7195 -7 
Impacted FilesCoverage Δ
datafusion/sql/src/utils.rs51.17% <71.42%> (+0.19%)⬆️
datafusion/sql/src/planner.rs81.53% <100.00%> (+0.05%)⬆️
datafusion/core/src/logical_plan/plan.rs84.61% <0.00%> (-9.19%)⬇️
datafusion/core/src/test/mod.rs83.48% <0.00%> (-4.55%)⬇️
datafusion/core/src/physical_plan/planner.rs77.51% <0.00%> (-1.82%)⬇️
...afusion/core/src/datasource/file_format/parquet.rs87.32% <0.00%> (-1.24%)⬇️
...physical-expr/src/expressions/get_indexed_field.rs93.95% <0.00%> (-0.94%)⬇️
datafusion/core/src/execution/memory_manager.rs70.25% <0.00%> (-0.63%)⬇️
datafusion/core/src/catalog/schema.rs85.00% <0.00%> (-0.49%)⬇️
datafusion/common/src/scalar.rs74.82% <0.00%> (-0.36%)⬇️
... and 76 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 49e072a...12b3faf. Read the comment docs.

Comment threaddatafusion/sql/src/utils.rs Outdated
@alamb

alamb commented Jun 6, 2022

Copy link
Copy Markdown
Contributor

@gandronchik can you please provide a description of this PR (namely what problem it is solving)? It is likely obvious to you but it isn't immediately obvious to me and it is much faster to review a PR (and get it merged) if we don't have to spend time researching the "why this change" and instead can focus on "is the change in behavior desired" and "does the code implemented the desired change in behavior"

🙏 thank you

@tustvold
tustvold marked this pull request as draft June 8, 2022 16:32
@gandronchik

Copy link
Copy Markdown
ContributorAuthor

@gandronchik can you please provide a description of this PR (namely what problem it is solving)? It is likely obvious to you but it isn't immediately obvious to me and it is much faster to review a PR (and get it merged) if we don't have to spend time researching the "why this change" and instead can focus on "is the change in behavior desired" and "does the code implemented the desired change in behavior"

🙏 thank you

Sure, I will do it next time. I'm sorry for the inconvenience 🙏

@gandronchik
gandronchik marked this pull request as ready for review June 10, 2022 08:30
Comment threaddatafusion/sql/src/planner.rs

@alambalamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @gandronchik -- the description makes it much easier to understand what this PR was attempting to do.

@alambalamb changed the title chore: default precision and scale for cast decimalAdd default precision and scale toCAST <EXPR> AS DECIMALJun 10, 2022
@gandronchik
gandronchikforce-pushed the default_precision_and_scale_for_decimal branch from 7552bd9 to 2fc34f0CompareJune 14, 2022 09:52
@gandronchik
gandronchik requested a review from alambJune 14, 2022 09:53

@alambalamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great -- thanks @gandronchik

@alamb
alamb merged commit 613b43a into apache:masterJun 14, 2022
@alambalamb changed the title Add default precision and scale toCAST <EXPR> AS DECIMALSupport default precision and scale toCAST <EXPR> AS DECIMALJun 14, 2022
waynexia pushed a commit to waynexia/arrow-datafusion that referenced this pull request Jun 20, 2022
* chore: default precision and scale for cast decimal
improve
ok
* fix decimal type max precision size (#48)
* minor
* add tests
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sqlSQL Planner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@gandronchik@codecov-commenter@alamb@tustvold@liukun4515@andygrove