Skip to content

GODRIVER-3987: Implement conditional, higher-order, and misc expression operators and tests - #16

Merged
linborland merged 3 commits into
mongodb-labs:mainfrom
linborland:godriver3987
Jul 22, 2026
Merged

GODRIVER-3987: Implement conditional, higher-order, and misc expression operators and tests#16
linborland merged 3 commits into
mongodb-labs:mainfrom
linborland:godriver3987

Conversation

@linborland

Copy link
Copy Markdown
Contributor

GODRIVER-3987

Implements the following operators and their corresponding tests:

  • Conditional: $cond, $switch (plus exported SwitchCase type and Case constructor)
  • Higher-order: $let, $map, $reduce, $function
  • Misc: $literal, $rand, $meta, $createObjectId
  • Statistical: $percentile, $median
  • Similarity: $similarityCosine, $similarityDotProduct, $similarityEuclidean
  • Hash/EJSON: $hash, $hexHash, $serializeEJSON, $deserializeEJSON

Adds the string type to the BoolResolver type.

Fixes Concat to allow concatenation of different types.

Renames FilterArray to Filter for consistency with operator name: $filter.

@linborland
linborland requested a review from a team as a code owner July 14, 2026 19:02
@linborland
linborland requested review from qingyang-hu and removed request for a team July 14, 2026 19:02
Comment thread mql/agg/operator.go
Comment on lines +718 to +720
if o.hasOnError {
doc = append(doc, bson.E{Key: "onError", Value: o.onError})
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion] Is it possible to extend the hasOnError/hasDefault pattern to the older WithConvertOnError/WithConvertOnNull/WithShiftDefault options, where nulls are dropped silently?

Comment thread mql/agg/operator.go Outdated
Comment on lines +828 to +830
if o.lang != nil {
lang = o.lang.(string)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion] Maybe we can use a hasLang here?

Comment thread mql/agg/operator.go
}
return AnyExpr{expr: bson.D{{Key: "$function", Value: bson.D{
{Key: "body", Value: bson.JavaScript(body)},
{Key: "args", Value: args},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blocking] We need to normalize a nil args slice to a non-nil empty slice:

if args == nil {
	args = []Expr{}
}

Otherwise, the function returns args: null.
A test case is also worthwhile to safeguard it.

@linborland
linborland requested a review from qingyang-hu July 21, 2026 15:03
@linborland
linborland merged commit 5f997bd into mongodb-labs:main Jul 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants