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

Redundant fields/nullable entries in STRUCT serialization to JSON

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.38.0
    • 1.39.0
    • None

    Description

      The JSON serialization of a RelDatatypeField of type STRUCT contains redundant fields and nullable entries along with unnecessary nesting.

      Consider for example, a field "address" of type STRUCT composed from the following fields.

      RelDataType type = typeFactory.builder()
              .add("street", SqlTypeName.VARCHAR, 50)
              .add("number", SqlTypeName.INTEGER)
              .add("building", SqlTypeName.VARCHAR, 20).nullable(true)
              .build();
          RelDataTypeField address =
              new RelDataTypeFieldImpl("address", 0, type);
      

      At the moment, the JSON serialization for the field "address" is shown below.

      {
        "fields": {
          "fields": [
            {
              "type": "VARCHAR",
              "nullable": false,
              "precision": 50,
              "name": "street"
            },
            {
              "type": "INTEGER",
              "nullable": false,
              "name": "number"
            },
            {
              "type": "VARCHAR",
              "nullable": true,
              "precision": 20,
              "name": "building"
            }
          ],
          "nullable": false
        },
        "nullable": false,
        "name": "address"
      }
      

      Note that the "fields" key appears twice and there is an unnecessary wrapping of a JSON array (inner "fields") inside a JSON object (outer "fields"). The outer "fields" object cannot have more entries so it doesn't offer anything.

      Moreover, observe that there are two "nullable":false entries and both reflect the nullability of the "address" field.

      The redundancy leads to wasted space and more convoluted representation that is hard to follow especially when there are nested STRUCTS.

      The same information could be represented using the following JSON serialization:

      {
        "fields": [
          {
            "type": "VARCHAR",
            "nullable": false,
            "precision": 50,
            "name": "street"
          },
          {
            "type": "INTEGER",
            "nullable": false,
            "name": "number"
          },
          {
            "type": "VARCHAR",
            "nullable": true,
            "precision": 20,
            "name": "building"
          }
        ],
        "nullable": false,
        "name": "address"
      }
      

      Attachments

        Issue Links

          Activity

            People

              zabetak Stamatis Zampetakis
              zabetak Stamatis Zampetakis
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: