-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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: 0 is formatted incorrectly for DECIMALs with scale >= 7 #102217
Comments
Root cause is here: Since we have a 0 coefficient this gets triggered. Consider the go program, which replicates the logic: package main
import (
"fmt"
"github.com/cockroachdb/apd/v3"
)
func main() {
for _, str := range []string{"0.000000", "0.0000000", "1.000000000"} {
d, _, err := apd.NewFromString(str)
if err != nil {
panic(err)
}
fmt.Printf("##### %s\n", str)
digits := d.Coeff.Append([]byte{}, 10)
fmt.Printf("decimal info: form: %v, neg: %v, exp: %d, co: %v\n", d.Form, d.Negative, d.Exponent, d.Coeff)
fmt.Printf("digits = %s: %d\n", digits, len(digits))
adj := int(d.Exponent) + (len(digits) - 1)
const adjExponentLimit = -6
fmt.Printf("adj: %d, d.Exponent <= 0 && adj >= adjExponentLimit: %t\n\n", adj, d.Exponent <= 0 && adj >= adjExponentLimit)
}
} output:
I think we need to special case 0 somehow in this logic. |
Also not sure
@rafiss penny for your thoughts? |
After #102220, not sure how possible this is to fix. It goes really deep as the "Decimal.String()" method is called EVERYWHERE (e.g. execution code). Fixing it exhaustively means fixing it at the |
@dikshant PTAL and see if you can get this prioritized |
I can confirm with #102299 which has cockroachdb/apd#128 in, AWS DMS validation works as expected for this case. It's a somewhat weird fix as cockroachdb/apd doesn't do the thing I think it should do (following the RDA spec, |
102299: tree: fix decimal strings for 0 with exponents < -6 r=rafiss a=otan Release note (bug fix): Fix a bug where 0 with exponents < -6 would display as `0E(exponent)` instead of printing all 0s, e.g. `0E-7` should be `0.0000000`. Informs #102217 103078: sql: resolve values types after building scalars in optbuilder r=rharding6373 a=rharding6373 Previously, we would build scalars in VALUES clauses after resolving the value column types. However, for UDFs, we modify the type if it's a record-returning function during the build. In this change we reverse the order so that we build scalars and then resolve types. This bug was introduced by #98162. Epic: None Fixes: #102718 Release note: This fixes a bug in VALUES clauses containing a call to a record-returning UDF that could manifest as an internal error in some queries. 103588: kvstreamer: add non-negative float validation to a cluster setting r=yuzefovich a=yuzefovich We forgot to add non-negative validation function to private `sql.distsql.streamer.avg_response_size_multiple` cluster setting. If this were set to a negative value, it would result in an undefined behavior of the streamer (we could try setting negative `TargetBytes` limit on `BatchRequest`s). I don't think anyone ever used it though so far. Epic: None Release note: None 103625: ccl/sqlproxyccl: fix flake on TestWatchTenants r=JeffSwenson a=jaylim-crl Fixes #103494. This commit fixes a flake on TestWatchTenants. There's a possibility where the cache invalidation logic races with the watcher termination logic in the test. This commit updates the test to wait for the cache invalidation before proceeding. Release note: None Epic: none Co-authored-by: Oliver Tan <otan@cockroachlabs.com> Co-authored-by: rharding6373 <rharding6373@users.noreply.github.com> Co-authored-by: Yahor Yuzefovich <yahor@cockroachlabs.com> Co-authored-by: Jay <jay@cockroachlabs.com>
closed by #102299 |
In CockroachDB, 0 is formatted differently for
DECIMAL(19,9)
:Compared to postgresql:
This seems to happen for scale >= 7:
This is affect third party tooling which does exact comparisons for validation.
Jira issue: CRDB-27348
Epic CRDB-27601
The text was updated successfully, but these errors were encountered: