Search in sources :

Example 1 with GenMRUnionCtx

use of org.apache.hadoop.hive.ql.optimizer.GenMRProcContext.GenMRUnionCtx in project hive by apache.

the class GenMapRedUtils method initUnionPlan.

/*
   * It is a idempotent function to add various intermediate files as the source
   * for the union. The plan has already been created.
   */
public static void initUnionPlan(GenMRProcContext opProcCtx, UnionOperator currUnionOp, Task<? extends Serializable> currTask, boolean local) throws SemanticException {
    // can be traversed more than one
    if (currUnionOp != null) {
        GenMRUnionCtx uCtx = opProcCtx.getUnionTask(currUnionOp);
        assert uCtx != null;
        setUnionPlan(opProcCtx, local, currTask, uCtx, false);
    }
}
Also used : GenMRUnionCtx(org.apache.hadoop.hive.ql.optimizer.GenMRProcContext.GenMRUnionCtx)

Example 2 with GenMRUnionCtx

use of org.apache.hadoop.hive.ql.optimizer.GenMRProcContext.GenMRUnionCtx in project hive by apache.

the class GenMapRedUtils method joinUnionPlan.

/*
   * join current union task to old task
   */
public static void joinUnionPlan(GenMRProcContext opProcCtx, UnionOperator currUnionOp, Task<? extends Serializable> currentUnionTask, Task<? extends Serializable> existingTask, boolean local) throws SemanticException {
    assert currUnionOp != null;
    GenMRUnionCtx uCtx = opProcCtx.getUnionTask(currUnionOp);
    assert uCtx != null;
    setUnionPlan(opProcCtx, local, existingTask, uCtx, true);
    List<Task<? extends Serializable>> parTasks = null;
    if (opProcCtx.getRootTasks().contains(currentUnionTask)) {
        opProcCtx.getRootTasks().remove(currentUnionTask);
        if (!opProcCtx.getRootTasks().contains(existingTask) && (existingTask.getParentTasks() == null || existingTask.getParentTasks().isEmpty())) {
            opProcCtx.getRootTasks().add(existingTask);
        }
    }
    if ((currentUnionTask != null) && (currentUnionTask.getParentTasks() != null) && !currentUnionTask.getParentTasks().isEmpty()) {
        parTasks = new ArrayList<Task<? extends Serializable>>();
        parTasks.addAll(currentUnionTask.getParentTasks());
        Object[] parTaskArr = parTasks.toArray();
        for (Object parTask : parTaskArr) {
            ((Task<? extends Serializable>) parTask).removeDependentTask(currentUnionTask);
        }
    }
    if ((currentUnionTask != null) && (parTasks != null)) {
        for (Task<? extends Serializable> parTask : parTasks) {
            parTask.addDependentTask(existingTask);
            if (opProcCtx.getRootTasks().contains(existingTask)) {
                opProcCtx.getRootTasks().remove(existingTask);
            }
        }
    }
    opProcCtx.setCurrTask(existingTask);
}
Also used : SparkTask(org.apache.hadoop.hive.ql.exec.spark.SparkTask) ConditionalTask(org.apache.hadoop.hive.ql.exec.ConditionalTask) Task(org.apache.hadoop.hive.ql.exec.Task) MoveTask(org.apache.hadoop.hive.ql.exec.MoveTask) MapRedTask(org.apache.hadoop.hive.ql.exec.mr.MapRedTask) DependencyCollectionTask(org.apache.hadoop.hive.ql.exec.DependencyCollectionTask) Serializable(java.io.Serializable) GenMRUnionCtx(org.apache.hadoop.hive.ql.optimizer.GenMRProcContext.GenMRUnionCtx)

Example 3 with GenMRUnionCtx

use of org.apache.hadoop.hive.ql.optimizer.GenMRProcContext.GenMRUnionCtx in project hive by apache.

the class GenMapRedUtils method joinUnionPlan.

/*
   * join current union task to old task
   */
public static void joinUnionPlan(GenMRProcContext opProcCtx, UnionOperator currUnionOp, Task<?> currentUnionTask, Task<?> existingTask, boolean local) throws SemanticException {
    assert currUnionOp != null;
    GenMRUnionCtx uCtx = opProcCtx.getUnionTask(currUnionOp);
    assert uCtx != null;
    setUnionPlan(opProcCtx, local, existingTask, uCtx, true);
    List<Task<?>> parTasks = null;
    if (opProcCtx.getRootTasks().contains(currentUnionTask)) {
        opProcCtx.getRootTasks().remove(currentUnionTask);
        if (!opProcCtx.getRootTasks().contains(existingTask) && (existingTask.getParentTasks() == null || existingTask.getParentTasks().isEmpty())) {
            opProcCtx.getRootTasks().add(existingTask);
        }
    }
    if ((currentUnionTask != null) && (currentUnionTask.getParentTasks() != null) && !currentUnionTask.getParentTasks().isEmpty()) {
        parTasks = new ArrayList<Task<?>>();
        parTasks.addAll(currentUnionTask.getParentTasks());
        Object[] parTaskArr = parTasks.toArray();
        for (Object parTask : parTaskArr) {
            ((Task<?>) parTask).removeDependentTask(currentUnionTask);
        }
    }
    if ((currentUnionTask != null) && (parTasks != null)) {
        for (Task<?> parTask : parTasks) {
            parTask.addDependentTask(existingTask);
            if (opProcCtx.getRootTasks().contains(existingTask)) {
                opProcCtx.getRootTasks().remove(existingTask);
            }
        }
    }
    opProcCtx.setCurrTask(existingTask);
}
Also used : SparkTask(org.apache.hadoop.hive.ql.exec.spark.SparkTask) ConditionalTask(org.apache.hadoop.hive.ql.exec.ConditionalTask) TezTask(org.apache.hadoop.hive.ql.exec.tez.TezTask) Task(org.apache.hadoop.hive.ql.exec.Task) MoveTask(org.apache.hadoop.hive.ql.exec.MoveTask) MapRedTask(org.apache.hadoop.hive.ql.exec.mr.MapRedTask) DependencyCollectionTask(org.apache.hadoop.hive.ql.exec.DependencyCollectionTask) GenMRUnionCtx(org.apache.hadoop.hive.ql.optimizer.GenMRProcContext.GenMRUnionCtx)

Example 4 with GenMRUnionCtx

use of org.apache.hadoop.hive.ql.optimizer.GenMRProcContext.GenMRUnionCtx in project hive by apache.

the class GenMapRedUtils method initUnionPlan.

/*
   * It is a idempotent function to add various intermediate files as the source
   * for the union. The plan has already been created.
   */
public static void initUnionPlan(GenMRProcContext opProcCtx, UnionOperator currUnionOp, Task<?> currTask, boolean local) throws SemanticException {
    // can be traversed more than one
    if (currUnionOp != null) {
        GenMRUnionCtx uCtx = opProcCtx.getUnionTask(currUnionOp);
        assert uCtx != null;
        setUnionPlan(opProcCtx, local, currTask, uCtx, false);
    }
}
Also used : GenMRUnionCtx(org.apache.hadoop.hive.ql.optimizer.GenMRProcContext.GenMRUnionCtx)

Example 5 with GenMRUnionCtx

use of org.apache.hadoop.hive.ql.optimizer.GenMRProcContext.GenMRUnionCtx in project hive by apache.

the class GenMRUnion1 method process.

/**
 * Union Operator encountered . Currently, the algorithm is pretty simple: If
 * all the sub-queries are map-only, don't do anything. Otherwise, insert a
 * FileSink on top of all the sub-queries.
 *
 * This can be optimized later on.
 *
 * @param nd
 *          the file sink operator encountered
 * @param opProcCtx
 *          context
 */
@Override
public Object process(Node nd, Stack<Node> stack, NodeProcessorCtx opProcCtx, Object... nodeOutputs) throws SemanticException {
    UnionOperator union = (UnionOperator) nd;
    GenMRProcContext ctx = (GenMRProcContext) opProcCtx;
    ParseContext parseCtx = ctx.getParseCtx();
    UnionProcContext uCtx = parseCtx.getUCtx();
    // Map-only subqueries can be optimized in future to not write to a file in
    // future
    Map<Operator<? extends OperatorDesc>, GenMapRedCtx> mapCurrCtx = ctx.getMapCurrCtx();
    if (union.getConf().isAllInputsInSameReducer()) {
        // All inputs of this UnionOperator are in the same Reducer.
        // We do not need to break the operator tree.
        mapCurrCtx.put((Operator<? extends OperatorDesc>) nd, new GenMapRedCtx(ctx.getCurrTask(), ctx.getCurrAliasId()));
        return null;
    }
    UnionParseContext uPrsCtx = uCtx.getUnionParseContext(union);
    ctx.setCurrUnionOp(union);
    // map-reduce job
    if (uPrsCtx.allMapOnlySubQ()) {
        return processMapOnlyUnion(union, stack, ctx, uCtx);
    }
    assert uPrsCtx != null;
    Task<?> currTask = ctx.getCurrTask();
    int pos = UnionProcFactory.getPositionParent(union, stack);
    Task<?> uTask = null;
    MapredWork uPlan = null;
    // union is encountered for the first time
    GenMRUnionCtx uCtxTask = ctx.getUnionTask(union);
    if (uCtxTask == null) {
        uPlan = GenMapRedUtils.getMapRedWork(parseCtx);
        uTask = TaskFactory.get(uPlan);
        uCtxTask = new GenMRUnionCtx(uTask);
        ctx.setUnionTask(union, uCtxTask);
    } else {
        uTask = uCtxTask.getUTask();
    }
    // Copy into the current union task plan if
    if (uPrsCtx.getMapOnlySubq(pos) && uPrsCtx.getRootTask(pos)) {
        processSubQueryUnionMerge(ctx, uCtxTask, union, stack);
        if (ctx.getRootTasks().contains(currTask)) {
            ctx.getRootTasks().remove(currTask);
        }
    } else // If it a map-reduce job, create a temporary file
    {
        // is the current task a root task
        if (shouldBeRootTask(currTask) && !ctx.getRootTasks().contains(currTask) && (currTask.getParentTasks() == null || currTask.getParentTasks().isEmpty())) {
            ctx.getRootTasks().add(currTask);
        }
        processSubQueryUnionCreateIntermediate(union.getParentOperators().get(pos), union, uTask, ctx, uCtxTask);
        // the currAliasId and CurrTopOp is not valid any more
        ctx.setCurrAliasId(null);
        ctx.setCurrTopOp(null);
        ctx.getOpTaskMap().put(null, uTask);
    }
    ctx.setCurrTask(uTask);
    mapCurrCtx.put((Operator<? extends OperatorDesc>) nd, new GenMapRedCtx(ctx.getCurrTask(), null));
    return true;
}
Also used : TableScanOperator(org.apache.hadoop.hive.ql.exec.TableScanOperator) UnionOperator(org.apache.hadoop.hive.ql.exec.UnionOperator) Operator(org.apache.hadoop.hive.ql.exec.Operator) UnionProcContext(org.apache.hadoop.hive.ql.optimizer.unionproc.UnionProcContext) UnionParseContext(org.apache.hadoop.hive.ql.optimizer.unionproc.UnionProcContext.UnionParseContext) GenMRUnionCtx(org.apache.hadoop.hive.ql.optimizer.GenMRProcContext.GenMRUnionCtx) UnionOperator(org.apache.hadoop.hive.ql.exec.UnionOperator) MapredWork(org.apache.hadoop.hive.ql.plan.MapredWork) ParseContext(org.apache.hadoop.hive.ql.parse.ParseContext) UnionParseContext(org.apache.hadoop.hive.ql.optimizer.unionproc.UnionProcContext.UnionParseContext) GenMapRedCtx(org.apache.hadoop.hive.ql.optimizer.GenMRProcContext.GenMapRedCtx) OperatorDesc(org.apache.hadoop.hive.ql.plan.OperatorDesc)

Aggregations

GenMRUnionCtx (org.apache.hadoop.hive.ql.optimizer.GenMRProcContext.GenMRUnionCtx)6 ConditionalTask (org.apache.hadoop.hive.ql.exec.ConditionalTask)2 DependencyCollectionTask (org.apache.hadoop.hive.ql.exec.DependencyCollectionTask)2 MoveTask (org.apache.hadoop.hive.ql.exec.MoveTask)2 Task (org.apache.hadoop.hive.ql.exec.Task)2 MapRedTask (org.apache.hadoop.hive.ql.exec.mr.MapRedTask)2 SparkTask (org.apache.hadoop.hive.ql.exec.spark.SparkTask)2 GenMapRedCtx (org.apache.hadoop.hive.ql.optimizer.GenMRProcContext.GenMapRedCtx)2 UnionParseContext (org.apache.hadoop.hive.ql.optimizer.unionproc.UnionProcContext.UnionParseContext)2 Serializable (java.io.Serializable)1 Operator (org.apache.hadoop.hive.ql.exec.Operator)1 TableScanOperator (org.apache.hadoop.hive.ql.exec.TableScanOperator)1 UnionOperator (org.apache.hadoop.hive.ql.exec.UnionOperator)1 TezTask (org.apache.hadoop.hive.ql.exec.tez.TezTask)1 UnionProcContext (org.apache.hadoop.hive.ql.optimizer.unionproc.UnionProcContext)1 ParseContext (org.apache.hadoop.hive.ql.parse.ParseContext)1 MapredWork (org.apache.hadoop.hive.ql.plan.MapredWork)1 OperatorDesc (org.apache.hadoop.hive.ql.plan.OperatorDesc)1