Skip to content

Commit

Permalink
evalengine: Fix the min / max calculation for decimals (#14614)
Browse files Browse the repository at this point in the history
Signed-off-by: Dirkjan Bussink <[email protected]>
  • Loading branch information
dbussink authored Nov 27, 2023
1 parent 3828d43 commit 6f7dfc7
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 6f7dfc7

Please sign in to comment.