Uploaded image for project: 'Pentaho Analysis - Mondrian'
  1. Pentaho Analysis - Mondrian
  2. MONDRIAN-648

AS operator has lower precedence than required by MDX specification


    • Type: Bug
    • Status: Open
    • Severity: Medium
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: Backlog
    • Component/s: None
    • Labels:
    • Notice:
      When an issue is open, the "Fix Version/s" field conveys a target, not necessarily a commitment. When an issue is closed, the "Fix Version/s" field conveys the version that the issue was fixed in.


      The AS operator (which creates named sets within expressions) has the wrong precedence.

      For example, given

      select [Time].Children * [Gender].Children as t on 0 from Sales

      should according to the MDX spec be equivalent to

      select [Time].Children * ([Gender].Children as t) on 0 from Sales

      but in current Mondrian it is equivalent to

      select ([Time].Children * [Gender].Children) as t on 0 from Sales

      In other words, 'AS' has lower precedence than '*' but should have higher precedence.

      From "Operators (MDX Syntax)" http://msdn.microsoft.com/en-us/library/ms144825.aspx :

      > The following list shows operator precedence, from highest to lowest.
      > Operators in the same line are equal in precedence, and are
      > evaluated from left to right unless otherwise forced by parenthesis:
      > IS
      > AS
      > DISTINCT
      > :
      > ^
      > /, *
      > +, -
      > EXISTING
      > <>, >=, =, <=, >, <
      > NOT
      > AND
      > XOR
      > OR

      The low precedence of AS is necessary because AS in the CAST operator has low precedence. Otherwise

      CAST(a AND b AS string)

      would be parsed as

      CAST(a AND (b AS string))

      which is silly. It's difficult to give AS different precedences in different contexts, so we chose to favor CAST. If the precedence rules don't suit, you can add parentheses.

      For more examples, search for this bug number in Mondrian source code and test suite. (Bug.BugMondrianXxxFixed.)




            • Assignee:
              jhyde Julian Hyde
              jhyde Julian Hyde
            • Votes:
              0 Vote for this issue
              0 Start watching this issue


              • Created: