[TRAFODION-2400] wrong results for passthru cols Wrong results were returned for passthru columns in TMUDFs when we had equal predicates on the source table. This was related to VEG rewrite, where the rewritten expression had the wrong type.
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/50972910 Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/50972910 Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/50972910 Branch: refs/heads/master Commit: 5097291082615ac4f05b302e3cc5478fb7f3dfb7 Parents: 2faae45 Author: Hans Zeller <[email protected]> Authored: Tue Dec 20 22:40:55 2016 +0000 Committer: Hans Zeller <[email protected]> Committed: Tue Dec 20 22:40:55 2016 +0000 ---------------------------------------------------------------------- core/sql/generator/GenPreCode.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/50972910/core/sql/generator/GenPreCode.cpp ---------------------------------------------------------------------- diff --git a/core/sql/generator/GenPreCode.cpp b/core/sql/generator/GenPreCode.cpp index 10f9bf5..45e2a2d 100644 --- a/core/sql/generator/GenPreCode.cpp +++ b/core/sql/generator/GenPreCode.cpp @@ -10806,9 +10806,28 @@ RelExpr * PhysicalTableMappingUDF::preCodeGen(Generator * generator, for(Int32 i = 0; i < getArity(); i++) { - getChildInfo(i)->getOutputIds().replaceVEGExpressions( + ValueIdList &childOutputs(getChildInfo(i)->getOutputIds()); + ValueIdList origChildOutputs(childOutputs); + + childOutputs.replaceVEGExpressions( availableValues, getGroupAttr()->getCharacteristicInputs()); + + for (CollIndex j=0; j<childOutputs.entries(); j++) + if (NOT(childOutputs[j].getType() == origChildOutputs[j].getType())) + { + // VEG rewrite changed the type. + // Since we recorded the original type of the input + // column and exposed this type to the UDF writer, don't + // change the type now. Instead, add a cast back to the + // original type. + ItemExpr *castToOrigType = new(CmpCommon::statementHeap()) + Cast(childOutputs[j].getItemExpr(), + origChildOutputs[j].getType().newCopy()); + + castToOrigType->synthTypeAndValueId(); + childOutputs[j] = castToOrigType->getValueId(); + } } planInfo_ = getPhysicalProperty()->getUDRPlanInfo();
