-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
sql,pgwire: fixes for float formatting #82022
Conversation
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.
Nice - but I'll let oliver sign off.
Reviewed 6 of 6 files at r1, 3 of 3 files at r2, 2 of 2 files at r3, all commit messages.
Reviewable status:complete! 0 of 0 LGTMs obtained (waiting on @otan)
|
||
|
||
send | ||
Query {"String": "SET extra_float_digits = -1"} |
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.
can you add a test for a positive extra_float_digits > 1?
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.
adding
ReadyForQuery | ||
---- | ||
{"Type":"RowDescription","Fields":[{"Name":"float4","TableOID":0,"TableAttributeNumber":0,"DataTypeOID":700,"DataTypeSize":4,"TypeModifier":-1,"Format":0},{"Name":"float8","TableOID":0,"TableAttributeNumber":0,"DataTypeOID":701,"DataTypeSize":8,"TypeModifier":-1,"Format":0}]} | ||
{"Type":"DataRow","Values":[{"text":"0.33333334"},{"text":"0.3333333333333333"}]} |
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.
ooh we round up to 4? is this consistent when running this with PG?
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.
yep, the expected result was obtained by running against PG
@@ -162,6 +170,27 @@ func init() { | |||
} | |||
} | |||
|
|||
// PgwireFormatFloat returns a []byte representing a float according to | |||
// pgwire encoding. The result is appended to the given buffer. | |||
func PgwireFormatFloat( |
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.
wonder if this should be PGWire, but that's an optional nit
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.
i was matching the naming of PgwireFormatBool
34af9ad
to
9786005
Compare
bors r=otan |
Build failed: |
Release note (sql change): The extra_float_digits session variable now defaults to 1. The meaning of the variable has also changed. Now, any value greater than zero causes floats to be formatted in their shortest precise decimal representation. That is, the string representation produced is closer to the actual binary value than to any other value. (Previously, this was only the behavior when extra_float_digits was set to 3.) This change was made in accordance with an equivalent change that was part of the PostgreSQL 12.0 release. The behavior of a non-positive extra_float_digits value is unchanged. That will still reduce the number of float digits shown in the output string. The formula for number of digits shown is `max(1, (DIGITS + extra_float_digits))`, where DIGITS=6 for FLOAT4 values, and DIGITS=15 for FLOAT8 values.
Release note (bug fix): Fixed the formatting of floats in arrays and tuples sent over the client-server pgwire protocol so that they respect the extra_float_digits parameter, and correctly format infinity values.
There's no behavior change, but this reduces code duplication. This also adds a test that demonstrates a gap in our type/cast system. Release note: None
The encoding tests were updated so they use the new default value of 1 for extra_float_digits. This makes the test more aligned to Postgres behavior. Release note: None
bors r=otan |
82022: sql,pgwire: fixes for float formatting r=otan a=rafiss ### sql/pgwire: update float formatting to be compatible with PG12 Release note (sql change): The extra_float_digits session variable now defaults to 1. The meaning of the variable has also changed. Now, any value greater than zero causes floats to be formatted in their shortest precise decimal representation. That is, the string representation produced is closer to the actual binary value than to any other value. (Previously, this was only the behavior when extra_float_digits was set to 3.) This change was made in accordance with an equivalent change that was part of the PostgreSQL 12.0 release. The behavior of a non-positive extra_float_digits value is unchanged. That will still reduce the number of float digits shown in the output string. The formula for number of digits shown is `max(1, (DIGITS + extra_float_digits))`, where DIGITS=6 for FLOAT4 values, and DIGITS=15 for FLOAT8 values. ### sql/pgwire: fix formatting of float arrays Release note (bug fix): Fixed the formatting of floats in arrays sent over the client-server pgwire protocol so that they respect the extra_float_digits parameter, and correctly format infinity values. ### eval: use common function for float->text cast There's no behavior change, but this reduces code duplication. This also adds a test that demonstrates a gap in our type/cast system. Co-authored-by: Rafi Shamim <rafi@cockroachlabs.com>
Build failed: |
bors=otan |
bors r=otan |
1 similar comment
bors r=otan |
Build succeeded: |
This commit removes a TODO that was partially addressed by cockroachdb#82022. Informs cockroachdb#73747 Release note: None
This commit removes a TODO that was partially addressed by cockroachdb#82022. Informs cockroachdb#73743 Release note: None
105736: opt: wrap virtual computed column projections in a cast r=mgartner a=mgartner #### sql/logictest: remove assignment cast TODO This commit removes a TODO that was partially addressed by #82022. Informs #73743 Release note: None #### sql/types: fix T.Identical This commit fixes a bug in `types.T.Identical` which caused it to return false for collated string types with a different string-representation of locales that represents the same locale logically. For example, collated string types with locales `en_US` and `en_us` would not be identical, even though these are both valid representations of the same locale. There is no release note because this has not caused any known bugs. Release note: None #### opt: wrap virtual computed column projections in a cast optbuilder wraps an assignment cast around a virtual computed column expression when writing to the table if the expression does not have the same type as the virtual column. This matches the behavior of all writes to columns of expressions that don't match the target column type. However, the same cast was not applied to the projection of the virtual column expression when reading from the table. This cast is necessary in order to produce the correct value of the column - the projection must produce the same value that would have been written to the table if the column was a stored computed column. This commit corrects optbuilder so that the cast is correctly added to the projection. Note that this commit adds a standard cast, not an assignment cast, as a temporary workaround until #81698 is addressed. This is because an assignment cast can fail in cases when a regular cast will not. Because we don't validate that all existing rows can successfully produce a new virtual column expression during a backfill, adding an assignment cast to the projection of the virtual column could cause future reads to error. Once #81698 is addressed, we can change these casts to assignment casts so that they directly match the values that would be written to the same column if it were stored. Fixes #91817 Informs #81698 Release note (bug fix): A bug has been fixed that could produce incorrect values for virtual computed columns in rare cases. The bug only presented when the virtual column expression's type did not match the type of the virtual column. 105932: opt/exec: add passthrough cols to DELETE USING result cols in explain r=yuzefovich,DrewKimball a=michae2 Now that we support `DELETE USING`, delete nodes can have passthrough columns. Add these to the result columns used by `EXPLAIN (TYPES)`. Fixes: #105803 Release note (sql change): Fix an internal error when using `EXPLAIN (TYPES)` on a `DELETE FROM ... USING ... RETURNING` statement. Co-authored-by: Marcus Gartner <marcus@cockroachlabs.com> Co-authored-by: Michael Erickson <michae2@cockroachlabs.com>
This commit removes a TODO that was partially addressed by cockroachdb#82022. Informs cockroachdb#73743 Release note: None
sql/pgwire: update float formatting to be compatible with PG12
Release note (sql change): The extra_float_digits session variable now
defaults to 1. The meaning of the variable has also changed. Now, any
value greater than zero causes floats to be formatted in their
shortest precise decimal representation. That is, the string representation
produced is closer to the actual binary value than to any other value.
(Previously, this was only the behavior when extra_float_digits was set
to 3.) This change was made in accordance with an equivalent change that
was part of the PostgreSQL 12.0 release.
The behavior of a non-positive extra_float_digits value is unchanged. That
will still reduce the number of float digits shown in the output string.
The formula for number of digits shown is
max(1, (DIGITS + extra_float_digits))
,where DIGITS=6 for FLOAT4 values, and DIGITS=15 for FLOAT8 values.
sql/pgwire: fix formatting of float arrays
Release note (bug fix): Fixed the formatting of floats in arrays sent
over the client-server pgwire protocol so that they respect the
extra_float_digits parameter, and correctly format infinity values.
eval: use common function for float->text cast
There's no behavior change, but this reduces code duplication.
This also adds a test that demonstrates a gap in our type/cast system.