Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-4387

Document that RexSimplify.simplifyUnknownAs could narrow or widen nullness of the given expression

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.26.0
    • None
    • core
    • None

    Description

      It is expected that RexSimplify.simplifyUnknownAs would make the expression "simpler" (e.g. less RexNodes or something like that), however, there's no explicit contract on the resulting expression.

      For instance the following expression has non-nullable type

      case_(isUnknown(vBool(1)), trueLiteral, vBool(1), falseLiteral, trueLiteral)
      

      however, it might be simplified to the following *nullable* expression:

      or(isUnknown(vBool(1)), not(vBool(1)))
      

      Note: the expression never returns null, however, it might be not that obvious that the simplified expression never returns null.

      I suggest we add explicit note to simplifyUnknownAs method that says the method is allowed to narrow or widen the nullness of the given expression type

      simplifyPreservingType(RexNode, RexUnknownAs, boolean matchNullability) could be used to keep nullness intact.

      PS. It woud be nice to simplify or(isUnknown(vBool(1)), not(vBool(1))) to isNotTrue(vBool(1)), however, that is another story. I guess there might be different cases (e.g. involving more complicated cases) that would result in nullability "widening".

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              vladimirsitnikov Vladimir Sitnikov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: