Program: 13344
Project: 13344
Buggy source:
/** 
 * If a primary_key equals a constant value in the given node, and also is defined as the routing key, write the value to the   {@link ParsedStatement} and return true.The  {@link org.cratedb.action.sql.TransportSQLAction} can then make decisions usingthis values if e.g. a  {@link org.elasticsearch.action.get.GetRequest} should be usedinstead of a  {@link org.elasticsearch.action.search.SearchRequest}.
 * @param stmt
 * @param node
 * @return
 * @throws StandardException
 */
private Boolean checkSinglePrimaryAndRouting(ParsedStatement stmt,ValueNode node) throws StandardException {
  List<String> primaryKeys=tableContext.primaryKeys();
  if (primaryKeys.isEmpty()) {
    primaryKeys.add("String_Node_Str");
  }
  if (node instanceof BinaryRelationalOperatorNode) {
    ValueNode leftOperand=((BinaryRelationalOperatorNode)node).getLeftOperand();
    ValueNode rightOperand=((BinaryRelationalOperatorNode)node).getRightOperand();
    Object value=null;
    if (leftOperand instanceof ColumnReference) {
      if (tableContext.isRouting(leftOperand.getColumnName()) && primaryKeys.contains(leftOperand.getColumnName())) {
        value=stmt.visitor().evaluateValueNode(tableContext,leftOperand.getColumnName(),rightOperand);
      }
    }
    if (rightOperand instanceof ColumnReference) {
      if (tableContext.isRouting(rightOperand.getColumnName()) && primaryKeys.contains(rightOperand.getColumnName())) {
        value=stmt.visitor().evaluateValueNode(tableContext,rightOperand.getColumnName(),leftOperand);
      }
    }
    if (value != null) {
      stmt.setPlannerResult(PRIMARY_KEY_VALUE,value.toString());
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
/** 
 * If a primary_key equals a constant value in the given node, and also is defined as the routing key, write the value to the   {@link ParsedStatement} and return true.The  {@link org.cratedb.action.sql.TransportSQLAction} can then make decisions usingthis values if e.g. a  {@link org.elasticsearch.action.get.GetRequest} should be usedinstead of a  {@link org.elasticsearch.action.search.SearchRequest}.
 * @param stmt
 * @param node
 * @return
 * @throws StandardException
 */
private Boolean checkSinglePrimaryAndRouting(ParsedStatement stmt,ValueNode node) throws StandardException {
  List<String> primaryKeys=tableContext.primaryKeys();
  if (primaryKeys.isEmpty()) {
    primaryKeys.add("String_Node_Str");
  }
  if (node instanceof BinaryRelationalOperatorNode && ((BinaryRelationalOperatorNode)node).getOperatorType() == XContentGenerator.SQLOperatorTypes.EQUALS) {
    ValueNode leftOperand=((BinaryRelationalOperatorNode)node).getLeftOperand();
    ValueNode rightOperand=((BinaryRelationalOperatorNode)node).getRightOperand();
    Object value=null;
    if (leftOperand instanceof ColumnReference) {
      if (tableContext.isRouting(leftOperand.getColumnName()) && primaryKeys.contains(leftOperand.getColumnName())) {
        value=stmt.visitor().evaluateValueNode(tableContext,leftOperand.getColumnName(),rightOperand);
      }
    }
    if (rightOperand instanceof ColumnReference) {
      if (tableContext.isRouting(rightOperand.getColumnName()) && primaryKeys.contains(rightOperand.getColumnName())) {
        value=stmt.visitor().evaluateValueNode(tableContext,rightOperand.getColumnName(),leftOperand);
      }
    }
    if (value != null) {
      stmt.setPlannerResult(PRIMARY_KEY_VALUE,value.toString());
      return true;
    }
  }
  return false;
}