Re: How to give type in case of type mismatch while doing union
> On Apr 29, 2020, at 21:31, Danny Chan wrote: > > Or try SQL, it has the implicit type coercion ~ That’s true. SQL is a great way to build relational algebra expressions. Highly recommended. Julian
Re: How to give type in case of type mismatch while doing union
Or try SQL, it has the implicit type coercion ~ Best, Danny Chan 在 2020年4月28日 +0800 AM4:36,Julian Hyde ,写道: > 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) may be useful. > > Julian > > > > On Apr 27, 2020, at 1:32 PM, Rui Wang 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 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 于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 > > > > > > > >
Re: How to give type in case of type mismatch while doing union
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) may be useful. Julian > On Apr 27, 2020, at 1:32 PM, Rui Wang 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 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 于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 >>> >>
Re: How to give type in case of type mismatch while doing union
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 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 于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 > > >
Re: How to give type in case of type mismatch while doing union
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 于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 >
How to give type in case of type mismatch while doing union
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