Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hive.ql.exec;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.ql.exec.mr.MapRedTask;
import org.apache.hadoop.hive.ql.exec.mr.MapredLocalTask;
import org.apache.hadoop.hive.ql.exec.repl.ReplDumpTask;
import org.apache.hadoop.hive.ql.exec.repl.ReplDumpWork;
import org.apache.hadoop.hive.ql.exec.repl.ReplStateLogTask;
import org.apache.hadoop.hive.ql.exec.repl.ReplStateLogWork;
import org.apache.hadoop.hive.ql.exec.repl.bootstrap.ReplLoadTask;
import org.apache.hadoop.hive.ql.exec.repl.bootstrap.ReplLoadWork;
import org.apache.hadoop.hive.ql.exec.spark.SparkTask;
import org.apache.hadoop.hive.ql.exec.tez.TezTask;
import org.apache.hadoop.hive.ql.io.merge.MergeFileTask;
import org.apache.hadoop.hive.ql.io.merge.MergeFileWork;
import org.apache.hadoop.hive.ql.plan.ColumnStatsUpdateWork;
import org.apache.hadoop.hive.ql.plan.StatsWork;
import org.apache.hadoop.hive.ql.plan.ConditionalWork;
import org.apache.hadoop.hive.ql.plan.CopyWork;
import org.apache.hadoop.hive.ql.plan.DDLWork;
import org.apache.hadoop.hive.ql.plan.DependencyCollectionWork;
import org.apache.hadoop.hive.ql.plan.ExplainSQRewriteWork;
import org.apache.hadoop.hive.ql.plan.ExplainWork;
import org.apache.hadoop.hive.ql.plan.ExportWork;
import org.apache.hadoop.hive.ql.plan.FetchWork;
import org.apache.hadoop.hive.ql.plan.FunctionWork;
import org.apache.hadoop.hive.ql.plan.MapredLocalWork;
import org.apache.hadoop.hive.ql.plan.MapredWork;
import org.apache.hadoop.hive.ql.plan.MoveWork;
import org.apache.hadoop.hive.ql.plan.ReplCopyWork;
import org.apache.hadoop.hive.ql.plan.ReplTxnWork;
import org.apache.hadoop.hive.ql.plan.SparkWork;
import org.apache.hadoop.hive.ql.plan.TezWork;
import com.facebook.presto.hive.$internal.com.google.common.annotations.VisibleForTesting;
/**
* TaskFactory implementation.
**/
public final class TaskFactory {
/**
* taskTuple.
*
* @param
*/
public static final class TaskTuple {
public Class workClass;
public Class extends Task> taskClass;
public TaskTuple(Class workClass, Class extends Task> taskClass) {
this.workClass = workClass;
this.taskClass = taskClass;
}
}
public static ArrayList> taskvec;
static {
taskvec = new ArrayList>();
taskvec.add(new TaskTuple(MoveWork.class, MoveTask.class));
taskvec.add(new TaskTuple(FetchWork.class, FetchTask.class));
taskvec.add(new TaskTuple(CopyWork.class, CopyTask.class));
taskvec.add(new TaskTuple(ReplCopyWork.class, ReplCopyTask.class));
taskvec.add(new TaskTuple(DDLWork.class, DDLTask.class));
taskvec.add(new TaskTuple(
MaterializedViewDesc.class,
MaterializedViewTask.class));
taskvec.add(new TaskTuple(FunctionWork.class,
FunctionTask.class));
taskvec
.add(new TaskTuple(ExplainWork.class, ExplainTask.class));
taskvec
.add(new TaskTuple(ExplainSQRewriteWork.class, ExplainSQRewriteTask.class));
taskvec.add(new TaskTuple(ConditionalWork.class,
ConditionalTask.class));
taskvec.add(new TaskTuple(MapredWork.class,
MapRedTask.class));
taskvec.add(new TaskTuple(MapredLocalWork.class,
MapredLocalTask.class));
taskvec.add(new TaskTuple(StatsWork.class, StatsTask.class));
taskvec.add(new TaskTuple(ColumnStatsUpdateWork.class, ColumnStatsUpdateTask.class));
taskvec.add(new TaskTuple(MergeFileWork.class,
MergeFileTask.class));
taskvec.add(new TaskTuple(DependencyCollectionWork.class,
DependencyCollectionTask.class));
taskvec.add(new TaskTuple(TezWork.class, TezTask.class));
taskvec.add(new TaskTuple(SparkWork.class, SparkTask.class));
taskvec.add(new TaskTuple<>(ReplDumpWork.class, ReplDumpTask.class));
taskvec.add(new TaskTuple<>(ReplLoadWork.class, ReplLoadTask.class));
taskvec.add(new TaskTuple<>(ReplStateLogWork.class, ReplStateLogTask.class));
taskvec.add(new TaskTuple(ExportWork.class, ExportTask.class));
taskvec.add(new TaskTuple(ReplTxnWork.class, ReplTxnTask.class));
}
private static ThreadLocal tid = new ThreadLocal() {
@Override
protected Integer initialValue() {
return Integer.valueOf(0);
}
};
public static int getAndIncrementId() {
int curValue = tid.get().intValue();
tid.set(new Integer(curValue + 1));
return curValue;
}
public static void resetId() {
tid.set(Integer.valueOf(0));
}
@SuppressWarnings("unchecked")
@VisibleForTesting
static Task get(Class workClass) {
for (TaskTuple extends Serializable> t : taskvec) {
if (t.workClass == workClass) {
try {
Task ret = (Task) t.taskClass.newInstance();
ret.setId("Stage-" + Integer.toString(getAndIncrementId()));
return ret;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
throw new RuntimeException("No task for work class " + workClass.getName());
}
public static Task get(T work, HiveConf conf) {
@SuppressWarnings("unchecked")
Task ret = get((Class) work.getClass());
ret.setWork(work);
if (null != conf) {
ret.setConf(conf);
}
return ret;
}
public static Task get(T work) {
return get(work, null);
}
@SafeVarargs
public static Task getAndMakeChild(T work,
HiveConf conf, Task extends Serializable>... tasklist) {
Task ret = get(work);
if (tasklist.length == 0) {
return (ret);
}
makeChild(ret, tasklist);
return (ret);
}
@SafeVarargs
public static void makeChild(Task> ret,
Task extends Serializable>... tasklist) {
// Add the new task as child of each of the passed in tasks
for (Task extends Serializable> tsk : tasklist) {
List> children = tsk.getChildTasks();
if (children == null) {
children = new ArrayList>();
}
children.add(ret);
tsk.setChildTasks(children);
}
}
private TaskFactory() {
// prevent instantiation
}
}