-
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
logictest: introduce a separate matcher for floats #55530
Conversation
92eb84a
to
fa818d7
Compare
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.
Reviewed 1 of 2 files at r1.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @asubiotto and @yuzefovich)
pkg/sql/logictest/logic.go, line 167 at r1 (raw file):
// to string (arrays, timestamps, etc.). // - I for integer // - F for floating point (matches 15 significant decimal digits)
Add a link to the postgres docs here.
pkg/sql/logictest/logic.go, line 2513 at r1 (raw file):
if *flexTypes && (valT == reflect.Int64) { t.signalIgnoredError( fmt.Errorf("result type mismatch: expected R, got %T", val), query.pos, query.sql,
nit: update
pkg/sql/logictest/logic.go, line 2630 at r1 (raw file):
if query.checkResults { resultsMatch := reflect.DeepEqual(query.expectedResults, actualResults)
It feels wrong to do a full equality check and then check for float columns if it fails. If we're just checking strings, why do we need to do a DeepEqual
? I would iterate over the results in order and change the equality check based on the type.
pkg/sql/logictest/logic.go, line 2656 at r1 (raw file):
resultsMatch = true for i, colT := range query.colTypes { expected, actual := query.expectedResults[i], actualResults[i]
I would extract this logic into a separate function which you might be able to unit test (why not?). This'll also make this main body of code easier to read.
pkg/sql/logictest/logic.go, line 2685 at r1 (raw file):
} expFloat = normalize(expFloat) actFloat = normalize(actFloat)
Won't this return that 123.45
and 12.345
are equal since they'll both be normalized to 1.2345
?
fa818d7
to
8eca2d2
Compare
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @asubiotto)
pkg/sql/logictest/logic.go, line 167 at r1 (raw file):
Previously, asubiotto (Alfonso Subiotto Marqués) wrote…
Add a link to the postgres docs here.
Done.
pkg/sql/logictest/logic.go, line 2630 at r1 (raw file):
Previously, asubiotto (Alfonso Subiotto Marqués) wrote…
It feels wrong to do a full equality check and then check for float columns if it fails. If we're just checking strings, why do we need to do a
DeepEqual
? I would iterate over the results in order and change the equality check based on the type.
Good idea, done.
pkg/sql/logictest/logic.go, line 2656 at r1 (raw file):
Previously, asubiotto (Alfonso Subiotto Marqués) wrote…
I would extract this logic into a separate function which you might be able to unit test (why not?). This'll also make this main body of code easier to read.
Good idea, done.
pkg/sql/logictest/logic.go, line 2685 at r1 (raw file):
Previously, asubiotto (Alfonso Subiotto Marqués) wrote…
Won't this return that
123.45
and12.345
are equal since they'll both be normalized to1.2345
?
Yes, you're right, good catch.
8eca2d2
to
692ff30
Compare
This commit adds another type annotation `F` intended to be used for floating point numbers which have a separate matcher that allows for some deviation in the precision. Namely, the matcher checks that the expected and the actual numbers match in 15 significant decimal digits. Note that I think the matching algorithm introduces some rounding errors, so it might not work perfectly in all scenarios, yet it should be good enough in rare test cases when we need it. Release note: None
692ff30
to
9d2c054
Compare
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.
Reviewed 1 of 2 files at r1, 4 of 4 files at r2.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @asubiotto and @yuzefovich)
pkg/sql/logictest/logic.go, line 2705 at r2 (raw file):
} if expected == 0 || actual == 0 { return expected == actual, nil
Is this correct? What about if expected is 0
and actual is 0.0000000000000000000000001
?
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @asubiotto)
pkg/sql/logictest/logic.go, line 2705 at r2 (raw file):
Previously, asubiotto (Alfonso Subiotto Marqués) wrote…
Is this correct? What about if expected is
0
and actual is0.0000000000000000000000001
?
I believe these should be treated as different. The question is what Postgres refers to as 15 decimal digits precision
- I believe it means 15 significant decimal digits are correct, and in your example we have only 1 significant digit in the right number if I'm not mistaken.
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.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @yuzefovich)
pkg/sql/logictest/logic.go, line 2705 at r2 (raw file):
Previously, yuzefovich wrote…
I believe these should be treated as different. The question is what Postgres refers to as
15 decimal digits precision
- I believe it means 15 significant decimal digits are correct, and in your example we have only 1 significant digit in the right number if I'm not mistaken.
I think you're right.
TFTR! bors r+ |
Build succeeded: |
This commit adds another type annotation
F
intended to be used forfloating point numbers which have a separate matcher that allows for
some deviation in the precision. Namely, the matcher checks that the
expected and the actual numbers match in 15 significant decimal
digits. Note that I think the matching algorithm introduces some
rounding errors, so it might not work perfectly in all scenarios, yet it
should be good enough in rare test cases when we need it.
Informs: #55268.
Release note: None