Anjali, If you’re using RelBuilder to create the union, or creating the union manually, it is your responsibility to make sure that the input RelNodes have compatible types.
RelDataTypeFactory.leastRestrictive(List<RelDataType>) may be useful. Julian > On Apr 27, 2020, at 1:32 PM, Rui Wang <amaliu...@apache.org> wrote: > > Did a quick test by running a SQL query that has UNION on two different > types. Validator gave a correct error message (not NPE) to remind type > mismatch. > > Agreed with Jin, could you provide more context/example how you reach the > NPE? (It could be better if you can file a Jira with your context). > > > -Rui > > On Mon, Apr 27, 2020 at 4:35 AM XING JIN <jinxing.co...@gmail.com> wrote: > >> Hi, Anjali ~ >> Are you doing the UNION by Sql ? If so, can you give the Sql content ? >> Are you doing the UNION on RelNodes ?, If so, you need to do type CAST. >> >> Jin >> >> Anjali Shrishrimal <anjali.shrishri...@1eq.com.invalid> 于2020年4月27日周一 >> 下午4:25写道: >> >>> Hi, >>> >>> While doing union of 2 RelNodes with different types, I am getting NPE. >> (I >>> am using calcite 1.21.0) >>> java.lang.NullPointerException: at index 0 >>> at >>> >> com.google.common.collect.ObjectArrays.checkElementNotNull(ObjectArrays.java:225) >>> at >>> >> com.google.common.collect.ObjectArrays.checkElementsNotNull(ObjectArrays.java:215) >>> at >>> >> com.google.common.collect.ObjectArrays.checkElementsNotNull(ObjectArrays.java:209) >>> at >>> com.google.common.collect.ImmutableList.construct(ImmutableList.java:346) >>> at >>> com.google.common.collect.ImmutableList.copyOf(ImmutableList.java:258) >>> at >>> >> org.apache.calcite.rel.type.RelDataTypeFactoryImpl.canonize(RelDataTypeFactoryImpl.java:373) >>> at >>> >> org.apache.calcite.rel.type.RelDataTypeFactoryImpl.createStructType(RelDataTypeFactoryImpl.java:155) >>> at >>> >> org.apache.calcite.rel.type.RelDataTypeFactoryImpl.createStructType(RelDataTypeFactoryImpl.java:146) >>> at >>> >> org.apache.calcite.rel.type.RelDataTypeFactory$Builder.build(RelDataTypeFactory.java:569) >>> at >>> >> org.apache.calcite.rel.type.RelDataTypeFactoryImpl.leastRestrictiveStructuredType(RelDataTypeFactoryImpl.java:257) >>> at >>> >> org.apache.calcite.sql.type.SqlTypeFactoryImpl.leastRestrictiveSqlType(SqlTypeFactoryImpl.java:285) >>> at >>> >> org.apache.calcite.sql.type.SqlTypeFactoryImpl.leastRestrictive(SqlTypeFactoryImpl.java:156) >>> at >>> org.apache.calcite.rel.core.SetOp.deriveRowType(SetOp.java:107) >>> >>> If the column types (family types) are different, currently the derived >>> type is null. Is there any way to control that? >>> Where can I define the type in case of mismatch ? >>> >>> >>> Thank you, >>> Anjali Shrishrimal >>> >>