zabetak commented on a change in pull request #898: [CALCITE-2464] Allow to set nullability for columns of structured types (Ruben Quesada Lopez) URL: https://github.com/apache/calcite/pull/898#discussion_r259329627
########## File path: core/src/main/java/org/apache/calcite/jdbc/JavaTypeFactoryImpl.java ########## @@ -243,11 +243,24 @@ public RelDataType toSql(RelDataType type) { /** Converts a type in Java format to a SQL-oriented type. */ public static RelDataType toSql(final RelDataTypeFactory typeFactory, RelDataType type) { + return toSql(typeFactory, type, true); + } + + private static RelDataType toSql(final RelDataTypeFactory typeFactory, + RelDataType type, boolean isRootType) { if (type instanceof RelRecordType) { - return typeFactory.createStructType( - Lists.transform(type.getFieldList(), - field -> toSql(typeFactory, field.getType())), - type.getFieldNames()); + RelDataType structType = typeFactory.createStructType( + Lists.transform(type.getFieldList(), + field -> toSql(typeFactory, field.getType(), false)), + type.getFieldNames()); + + // struct types are created by default with nullability false, so if we are dealing + // with the "root" type and it should be nullable, change its nullability + if (isRootType && type.isNullable()) { Review comment: I would move this if at the end of the method and unify setting the nullability for struct and java types. Checking if the type is nullable is not necessary since the control is already incorporated inside `createTypeWithNullability` method. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services