Paul Rogers created DRILL-7502:
----------------------------------
Summary: Incorrect/invalid codegen for typeof() with UNION
Key: DRILL-7502
URL: https://issues.apache.org/jira/browse/DRILL-7502
Project: Apache Drill
Issue Type: Bug
Reporter: Paul Rogers
The {{typeof()}} function is defined as follows:
{code:java}
@FunctionTemplate(names = {"typeOf"},
scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = NullHandling.INTERNAL)
public static class GetType implements DrillSimpleFunc {
@Param
FieldReader input;
@Output
VarCharHolder out;
@Inject
DrillBuf buf;
@Override
public void setup() {}
@Override
public void eval() {
String typeName = input.getTypeString();
byte[] type = typeName.getBytes();
buf = buf.reallocIfNeeded(type.length);
buf.setBytes(0, type);
out.buffer = buf;
out.start = 0;
out.end = type.length;
}
}
{code}
Note that the {{input}} field is defined as {{FieldReader}} which has a method
called {{getTypeString()}}. As a result, the code works fine in all existing
tests in {{TestTypeFns}}.
I tried to add a function to use {{typeof()}} on a column of type {{UNION}}.
When I did, the query failed with a compile error in generated code:
{noformat}
SYSTEM ERROR: CompileException: Line 42, Column 43:
A method named "getTypeString" is not declared in any enclosing class nor any
supertype, nor through a static import
{noformat}
The stack trace shows the generated code; Note that the type of {{input}}
changes from a reader to a holder, causing code to be invalid:
{code:java}
public class ProjectorGen0 {
DrillBuf work0;
UnionVector vv1;
VarCharVector vv6;
DrillBuf work9;
VarCharVector vv11;
DrillBuf work14;
VarCharVector vv16;
public void doEval(int inIndex, int outIndex)
throws SchemaChangeException
{
{
UnionHolder out4 = new UnionHolder();
{
out4 .isSet = vv1 .getAccessor().isSet((inIndex));
if (out4 .isSet == 1) {
vv1 .getAccessor().get((inIndex), out4);
}
}
//---- start of eval portion of typeOf function. ----//
VarCharHolder out5 = new VarCharHolder();
{
final VarCharHolder out = new VarCharHolder();
UnionHolder input = out4;
DrillBuf buf = work0;
UnionFunctions$GetType_eval:
{
String typeName = input.getTypeString();
byte[] type = typeName.getBytes();
buf = buf.reallocIfNeeded(type.length);
buf.setBytes(0, type);
out.buffer = buf;
out.start = 0;
out.end = type.length;
}
{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)