Skip to content

Use Names constants for the remaining operator wire names #2666

Open

Description

@erichare

#2651 adds UpdateOperator.Names, a set of string constants that the enum and its schema annotations both read. CommandName.Names already does the same for command names. A few other enums still have their wire names repeated as string literals in the code that parses them. This ticket moves those to the same pattern where it fits. It follows up on this review comment.

Why

A switch case label and an annotation value both need a compile-time constant. Code in those spots cannot call the enum's getter, so it repeats the literal instead. If one copy changes and the other does not, the parser stops matching that operator and nothing fails at compile time. A Names holder gives each wire name one definition that the enum, the switch statements, and any annotations all reference.

Where it applies

Links are pinned to 7056432.

  • LogicalExpression.LogicalOperator defines $and, $or, and $not (L15-L17). FilterClauseBuilder matches them as literals in a switch (L159-L160) and in an equals check (L148).
  • UpdateOperatorModifier defines $each and $position (L4-L5). AddToSetOperation (L58) and PushOperation (L61, L71) switch on the literals. TableUpdatePushResolver checks for "$each" directly (L121).
  • JsonExtensionType defines $date, $binary, $objectId, and $uuid (L14-L20). EJSONWrapper declares its own $DATE and $BINARY constants (L19-L21), and DocumentConstants.Fields.BINARY_VECTOR_TEXT_FIELD declares "$binary" a third time (L21). One of these should be the source and the others should point at it.

Out of scope

The filter comparison enums (ValueComparisonOperator, ArrayComparisonOperator, and ElementComparisonOperator) have no literal copies in code today. Their names only appear in Javadoc and in OpenAPI example text blocks, where a constant cannot go. Add a Names holder there only when a switch or an annotation starts to need one. Document field names such as $vector and $lexical already live in DocumentConstants.Fields.

Done when

Each enum above reads its wire names from a Names holder, and the listed call sites use those constants instead of literals. Accepted API syntax does not change, and the existing parser tests still pass.

CC @amorton

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions