Render select-list literals as $literal so MQL does not read them as inclusion flags

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Major - P3
    • 1.0.0
    • Affects Version/s: None
    • Component/s: Query
    • 1
    • None
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      Summary

      A literal in the select list becomes a $project value. Rendered bare, MQL reads it as an
      inclusion or exclusion flag, or as a field path, rather than as a constant, so it has to be wrapped
      in $literal.

      Hibernate ORM emits such literals on its own, not only when an application writes one. Loading an
      entity whose embeddable holds the non-owning side of an association projects a null placeholder:

      {"aggregate": "shelters", "pipeline": [
        {"$match": {"_id": {"$eq": 1}}},
        {"$project": {"#c_1": {"$literal": null}}}
      ]}
      

      A numeric literal is the case MQL is most likely to misread rather than reject: {{select 1, i.name
      from Item i}} renders a value of 1, which $project treats as an inclusion flag for a field named
      after the alias.

      Proposed fix

      In AbstractMqlTranslator, wrap a projection expression that resolves to a value in
      AstLiteralExpression before adding it to the $project stage.

      Acceptance

      select null, i.name from Item i, select 'foobar', i.name from Item i and {{select 1, i.name
      from Item i}} each return the literal at position 1 and the attribute at position 2.

            Assignee:
            Jeffrey Yemin
            Reporter:
            Jeffrey Yemin
            Almas Abdrazak
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: