Generate unique fieldname for partitionBy expression

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Fixed
    • Priority: Major - P3
    • 4.9.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible
    • Query Optimization 2021-02-22
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      When parsing a $setWindowFields stage, we translate the partitionBy to a $sort stage. But $sort can only sort by a field, not an expression. So, if the partitionBy expression is not a field path, we move the expression to a $set stage.

      The translation looks roughly like this:

      {$setWindowFields: {partitionBy: {$add: ...}, ...} }
      =>
      {$set: {tmp: {$add ...} } }
      {$sort: {tmp: 1} }
      {$_internalSetWindowFields: {partitionBy: "$tmp", ...} }
      {$unset: 'tmp'}
      

      But this is incorrect if the input has a field named 'tmp' already. (The actual name we use is not "tmp" but something like "_internal_setWindowFields_partitionKey".)

      Instead, we should generate a random fieldname, like a UUID (although maybe we want to string-encode it more efficiently than the usual hexadecimal).

            Assignee:
            Hartek Sabharwal
            Reporter:
            David Percy (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: