Index: ql/src/java/org/apache/hadoop/hive/ql/optimizer/physical/CommonJoinResolver.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/optimizer/physical/CommonJoinResolver.java (revision 1452628) +++ ql/src/java/org/apache/hadoop/hive/ql/optimizer/physical/CommonJoinResolver.java (working copy) @@ -234,11 +234,8 @@ } // create map join task and set big table as bigTablePosition - private ObjectPair convertTaskToMapJoinTask(String xml, + private ObjectPair convertTaskToMapJoinTask(MapredWork newWork, int bigTablePosition) throws UnsupportedEncodingException, SemanticException { - // deep copy a new mapred work from xml - InputStream in = new ByteArrayInputStream(xml.getBytes("UTF-8")); - MapredWork newWork = Utilities.deserializeMapRedWork(in, physicalContext.getConf()); // create a mapred task for this work MapRedTask newTask = (MapRedTask) TaskFactory.get(newWork, physicalContext .getParseContext().getConf()); @@ -365,14 +362,12 @@ String bigTableAlias = null; currWork.setOpParseCtxMap(parseCtx.getOpParseCtx()); currWork.setJoinTree(joinTree); - String xml = currWork.toXML(); if (convertJoinMapJoin) { // create map join task and set big table as bigTablePosition - MapRedTask newTask = convertTaskToMapJoinTask(xml, bigTablePosition).getFirst(); - + // do this to currWork since we return newTask unconditionally from here + MapRedTask newTask = convertTaskToMapJoinTask(currWork, bigTablePosition).getFirst(); newTask.setTaskTag(Task.MAPJOIN_ONLY_NOBACKUP); - replaceTask(currTask, newTask, physicalContext); // Can this task be merged with the child task. This can happen if a big table is being // joined with multiple small tables on different keys @@ -388,14 +383,19 @@ long ThresholdOfSmallTblSizeSum = HiveConf.getLongVar(conf, HiveConf.ConfVars.HIVESMALLTABLESFILESIZE); + // Keep a copy of currWork, for the loop below + String xml = currWork.toXML(); for (int i = 0; i < numAliases; i++) { // this table cannot be big table if (!bigTableCandidates.contains(i)) { continue; } + // deep copy a clean mapred work from xml + InputStream in = new ByteArrayInputStream(xml.getBytes("UTF-8")); + MapredWork newWork = Utilities.deserializeMapRedWork(in, physicalContext.getConf()); // create map join task and set big table as i - ObjectPair newTaskAlias = convertTaskToMapJoinTask(xml, i); + ObjectPair newTaskAlias = convertTaskToMapJoinTask(newWork, i); MapRedTask newTask = newTaskAlias.getFirst(); bigTableAlias = newTaskAlias.getSecond();