private Operator genConstraintsPlan(String dest, QB qb, Operator input) throws SemanticException {
    if (deleting(dest)) {
      // for DELETE statements NOT NULL constraint need not be checked
      return input;
    }

      if (updating(dest) && isCBOExecuted() && this.ctx.getOperation() != Context.Operation.MERGE) {
      // for UPDATE statements CBO already added and pushed down the constraints
      return input;
    }

    //MERGE statements could have inserted a cardinality violation branch, we need to avoid that
    if (mergeCardinalityViolationBranch(input)) {
      return input;
    }

    // if this is an insert into statement we might need to add constraint check
    assert (input.getParentOperators().size() == 1);
    RowResolver inputRR = opParseCtx.get(input).getRowResolver();
    Table targetTable = getTargetTable(qb, dest);
    ExprNodeDesc combinedConstraintExpr =
        ExprNodeTypeCheck.genConstraintsExpr(conf, targetTable, updating(dest), inputRR);

    if (combinedConstraintExpr != null) {
      return putOpInsertMap(OperatorFactory.getAndMakeChild(
          new FilterDesc(combinedConstraintExpr, false), new RowSchema(
              inputRR.getColumnInfos()), input), inputRR);
    }
    return input;
  }
@param totalFiles
         the totalFiles to set
ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java