Hi Gelbana, I am not sure why the scalar type is always nullable at this part of the code but I would expect that the type is obtained as follows:
final RelDataType type = typeFactory.copyType(fieldList.get(0).getType()); // which copies also the nullability of the type instead of final RelDataType type = typeFactory.createTypeWithNullability(fieldList.get(0).getType(), fieldList.get(0).getType().isNullable()); Best, Stamatis Στις Τρί, 5 Μαρ 2019 στις 2:01 μ.μ., ο/η Muhammad Gelbana < [email protected]> έγραψε: > 'm trying to rewrite the below query to be > SELECT (SELECT PRONAME FROM PG_PROC WHERE OID = col1) FROM (VALUES > ('array_in', 'array_out')) as tbl(col1, col2) > > When I try to test my code using this query > SELECT col1::regproc FROM (VALUES ('array_in', 'array_out')) as tbl(col1, > col2) > > The casting expression (col1::regproc) type is derived as *not* nullable > because the casting is applied on a column selected from VALUES. > > But RexSubQuery.scalar[1] always returns a RelNode with a nullable type. > > The exception I get when I try to run the query after rewriting is: > > set type is RecordType(REGPROC *NOT NULL* EXPR$0) NOT NULL > expression type is RecordType(REGPROC EXPR$0) NOT NULL > set is > rel#11:LogicalProject.NONE.[0](input=HepRelVertex#10,EXPR$0=$SCALAR_QUERY({ > LogicalFilter(condition=[=($1, $0)]) > LogicalProject(PRONAME=[$0]) > LogicalTableScan(table=[[PG_CATALOG, PG_PROC]]) > })) > expression is LogicalProject(EXPR$0=[$2]) > LogicalJoin(condition=[true], joinType=[left]) > LogicalValues(tuples=[[{ 'array_in', 'array_out' }]]) > LogicalAggregate(group=[{}], agg#0=[SINGLE_VALUE($0)]) > LogicalFilter(condition=[=($1, $0)]) > LogicalProject(PRONAME=[$0]) > LogicalTableScan(table=[[PG_CATALOG, PG_PROC]]) > > at > > org.apache.calcite.plan.RelOptUtil.verifyTypeEquivalence(RelOptUtil.java:381) > at > org.apache.calcite.plan.hep.HepRuleCall.transformTo(HepRuleCall.java:57) > at > org.apache.calcite.plan.RelOptRuleCall.transformTo(RelOptRuleCall.java:234) > at > > org.apache.calcite.rel.rules.SubQueryRemoveRule$SubQueryProjectRemoveRule.onMatch(SubQueryRemoveRule.java:518) > > Shouldn't we be able to specify if the scalar query type created by > RexSubQuery.scalar is nullable or not ? > > [1] > > https://github.com/apache/calcite/blob/d10aeb7f7e50dc7028ce102a5f590d0c50c49fa8/core/src/main/java/org/apache/calcite/rex/RexSubQuery.java#L94 > > Thanks, > Gelbana >
