From 34db0daf1f1d55bcd0f7ec1c9ff780b5b89d7d4c Mon Sep 17 00:00:00 2001 From: "vitess-bot[bot]" <108069721+vitess-bot[bot]@users.noreply.github.com> Date: Mon, 27 Nov 2023 10:23:18 -0600 Subject: [PATCH] [release-18.0] evalengine: Fix the min / max calculation for decimals (#14614) (#14616) Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com> --- go/vt/vtgate/evalengine/api_aggregation.go | 2 ++ go/vt/vtgate/evalengine/api_aggregation_test.go | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/go/vt/vtgate/evalengine/api_aggregation.go b/go/vt/vtgate/evalengine/api_aggregation.go index c0d490ced22..05a4f8711ad 100644 --- a/go/vt/vtgate/evalengine/api_aggregation.go +++ b/go/vt/vtgate/evalengine/api_aggregation.go @@ -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 } @@ -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 } diff --git a/go/vt/vtgate/evalengine/api_aggregation_test.go b/go/vt/vtgate/evalengine/api_aggregation_test.go index aab49541e71..bd3a10547fe 100644 --- a/go/vt/vtgate/evalengine/api_aggregation_test.go +++ b/go/vt/vtgate/evalengine/api_aggregation_test.go @@ -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,