diff --git ql/src/java/org/apache/hadoop/hive/ql/optimizer/GenMRFileSink1.java ql/src/java/org/apache/hadoop/hive/ql/optimizer/GenMRFileSink1.java index d7a83f775a..306037f3c2 100644 --- ql/src/java/org/apache/hadoop/hive/ql/optimizer/GenMRFileSink1.java +++ ql/src/java/org/apache/hadoop/hive/ql/optimizer/GenMRFileSink1.java @@ -71,16 +71,23 @@ public Object process(Node nd, Stack stack, NodeProcessorCtx opProcCtx, boolean chDir = false; // we should look take the parent of fsOp's task as the current task. FileSinkOperator fsOp = (FileSinkOperator) nd; - Map, GenMapRedCtx> mapCurrCtx = ctx - .getMapCurrCtx(); - GenMapRedCtx mapredCtx = mapCurrCtx.get(fsOp.getParentOperators().get(0)); - Task currTask = mapredCtx.getCurrTask(); - - ctx.setCurrTask(currTask); - ctx.addRootIfPossible(currTask); boolean isInsertTable = // is INSERT OVERWRITE TABLE GenMapRedUtils.isInsertInto(parseCtx, fsOp); + + Task currTask; + if (isInsertTable) { + Map, GenMapRedCtx> mapCurrCtx = ctx + .getMapCurrCtx(); + GenMapRedCtx mapredCtx = mapCurrCtx.get(fsOp.getParentOperators().get(0)); + currTask = mapredCtx.getCurrTask(); + + ctx.setCurrTask(currTask); + } else { + currTask = ctx.getCurrTask(); + } + + ctx.addRootIfPossible(currTask); HiveConf hconf = parseCtx.getConf(); // Mark this task as a final map reduce task (ignoring the optional merge task)