Repository: trafodion Updated Branches: refs/heads/master 7984e6901 -> 51cdb91d7
[TRAFODION-3018] Fix issue with UPPER on an UPSHIFT column Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/1d248e11 Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/1d248e11 Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/1d248e11 Branch: refs/heads/master Commit: 1d248e116f17819de24a2dd14c732238432ce379 Parents: 659e8ec Author: Dave Birdsall <dbirds...@apache.org> Authored: Wed Apr 4 23:08:52 2018 +0000 Committer: Dave Birdsall <dbirds...@apache.org> Committed: Wed Apr 4 23:08:52 2018 +0000 ---------------------------------------------------------------------- core/sql/optimizer/BindItemExpr.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafodion/blob/1d248e11/core/sql/optimizer/BindItemExpr.cpp ---------------------------------------------------------------------- diff --git a/core/sql/optimizer/BindItemExpr.cpp b/core/sql/optimizer/BindItemExpr.cpp index 3c81218..4ed4b9e 100644 --- a/core/sql/optimizer/BindItemExpr.cpp +++ b/core/sql/optimizer/BindItemExpr.cpp @@ -3494,9 +3494,25 @@ ItemExpr *Upper::bindNode(BindWA *bindWA) if (bindWA->errStatus()) return this; // If our child is already upshifted, we can remove this Upper from the tree. + // BuiltinFunction::bindNode might have added a Cast node underneath Upper + // with the MATCH_CHILD_TYPE flag set. We need to remove it too + // else we can get into trouble with unmapped ValueIds at code generation + // time. (e.g. If a hash join equi-join predicate refers to the Cast, the + // Cast expression will be in the join child's characteristic outputs but + // when we generate the join predicate we skip the Cast looking for the + // underlying column. That might not be in the join child's characteristic + // outputs.) if (boundExpr == this) { CMPASSERT(getArity() == 1); ValueId opVid = child(0)->getValueId(); + ItemExpr * child0ie = opVid.getItemExpr(); + if (child0ie->getOperatorType() == ITM_CAST) + { + Cast * child0ieCast = (Cast *)child0ie; + if (child0ieCast->matchChildType()) + // we need to remove the Cast too + opVid = child0ieCast->child(0)->getValueId(); + } const CharType &ct = (const CharType &)opVid.getType(); CMPASSERT(ct.getTypeQualifier() == NA_CHARACTER_TYPE); if (ct.isUpshifted()) setValueId(opVid);