Skip to content

Commit

Permalink
[release-18.0] evalengine: Fix the min / max calculation for decimals (
Browse files Browse the repository at this point in the history
…#14614) (#14616)

Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
  • Loading branch information
vitess-bot[bot] authored Nov 27, 2023
1 parent bd364eb commit 34db0da
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 34db0da

Please sign in to comment.