Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support _id aggregation operators for $group stage #3096

Merged
merged 19 commits into from
Jul 26, 2023
Prev Previous commit
Next Next commit
cleanup
  • Loading branch information
noisersup committed Jul 25, 2023
commit 360c368c595f58d17656cc0e17a8c2c0e79846f9
12 changes: 6 additions & 6 deletions integration/aggregate_documents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestAggregateGroupErrors(t *testing.T) {
altMessage string // optional, alternative error message for FerretDB, ignored if empty
skip string // optional, skip test with a specified reason
}{
"GroupUnaryOperatorSum": {
"UnaryOperatorSum": {
pipeline: bson.A{
bson.D{{"$group", bson.D{{"sum", bson.D{{"$sum", bson.A{}}}}}}},
},
Expand All @@ -105,7 +105,7 @@ func TestAggregateGroupErrors(t *testing.T) {
},
altMessage: "The $sum accumulator is a unary operator",
},
"GroupTypeEmpty": {
"TypeEmpty": {
pipeline: bson.A{
bson.D{{"$group", bson.D{{"v", bson.D{}}}}},
},
Expand All @@ -115,7 +115,7 @@ func TestAggregateGroupErrors(t *testing.T) {
Message: "The field 'v' must be an accumulator object",
},
},
"GroupTwoOperators": {
"TwoOperators": {
pipeline: bson.A{
bson.D{{"$group", bson.D{{"_id", bson.D{{"$type", int32(42)}, {"$op", int32(42)}}}}}},
},
Expand All @@ -126,7 +126,7 @@ func TestAggregateGroupErrors(t *testing.T) {
},
altMessage: "An object representing an expression must have exactly one field",
},
"GroupTypeInvalidLen": {
"TypeInvalidLen": {
pipeline: bson.A{
bson.D{{"$group", bson.D{{"_id", bson.D{{"$type", bson.A{"foo", "bar"}}}}}}},
},
Expand All @@ -136,7 +136,7 @@ func TestAggregateGroupErrors(t *testing.T) {
Message: "Expression $type takes exactly 1 arguments. 2 were passed in.",
},
},
"GroupNonExistentOperator": {
"NonExistentOperator": {
pipeline: bson.A{
bson.D{{"$group", bson.D{{"_id", bson.D{{"$non-existent", "foo"}}}}}},
},
Expand Down Expand Up @@ -182,7 +182,7 @@ func TestAggregateGroupErrors(t *testing.T) {
Message: "'$' starts with an invalid character for a user variable name",
},
},
"GroupRecursiveNonExistentOperator": {
"RecursiveNonExistentOperator": {
pipeline: bson.A{
bson.D{{"$group", bson.D{{"_id", bson.D{{"$type", bson.D{{"$non-existent", "foo"}}}}}}}},
},
Expand Down
9 changes: 0 additions & 9 deletions internal/handlers/common/aggregations/stages/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,6 @@ func (m *groupMap) addOrAppend(groupKey any, docs ...*types.Document) {

// processOperatorError takes internal error related to operator evaluation and
// returns proper CommandError that can be returned by $group aggregation stage.
//
// Command error codes:
// - ErrEmptySubProject when operator value is empty.
// - ErrFieldPathInvalidName when FieldPath is invalid.
// - ErrNotImplemented when the operator or expression is not implemented yet.
// - ErrOperatorWrongLenOfArgs when the operator has an invalid number of arguments.
// - ErrInvalidPipelineOperator when the operator does not exist.
// - ErrFailedToParse when operator has invalid variable expression.
// - ErrGroupInvalidFieldPath when operator has empty path expression.
func processOperatorError(err error) error {
chilagrow marked this conversation as resolved.
Show resolved Hide resolved
var opErr operators.OperatorError
var exErr *aggregations.ExpressionError
Expand Down