private void setWriteIdForSurrogateKeys(LoadTableDesc ltd, Operator input) {
    if (ltd == null) {
      return;
    }

    Map<String, ExprNodeDesc> columnExprMap = input.getConf().getColumnExprMap();
    if (columnExprMap != null) {
      for (ExprNodeDesc desc : columnExprMap.values()) {
        if (desc instanceof ExprNodeGenericFuncDesc) {
          GenericUDF genericUDF = ((ExprNodeGenericFuncDesc)desc).getGenericUDF();
          if (genericUDF instanceof GenericUDFSurrogateKey) {
            ((GenericUDFSurrogateKey)genericUDF).setWriteId(ltd.getWriteId());
          }
        }
      }
    }

    for (Operator<? extends OperatorDesc> parent : (List<Operator<? extends OperatorDesc>>)input.getParentOperators()) {
      setWriteIdForSurrogateKeys(ltd, parent);
    }
  }
We will directly insert to the final destination in the following cases:
1. Non native table
2. Micro-managed (insert only table)
3. Full ACID table and operation type is INSERT
ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java