Skip to content

Commit

Permalink
evalengine: Fix the min / max calculation for decimals
Browse files Browse the repository at this point in the history
We were not storing the precision for the decimal here, resulting in
accidentally rounding it.

Signed-off-by: Dirkjan Bussink <[email protected]>
  • Loading branch information
dbussink committed Nov 27, 2023
1 parent 36a52e9 commit 1e5bf5c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions go/vt/vtgate/evalengine/api_aggregation.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ func (s *aggregationDecimal) Min(value sqltypes.Value) error {
}
if !s.dec.IsInitialized() || dec.Cmp(s.dec) < 0 {
s.dec = dec
s.prec = -dec.Exponent()
}
return nil
}
Expand All @@ -403,6 +404,7 @@ func (s *aggregationDecimal) Max(value sqltypes.Value) error {
}
if !s.dec.IsInitialized() || dec.Cmp(s.dec) > 0 {
s.dec = dec
s.prec = -dec.Exponent()
}
return nil
}
Expand Down
6 changes: 6 additions & 0 deletions go/vt/vtgate/evalengine/api_aggregation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ func TestMinMax(t *testing.T) {
min: sqltypes.NewVarBinary("a"),
max: sqltypes.NewVarBinary("b"),
},
{
type_: sqltypes.Decimal,
values: []sqltypes.Value{sqltypes.NewDecimal("1.001"), sqltypes.NewDecimal("2.1")},
min: sqltypes.NewDecimal("1.001"),
max: sqltypes.NewDecimal("2.1"),
},
{
// accent insensitive
type_: sqltypes.VarChar,
Expand Down

0 comments on commit 1e5bf5c

Please sign in to comment.