Index: ql/src/java/org/apache/hadoop/hive/ql/exec/MapOperator.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/exec/MapOperator.java (revision 1167289) +++ ql/src/java/org/apache/hadoop/hive/ql/exec/MapOperator.java (working copy) @@ -87,6 +87,8 @@ private Map, java.util.ArrayList> operatorToPaths; private final java.util.ArrayList childrenPaths = new ArrayList(); + private final Map, MapOpCtx> childrenOpToOpCtxMap = + new HashMap, MapOpCtx>(); private ArrayList> extraChildrenToClose = null; @@ -123,7 +125,10 @@ @Override public int hashCode() { - return (op == null) ? 0 : op.hashCode(); + int ret = (path == null) ? 0 : path.hashCode(); + ret += (alias == null) ? 0 : alias.hashCode(); + ret += (op == null) ? 0 : op.hashCode(); + return ret; } public Operator getOp() { @@ -358,7 +363,6 @@ statsMap.put(Counter.DESERIALIZE_ERRORS, deserialize_error_count); try { - boolean done = false; for (String onefile : conf.getPathToAliases().keySet()) { MapOpCtx opCtx = initObjectInspector(conf, hconf, onefile); Path onepath = new Path(new Path(onefile).toUri().getPath()); @@ -382,11 +386,11 @@ if (!onepath.toUri().relativize(fpath.toUri()).equals(fpath.toUri())) { children.add(op); childrenPaths.add(onefile); + childrenOpToOpCtxMap.put(op, opCtx); LOG.info("dump " + op.getName() + " " + opCtxMap.get(inp).getRowObjectInspector().getTypeName()); } setInspectorInput(inp); - done = true; } } @@ -410,8 +414,20 @@ // set that parent initialization is done and call initialize on children state = State.INIT; List> children = getChildOperators(); - Path fpath = new Path((new Path(HiveConf.getVar(hconf, - HiveConf.ConfVars.HADOOPMAPFILENAME))).toUri().getPath()); + + for (Entry, MapOpCtx> entry : childrenOpToOpCtxMap + .entrySet()) { + Operator child = entry.getKey(); + MapOpCtx mapOpCtx = entry.getValue(); + // Add alias, table name, and partitions to hadoop conf so that their + // children will + // inherit these + HiveConf.setVar(hconf, HiveConf.ConfVars.HIVETABLENAME, + mapOpCtx.tableName); + HiveConf.setVar(hconf, HiveConf.ConfVars.HIVEPARTITIONNAME, + mapOpCtx.partName); + child.initialize(hconf, new ObjectInspector[] {mapOpCtx.getRowObjectInspector()}); + } for (Entry entry : opCtxMap.entrySet()) { // Add alias, table name, and partitions to hadoop conf so that their @@ -430,20 +446,6 @@ extraChildrenToClose = new ArrayList>(); } extraChildrenToClose.add(op); - } - - // multiple input paths may corresponding the same operator (tree). The - // below logic is to avoid initialize one operator multiple times if there - // is one input path in this mapper's input paths. - boolean shouldInit = true; - List paths = operatorToPaths.get(op); - for (String path : paths) { - if (childrenPaths.contains(path) && !path.equals(input.path)) { - shouldInit = false; - break; - } - } - if (shouldInit) { op.initialize(hconf, new ObjectInspector[] {entry.getValue().getRowObjectInspector()}); } }