Skip to content
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

refactor numeric code and handle typmod better #2091

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

heavycrystal
Copy link
Contributor

started with numeric refactor, but discovered typmod is being handled improperly in some places
bumped BQ to BIGNUMERIC limits
added tests for typmod parsing

// This is to reverse what make_numeric_typmod of Postgres does:
// logic copied from: https://github.com/postgres/postgres/blob/c4d5cb71d229095a39fda1121a75ee40e6069a2a/src/backend/utils/adt/numeric.c#L929
// Maps most "invalid" typmods to be unconstrained (same as -1)
func NewParsedNumericTypmod(typmod int32) *NumericTypmod {
Copy link
Contributor

@serprex serprex Sep 22, 2024

Choose a reason for hiding this comment

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

Suggested change
func NewParsedNumericTypmod(typmod int32) *NumericTypmod {
func NewParsedNumericTypmod(typmod int32) NumericTypmod {

Seems like a type best passed by value & treated as immutable. Can even fit a Valid bool without impacting struct size, but seems that's what constrained might be

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not a big fan of passing by value since we need to store this in QField which currently has no way to communicate something is only needed for numerics

basically an implicit vs explicit thing

Copy link
Contributor

Choose a reason for hiding this comment

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

That'd be handled by a Valid bool

precision := int16((offsetMod >> 16) & 0x7FFF)
scale := int16(offsetMod & 0x7FFF)
return precision, scale
func (t *NumericTypmod) PrecisionAndScale() (int16, int16) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can make Precision/Scale public & remove this. No need for nil checks if you usually work with these by value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants