clintropolis opened a new pull request, #12851:
URL: https://github.com/apache/druid/pull/12851

   ### Description
   Fixes some issues with SQL return type information of nested column 
functions that return `COMPLEX<json>` types.
   
   Druid native `COMPLEX` types are handled in SQL with 
`RowSignatures.ComplexSqlType`, which contains the native complex type name, 
which is a relatively recent addition. This works relatively well so far, but 
there were a few rough edges with how we were using it and the way that calcite 
works that were causing the complex type information to be lost, making the 
query result type header information report the types as `COMPLEX` (the 
"unknown" complex) instead of `COMPLEX<json>`. The reason for this loss of 
information was due to the way `ReturnTypes.explicit` type inference works, 
which makes a new type using the `SqlTypeName`, which would lose the Druid 
complex type name when it made a standard `SqlTypeName.OTHER` instead of a 
`RowSignatures.ComplexSqlType`. This can be fixed by implementing the return 
type directly. However, this made apparent another issue, which is that Calcite 
uses `!=` to check type equality instead of `equals`, so it is necessary to 
feed the `RowSignatures.C
 omplexSqlType` into the `RelDataTypeFactory` to ensure that the type is 
interned so that all of the signatures are using the same instance.
   
   Ive added a new method 
   ```
   public static RelDataType makeComplexType(RelDataTypeFactory typeFactory, 
ColumnType columnType, boolean isNullable)
   ```
   
   which uses the `typeFactory` to ensure that the types are interned. I've 
also updated the javadocs to mention how to effectively use 
`RowSignatures.ComplexSqlType` if not using this method to try to prevent other 
users of this type from
   running into the same issues.
   
   I've also added some methods to `BaseCalciteQueryTest` that allow expecting 
the result `RowSignature` of the query being tested, and switched 
`CalciteNestedQueryTest` to use them to ensure that the the fixes work 
correctly.
   
   <hr>
   
   <!-- Check the items by putting "x" in the brackets for the done things. Not 
all of these items apply to every PR. Remove the items which are not done or 
not relevant to the PR. None of the items from the checklist below are strictly 
necessary, but it would be very helpful if you at least self-review the PR. -->
   
   This PR has:
   - [ ] been self-reviewed.
      - [ ] using the [concurrency 
checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md)
 (Remove this item if the PR doesn't have any relation to concurrency.)
   - [ ] added documentation for new or modified features or behaviors.
   - [ ] added Javadocs for most classes and all non-trivial methods. Linked 
related entities via Javadoc links.
   - [ ] added or updated version, license, or notice information in 
[licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
   - [ ] added comments explaining the "why" and the intent of the code 
wherever would not be obvious for an unfamiliar reader.
   - [ ] added unit tests or modified existing tests to cover new code paths, 
ensuring the threshold for [code 
coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md)
 is met.
   - [ ] added integration tests.
   - [ ] been tested in a test Druid cluster.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to