Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-24311

Support expression reduction for JSON construction functions

    XMLWordPrintableJSON

Details

    Description

      For JSON construction functions such as JSON_OBJECT, we currently disable expression reduction. This is because these functions have special semantics where they behave differently depending on their call context. For example, JSON_OBJECT returns a JSON string. This means that a call like

      JSON_OBJECT('A' VALUE JSON_OBJECT('B' VALUE 'C'))

      would result in

      {"A": "{\"B\": \"C\"}"}

      However, this is not user-friendly, and thus such nested calls are treated differently and instead result in the likely more intended outcome

      {"A": {"B": "C"}}

      To make this work, the function looks at its operands and checks whether each operand is another RexCall to such a JSON construction function. If it is, it inserts it as a raw node instead.

      This creates a problem during expression reduction. The RexCall will be replaced with a RexLiteral carrying the JSON string value. The function looking at the operands now cannot determine that this originated from such a RexCall anymore, and yields the unintended result once again. To prevent this, we currently disable expression reduction for these functions.

      We should aim to once again allow such expressions to be reduced while still preserving the intended behavior. See this comment for a rough idea of how this could be achieved.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              airblader Ingo Bürk
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated: