Digest is suitable for telling whether two expressions (RexNodes) are
equivalent. And it makes a good key for hash-maps.

However if I may rule was looking for a particular pattern I wouldn't match
on digest. Instead of

RexNode rex;
if (!rex.getDigest().equalTo("+($0, 1)") {
  return;
}

I would write

RexNode rex;
switch (rex.getKind()) {
default:
  return; // not a match
case PLUS:
  switch (rex.getOperands().get(0).getKind()) {
  default:
    return; // not a match
  case LITERAL:
    RexLiteral literal = (RexLiteral) rex.getOperands().get(0);
    if (!1.equals(literal.getValue()) {
      return; // not a match
    }
    // fall through; we got a match
  }
}

(I'm using RexNode.getKind() here because it works for the common node
types. You can also use 'rex instanceof ...' and '((RexCall)
rex).getOperator() == SqlStdOperatorTable.MY_OPERATOR'.)

Julian


On Wed, Aug 13, 2014 at 6:54 AM, Ravi Nallappan <[email protected]>
wrote:

> Hi,
>
> Within onMatch() for ProjectRel, is it intended to use digest string (via
> toString) to lookup content of RexNode tree or its advisable to traverse
> through the nodes instead for the purpose?
>
> if (n instanceof RexCall && n.toString().compareTo("+(4, 2)") == 0) {...}
>
> Thanks & Regards,
> Ravi Nallappan
>

Reply via email to