Hey Guys,
I was hitting the following assertion when using an aggregate
function(max) with a drill custom function (substr)
/AssertionError:[ Internal error: while converting `substr`(`A`, 1, 3) ]
< InvocationTargetException < UnsupportedOperationException:[ class
org.eigenbase.sql.SqlUnresolvedFunction: substr ]"
/Stack Trace:
at org.eigenbase.util.Util.needToImplement(Util.java:903)
~[optiq-core-0.7-20140513.013236-5.jar:na]
at org.eigenbase.sql.SqlOperator.inferReturnType(SqlOperator.java:456)
~[optiq-core-0.7-20140513.013236-5.jar:na]
at org.eigenbase.rex.RexBuilder.deriveReturnType(RexBuilder.java:260)
~[optiq-core-0.7-20140513.013236-5.jar:na]
at org.eigenbase.rex.RexBuilder.makeCall(RexBuilder.java:219)
~[optiq-core-0.7-20140513.013236-5.jar:na]
at
org.eigenbase.sql2rel.StandardConvertletTable.convertFunction(StandardConvertletTable.java:597)
~[optiq-core-0.7-20140513.013236-5.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)(NativeMethodAccessorImpl.java) ~[na:1.7.0_45]
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
~[na:1.7.0_45]
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
~[na:1.7.0_45]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_45]
at
org.eigenbase.sql2rel.ReflectiveConvertletTable$2.convertCall(ReflectiveConvertletTable.java:139)
~[optiq-core-0.7-20140513.013236-5.jar:na]
at
org.eigenbase.sql2rel.SqlNodeToRexConverterImpl.convertCall(SqlNodeToRexConverterImpl.java:52)
~[optiq-core-0.7-20140513.013236-5.jar:na]
at
org.eigenbase.sql2rel.SqlToRelConverter$Blackboard.visit(SqlToRelConverter.java:4210)
~[optiq-core-0.7-20140513.013236-5.jar:na]
at
org.eigenbase.sql2rel.SqlToRelConverter$Blackboard.visit(SqlToRelConverter.java:3611)
~[optiq-core-0.7-20140513.013236-5.jar:na]
at org.eigenbase.sql.SqlCall.accept(SqlCall.java:133)
~[optiq-core-0.7-20140513.013236-5.jar:na]
at
org.eigenbase.sql2rel.SqlToRelConverter$Blackboard.convertExpression(SqlToRelConverter.java:4116)
~[optiq-core-0.7-20140513.013236-5.jar:na]
at
org.eigenbase.sql2rel.SqlToRelConverter$AggConverter.visit(SqlToRelConverter.java:4517)
~[optiq-core-0.7-20140513.013236-5.jar:na]
at
org.eigenbase.sql2rel.SqlToRelConverter$AggConverter.visit(SqlToRelConverter.java:4363)
~[optiq-core-0.7-20140513.013236-5.jar:na]
at org.eigenbase.sql.SqlCall.accept(SqlCall.java:133)
~[optiq-core-0.7-20140513.013236-5.jar:na]
at
org.eigenbase.sql2rel.SqlToRelConverter$AggConverter.visit(SqlToRelConverter.java:4473)
~[optiq-core-0.7-20140513.013236-5.jar:na]
at
org.eigenbase.sql2rel.SqlToRelConverter$AggConverter.visit(SqlToRelConverter.java:4363)
~[optiq-core-0.7-20140513.013236-5.jar:na]
at org.eigenbase.sql.SqlNodeList.accept(SqlNodeList.java:149) ~[optiq-core-0.7-20140513.013236-5.jar:na]
.....
Happens when we are done with the validation phase and are trying to
convert it to Rel. We hit this error when we are trying to infer the
return type of the 'substr' function, but the SqlOperator class
associated with this SqlCall is SqlUnresolvedFunction.
The problem seems to be that we are not invoking setOperator() on the
SqlCall associated with the 'substr' function, I notice that we are
calling setOperator() and replace the SqlUnresolvedFunction with the
DrillSqlOperator in the validation phase in SqlFunction.deriveType()
function (here
<https://github.com/julianhyde/optiq/blob/master/core/src/main/java/org/eigenbase/sql/SqlFunction.java#L290>).
Would appreciate any pointers on how to resolve this.
Thanks
Mehant