Stamatis Zampetakis created CALCITE-6832: --------------------------------------------
Summary: Redundant fields/nullable entries in STRUCT serialization to JSON Key: CALCITE-6832 URL: https://issues.apache.org/jira/browse/CALCITE-6832 Project: Calcite Issue Type: Bug Affects Versions: 1.38.0 Reporter: Stamatis Zampetakis Assignee: Stamatis Zampetakis Fix For: 1.39.0 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. {code:java} 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); {code} At the moment, the JSON serialization for the field "address" is shown below. {code:json} { "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" } {code} 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: {code:json} { "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" } {code} -- This message was sent by Atlassian Jira (v8.20.10#820010)