From e94f297bc6c738f50e546e2581248b6c3705fd24 Mon Sep 17 00:00:00 2001 From: Michael Pawliszyn Date: Wed, 21 Aug 2019 14:04:12 -0400 Subject: [PATCH] Empty results should return a count of 0 but a sum of null. Signed-off-by: Michael Pawliszyn --- go/vt/vtgate/engine/ordered_aggregate.go | 4 ++-- go/vt/vtgate/engine/ordered_aggregate_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go/vt/vtgate/engine/ordered_aggregate.go b/go/vt/vtgate/engine/ordered_aggregate.go index fa541903cbb..6044a79b398 100644 --- a/go/vt/vtgate/engine/ordered_aggregate.go +++ b/go/vt/vtgate/engine/ordered_aggregate.go @@ -376,9 +376,9 @@ func (oa *OrderedAggregate) createEmptyRow() ([]sqltypes.Value, error) { func createEmptyValueFor(opcode AggregateOpcode) (sqltypes.Value, error) { switch opcode { case AggregateCountDistinct: - return sqltypes.NULL, nil + return countZero, nil case AggregateSumDistinct: - return sumZero, nil + return sqltypes.NULL, nil } return sqltypes.NULL, vterrors.Errorf(vtrpc.Code_INVALID_ARGUMENT, "unknown aggregation %v", opcode) } diff --git a/go/vt/vtgate/engine/ordered_aggregate_test.go b/go/vt/vtgate/engine/ordered_aggregate_test.go index 5706761f031..43fd8ba8087 100644 --- a/go/vt/vtgate/engine/ordered_aggregate_test.go +++ b/go/vt/vtgate/engine/ordered_aggregate_test.go @@ -674,7 +674,7 @@ func TestNoInputAndNoGroupingKeys(t *testing.T) { "count(distinct col2)|sum(distinct col2)", "int64|decimal", ), - "null|0", + "0|null", ) assert.Equal(wantResult, result) }