We have a UDAF that returns “Number” as the result type. We use 
RexToLixTranslator to generate java code [1]. In the generated code, the value 
of the field with Number type is cast to Object[] and the compilation fails.

When I trace the flow, I see that in PhysTypeImpl the field classes are 
determined via javaRowClass method [2].  The type for the Number field turns 
out to be “BasicSqlType(Other)” and the javaRowClass [3] returns a “Object[]”. 
Somewhere down the line the field value is then cast to “Object[]” in the 
generate code [4].

Just wondering why Object[] is returned (should unknown fields be mapped to 
Object instead?). Also is it possible to write UDAFs that return super types 
like Number (so that it can work for any sub type) but the return type does not 
directly map to SQL types?

Thanks,
Arun

[1] 
https://github.com/apache/storm/blob/master/external/sql/storm-sql-core/src/jvm/org/apache/storm/sql/compiler/RexNodeToBlockStatementCompiler.java#L73
[2] 
https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/adapter/enumerable/PhysTypeImpl.java#L75
[3] 
https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumUtils.java#L96
[4] 
https://gist.github.com/arunmahadevan/35809494467d5636e31c0031f81d9aa7#file-test-java-L149


Reply via email to