PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/ql/src/test/org/apache/hadoop/hive/ql/exec/TestExecDriver.java

http://github.com/apache/hive
Java | 577 lines | 442 code | 95 blank | 40 comment | 18 complexity | e5b96f06959c85c161e14bcffbfc9908 MD5 | raw file
Possible License(s): Apache-2.0
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. package org.apache.hadoop.hive.ql.exec;
  19. import java.io.File;
  20. import java.io.FileInputStream;
  21. import java.util.ArrayList;
  22. import java.util.LinkedList;
  23. import java.util.List;
  24. import org.apache.hadoop.hive.metastore.Warehouse;
  25. import org.apache.hadoop.hive.ql.util.NullOrdering;
  26. import org.slf4j.Logger;
  27. import org.slf4j.LoggerFactory;
  28. import org.apache.hadoop.fs.FSDataInputStream;
  29. import org.apache.hadoop.fs.FileSystem;
  30. import org.apache.hadoop.fs.Path;
  31. import org.apache.hadoop.hive.conf.HiveConf;
  32. import org.apache.hadoop.hive.ql.CompilationOpContext;
  33. import org.apache.hadoop.hive.ql.TaskQueue;
  34. import org.apache.hadoop.hive.ql.QueryState;
  35. import org.apache.hadoop.hive.ql.exec.mr.ExecDriver;
  36. import org.apache.hadoop.hive.ql.exec.mr.MapRedTask;
  37. import org.apache.hadoop.hive.ql.io.AcidUtils;
  38. import org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat;
  39. import org.apache.hadoop.hive.ql.metadata.Hive;
  40. import org.apache.hadoop.hive.ql.metadata.Table;
  41. import org.apache.hadoop.hive.ql.parse.SemanticException;
  42. import org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc;
  43. import org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc;
  44. import org.apache.hadoop.hive.ql.plan.ExprNodeDesc;
  45. import org.apache.hadoop.hive.ql.plan.ExprNodeFieldDesc;
  46. import org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc;
  47. import org.apache.hadoop.hive.ql.plan.FileSinkDesc;
  48. import org.apache.hadoop.hive.ql.plan.FilterDesc;
  49. import org.apache.hadoop.hive.ql.plan.LoadTableDesc.LoadFileType;
  50. import org.apache.hadoop.hive.ql.plan.MapredWork;
  51. import org.apache.hadoop.hive.ql.plan.PartitionDesc;
  52. import org.apache.hadoop.hive.ql.plan.PlanUtils;
  53. import org.apache.hadoop.hive.ql.plan.ReduceSinkDesc;
  54. import org.apache.hadoop.hive.ql.plan.ReduceWork;
  55. import org.apache.hadoop.hive.ql.plan.ScriptDesc;
  56. import org.apache.hadoop.hive.ql.plan.SelectDesc;
  57. import org.apache.hadoop.hive.ql.session.SessionState;
  58. import org.apache.hadoop.hive.serde.serdeConstants;
  59. import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
  60. import org.apache.hadoop.hive.shims.ShimLoader;
  61. import org.apache.hadoop.mapred.TextInputFormat;
  62. import static org.junit.Assert.assertEquals;
  63. import org.junit.Before;
  64. import org.junit.Test;
  65. /**
  66. * Mimics the actual query compiler in generating end to end plans and testing
  67. * them out.
  68. *
  69. */
  70. public class TestExecDriver {
  71. static QueryState queryState;
  72. static HiveConf conf;
  73. private static final String TMPDIR;
  74. private static final Logger LOG = LoggerFactory.getLogger(TestExecDriver.class);
  75. private static final Path tmppath;
  76. private static Hive db;
  77. private static FileSystem fs;
  78. private static CompilationOpContext ctx = null;
  79. static {
  80. try {
  81. queryState = new QueryState.Builder().withHiveConf(new HiveConf(ExecDriver.class)).build();
  82. conf = queryState.getConf();
  83. conf.setBoolVar(HiveConf.ConfVars.SUBMITVIACHILD, true);
  84. conf.setBoolVar(HiveConf.ConfVars.SUBMITLOCALTASKVIACHILD, true);
  85. conf.setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER,
  86. "org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory");
  87. SessionState.start(conf);
  88. TMPDIR = System.getProperty("test.tmp.dir");
  89. tmppath = new Path(TMPDIR);
  90. fs = FileSystem.get(conf);
  91. if (fs.exists(tmppath) &&
  92. !ShimLoader.getHadoopShims().isDirectory(fs.getFileStatus(tmppath))) {
  93. throw new RuntimeException(TMPDIR + " exists but is not a directory");
  94. }
  95. if (!fs.exists(tmppath)) {
  96. if (!fs.mkdirs(tmppath)) {
  97. throw new RuntimeException("Could not make scratch directory "
  98. + TMPDIR);
  99. }
  100. }
  101. LOG.info("Directory of actual files: " + tmppath);
  102. for (Object one : Utilities.makeList("mapplan1.out", "mapplan2.out",
  103. "mapredplan1.out", "mapredplan2.out", "mapredplan3.out",
  104. "mapredplan4.out", "mapredplan5.out", "mapredplan6.out")) {
  105. Path onedir = new Path(tmppath, (String) one);
  106. if (fs.exists(onedir)) {
  107. fs.delete(onedir, true);
  108. }
  109. }
  110. // copy the test files into hadoop if required.
  111. int i = 0;
  112. Path[] hadoopDataFile = new Path[2];
  113. String[] testFiles = {"kv1.txt", "kv2.txt"};
  114. String testFileDir = new Path(conf.get("test.data.files")).toUri().getPath();
  115. LOG.info("Directory of expected files: " + testFileDir);
  116. for (String oneFile : testFiles) {
  117. Path localDataFile = new Path(testFileDir, oneFile);
  118. hadoopDataFile[i] = new Path(tmppath, oneFile);
  119. fs.copyFromLocalFile(false, true, localDataFile, hadoopDataFile[i]);
  120. i++;
  121. }
  122. // load the test files into tables
  123. i = 0;
  124. db = Hive.get(conf);
  125. String[] srctables = {"src", "src2"};
  126. LinkedList<String> cols = new LinkedList<String>();
  127. cols.add("key");
  128. cols.add("value");
  129. for (String src : srctables) {
  130. db.dropTable(Warehouse.DEFAULT_DATABASE_NAME, src, true, true);
  131. db.createTable(src, cols, null, TextInputFormat.class,
  132. HiveIgnoreKeyTextOutputFormat.class);
  133. db.loadTable(hadoopDataFile[i], src, LoadFileType.KEEP_EXISTING,
  134. true, false, false, true, null, 0, false, false);
  135. i++;
  136. }
  137. } catch (Throwable e) {
  138. throw new RuntimeException("Encountered throwable", e);
  139. }
  140. }
  141. MapredWork mr;
  142. @Before
  143. public void setUp() {
  144. mr = PlanUtils.getMapRedWork();
  145. ctx = new CompilationOpContext();
  146. }
  147. public static void addMapWork(MapredWork mr, Table tbl, String alias, Operator<?> work) {
  148. mr.getMapWork().addMapWork(tbl.getDataLocation(), alias, work, new PartitionDesc(
  149. Utilities.getTableDesc(tbl), null));
  150. }
  151. private static void fileDiff(String datafile, String testdir) throws Exception {
  152. String testFileDir = conf.get("test.data.files");
  153. // inbuilt assumption that the testdir has only one output file.
  154. Path diTest = new Path(tmppath, testdir);
  155. if (!fs.exists(diTest)) {
  156. throw new RuntimeException(TMPDIR + File.separator + testdir + " does not exist");
  157. }
  158. if (!ShimLoader.getHadoopShims().isDirectory(fs.getFileStatus(diTest))) {
  159. throw new RuntimeException(TMPDIR + File.separator + testdir + " is not a directory");
  160. }
  161. FSDataInputStream fiTest = fs.open((fs.listStatus(diTest))[0].getPath());
  162. FileInputStream fiGold = new FileInputStream(new File(testFileDir, datafile));
  163. if (!Utilities.contentsEqual(fiGold, fiTest, false)) {
  164. LOG.error(diTest.toString() + " does not match " + datafile);
  165. assertEquals(false, true);
  166. }
  167. }
  168. private FilterDesc getTestFilterDesc(String column) throws Exception {
  169. ArrayList<ExprNodeDesc> children1 = new ArrayList<ExprNodeDesc>();
  170. children1.add(new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo,
  171. column, "", false));
  172. ExprNodeDesc lhs = new ExprNodeGenericFuncDesc(
  173. TypeInfoFactory.doubleTypeInfo, FunctionRegistry.getFunctionInfo(
  174. serdeConstants.DOUBLE_TYPE_NAME).getGenericUDF(), children1);
  175. ArrayList<ExprNodeDesc> children2 = new ArrayList<ExprNodeDesc>();
  176. children2.add(new ExprNodeConstantDesc(TypeInfoFactory.longTypeInfo, Long
  177. .valueOf(100)));
  178. ExprNodeDesc rhs = new ExprNodeGenericFuncDesc(
  179. TypeInfoFactory.doubleTypeInfo, FunctionRegistry.getFunctionInfo(
  180. serdeConstants.DOUBLE_TYPE_NAME).getGenericUDF(), children2);
  181. ArrayList<ExprNodeDesc> children3 = new ArrayList<ExprNodeDesc>();
  182. children3.add(lhs);
  183. children3.add(rhs);
  184. ExprNodeDesc desc = new ExprNodeGenericFuncDesc(
  185. TypeInfoFactory.booleanTypeInfo, FunctionRegistry.getFunctionInfo("<")
  186. .getGenericUDF(), children3);
  187. return new FilterDesc(desc, false);
  188. }
  189. @SuppressWarnings("unchecked")
  190. private void populateMapPlan1(Table src) throws Exception {
  191. Operator<FileSinkDesc> op2 = OperatorFactory.get(ctx, new FileSinkDesc(new Path(TMPDIR + File.separator
  192. + "mapplan1.out"), Utilities.defaultTd, true));
  193. Operator<FilterDesc> op1 = OperatorFactory.get(getTestFilterDesc("key"), op2);
  194. addMapWork(mr, src, "a", op1);
  195. }
  196. @SuppressWarnings("unchecked")
  197. private void populateMapPlan2(Table src) throws Exception {
  198. Operator<FileSinkDesc> op3 = OperatorFactory.get(ctx, new FileSinkDesc(new Path(TMPDIR + File.separator
  199. + "mapplan2.out"), Utilities.defaultTd, false));
  200. Operator<ScriptDesc> op2 = OperatorFactory.get(new ScriptDesc("cat",
  201. PlanUtils.getDefaultTableDesc("" + Utilities.tabCode, "key,value"),
  202. TextRecordWriter.class, PlanUtils.getDefaultTableDesc(""
  203. + Utilities.tabCode, "key,value"), TextRecordReader.class,
  204. TextRecordReader.class, PlanUtils.getDefaultTableDesc("" + Utilities.tabCode, "key")), op3);
  205. Operator<FilterDesc> op1 = OperatorFactory.get(getTestFilterDesc("key"),
  206. op2);
  207. addMapWork(mr, src, "a", op1);
  208. }
  209. @SuppressWarnings("unchecked")
  210. private void populateMapRedPlan1(Table src) throws SemanticException {
  211. ArrayList<String> outputColumns = new ArrayList<String>();
  212. for (int i = 0; i < 2; i++) {
  213. outputColumns.add("_col" + i);
  214. }
  215. // map-side work
  216. Operator<ReduceSinkDesc> op1 = OperatorFactory.get(ctx, PlanUtils
  217. .getReduceSinkDesc(Utilities.makeList(getStringColumn("key")),
  218. Utilities.makeList(getStringColumn("value")), outputColumns, true,
  219. -1, 1, -1, AcidUtils.Operation.NOT_ACID, NullOrdering.NULLS_LAST));
  220. addMapWork(mr, src, "a", op1);
  221. ReduceWork rWork = new ReduceWork();
  222. rWork.setNumReduceTasks(Integer.valueOf(1));
  223. rWork.setKeyDesc(op1.getConf().getKeySerializeInfo());
  224. rWork.getTagToValueDesc().add(op1.getConf().getValueSerializeInfo());
  225. mr.setReduceWork(rWork);
  226. // reduce side work
  227. Operator<FileSinkDesc> op3 = OperatorFactory.get(ctx, new FileSinkDesc(new Path(TMPDIR + File.separator
  228. + "mapredplan1.out"), Utilities.defaultTd, false));
  229. List<ExprNodeDesc> cols = new ArrayList<ExprNodeDesc>();
  230. cols.add(getStringColumn(Utilities.ReduceField.VALUE.toString()+"."+outputColumns.get(1)));
  231. List<String> colNames = new ArrayList<String>();
  232. colNames.add(HiveConf.getColumnInternalName(2));
  233. Operator<SelectDesc> op2 = OperatorFactory.get(new SelectDesc(cols, colNames), op3);
  234. rWork.setReducer(op2);
  235. }
  236. @SuppressWarnings("unchecked")
  237. private void populateMapRedPlan2(Table src) throws Exception {
  238. ArrayList<String> outputColumns = new ArrayList<String>();
  239. for (int i = 0; i < 2; i++) {
  240. outputColumns.add("_col" + i);
  241. }
  242. // map-side work
  243. Operator<ReduceSinkDesc> op1 = OperatorFactory.get(ctx, PlanUtils
  244. .getReduceSinkDesc(Utilities.makeList(getStringColumn("key")),
  245. Utilities
  246. .makeList(getStringColumn("key"), getStringColumn("value")),
  247. outputColumns, false, -1, 1, -1, AcidUtils.Operation.NOT_ACID, NullOrdering.NULLS_LAST));
  248. addMapWork(mr, src, "a", op1);
  249. ReduceWork rWork = new ReduceWork();
  250. rWork.setNumReduceTasks(Integer.valueOf(1));
  251. rWork.setKeyDesc(op1.getConf().getKeySerializeInfo());
  252. rWork.getTagToValueDesc().add(op1.getConf().getValueSerializeInfo());
  253. mr.setReduceWork(rWork);
  254. // reduce side work
  255. Operator<FileSinkDesc> op4 = OperatorFactory.get(ctx, new FileSinkDesc(new Path(TMPDIR + File.separator
  256. + "mapredplan2.out"), Utilities.defaultTd, false));
  257. Operator<FilterDesc> op3 = OperatorFactory.get(getTestFilterDesc("0"), op4);
  258. List<ExprNodeDesc> cols = new ArrayList<ExprNodeDesc>();
  259. cols.add(getStringColumn(Utilities.ReduceField.KEY + ".reducesinkkey" + 0));
  260. cols.add(getStringColumn(Utilities.ReduceField.VALUE.toString()+"."+outputColumns.get(1)));
  261. Operator<SelectDesc> op2 = OperatorFactory.get(new SelectDesc(cols, outputColumns), op3);
  262. rWork.setReducer(op2);
  263. }
  264. /**
  265. * test reduce with multiple tagged inputs.
  266. */
  267. @SuppressWarnings("unchecked")
  268. private void populateMapRedPlan3(Table src, Table src2) throws SemanticException {
  269. List<String> outputColumns = new ArrayList<String>();
  270. for (int i = 0; i < 2; i++) {
  271. outputColumns.add("_col" + i);
  272. }
  273. // map-side work
  274. Operator<ReduceSinkDesc> op1 = OperatorFactory.get(ctx, PlanUtils
  275. .getReduceSinkDesc(Utilities.makeList(getStringColumn("key")),
  276. Utilities.makeList(getStringColumn("value")), outputColumns, true,
  277. Byte.valueOf((byte) 0), 1, -1, AcidUtils.Operation.NOT_ACID, NullOrdering.NULLS_LAST));
  278. addMapWork(mr, src, "a", op1);
  279. Operator<ReduceSinkDesc> op2 = OperatorFactory.get(ctx, PlanUtils
  280. .getReduceSinkDesc(Utilities.makeList(getStringColumn("key")),
  281. Utilities.makeList(getStringColumn("key")), outputColumns, true,
  282. Byte.valueOf((byte) 1), Integer.MAX_VALUE, -1, AcidUtils.Operation.NOT_ACID, NullOrdering.NULLS_LAST));
  283. addMapWork(mr, src2, "b", op2);
  284. ReduceWork rWork = new ReduceWork();
  285. rWork.setNumReduceTasks(Integer.valueOf(1));
  286. rWork.setNeedsTagging(true);
  287. rWork.setKeyDesc(op1.getConf().getKeySerializeInfo());
  288. rWork.getTagToValueDesc().add(op1.getConf().getValueSerializeInfo());
  289. mr.setReduceWork(rWork);
  290. rWork.getTagToValueDesc().add(op2.getConf().getValueSerializeInfo());
  291. // reduce side work
  292. Operator<FileSinkDesc> op4 = OperatorFactory.get(ctx, new FileSinkDesc(new Path(TMPDIR + File.separator
  293. + "mapredplan3.out"), Utilities.defaultTd, false));
  294. Operator<SelectDesc> op5 = OperatorFactory.get(new SelectDesc(Utilities
  295. .makeList(new ExprNodeFieldDesc(TypeInfoFactory.stringTypeInfo,
  296. new ExprNodeColumnDesc(TypeInfoFactory.getListTypeInfo(TypeInfoFactory.stringTypeInfo),
  297. Utilities.ReduceField.VALUE.toString(), "", false), "0", false)),
  298. Utilities.makeList(outputColumns.get(0))), op4);
  299. rWork.setReducer(op5);
  300. }
  301. @SuppressWarnings("unchecked")
  302. private void populateMapRedPlan4(Table src) throws SemanticException {
  303. // map-side work
  304. ArrayList<String> outputColumns = new ArrayList<String>();
  305. for (int i = 0; i < 2; i++) {
  306. outputColumns.add("_col" + i);
  307. }
  308. Operator<ReduceSinkDesc> op1 = OperatorFactory.get(ctx, PlanUtils
  309. .getReduceSinkDesc(Utilities.makeList(getStringColumn("tkey")),
  310. Utilities.makeList(getStringColumn("tkey"),
  311. getStringColumn("tvalue")), outputColumns, false, -1, 1, -1,
  312. AcidUtils.Operation.NOT_ACID, NullOrdering.NULLS_LAST));
  313. Operator<ScriptDesc> op0 = OperatorFactory.get(new ScriptDesc("cat",
  314. PlanUtils.getDefaultTableDesc("" + Utilities.tabCode, "key,value"),
  315. TextRecordWriter.class, PlanUtils.getDefaultTableDesc(""
  316. + Utilities.tabCode, "tkey,tvalue"), TextRecordReader.class,
  317. TextRecordReader.class, PlanUtils.getDefaultTableDesc("" + Utilities.tabCode, "key")), op1);
  318. Operator<SelectDesc> op4 = OperatorFactory.get(new SelectDesc(Utilities
  319. .makeList(getStringColumn("key"), getStringColumn("value")),
  320. outputColumns), op0);
  321. addMapWork(mr, src, "a", op4);
  322. ReduceWork rWork = new ReduceWork();
  323. rWork.setKeyDesc(op1.getConf().getKeySerializeInfo());
  324. rWork.getTagToValueDesc().add(op1.getConf().getValueSerializeInfo());
  325. rWork.setNumReduceTasks(Integer.valueOf(1));
  326. mr.setReduceWork(rWork);
  327. // reduce side work
  328. Operator<FileSinkDesc> op3 = OperatorFactory.get(ctx, new FileSinkDesc(new Path(TMPDIR + File.separator
  329. + "mapredplan4.out"), Utilities.defaultTd, false));
  330. List<ExprNodeDesc> cols = new ArrayList<ExprNodeDesc>();
  331. cols.add(getStringColumn(Utilities.ReduceField.KEY + ".reducesinkkey" + 0));
  332. cols.add(getStringColumn(Utilities.ReduceField.VALUE.toString()+"."+outputColumns.get(1)));
  333. Operator<SelectDesc> op2 = OperatorFactory.get(new SelectDesc(cols, outputColumns), op3);
  334. rWork.setReducer(op2);
  335. }
  336. public static ExprNodeColumnDesc getStringColumn(String columnName) {
  337. return new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, columnName,
  338. "", false);
  339. }
  340. @SuppressWarnings("unchecked")
  341. private void populateMapRedPlan5(Table src) throws SemanticException {
  342. // map-side work
  343. ArrayList<String> outputColumns = new ArrayList<String>();
  344. for (int i = 0; i < 2; i++) {
  345. outputColumns.add("_col" + i);
  346. }
  347. Operator<ReduceSinkDesc> op0 = OperatorFactory.get(ctx, PlanUtils
  348. .getReduceSinkDesc(Utilities.makeList(getStringColumn("0")), Utilities
  349. .makeList(getStringColumn("0"), getStringColumn("1")),
  350. outputColumns, false, -1, 1, -1, AcidUtils.Operation.NOT_ACID, NullOrdering.NULLS_LAST));
  351. Operator<SelectDesc> op4 = OperatorFactory.get(new SelectDesc(Utilities
  352. .makeList(getStringColumn("key"), getStringColumn("value")),
  353. outputColumns), op0);
  354. addMapWork(mr, src, "a", op4);
  355. ReduceWork rWork = new ReduceWork();
  356. mr.setReduceWork(rWork);
  357. rWork.setNumReduceTasks(Integer.valueOf(1));
  358. rWork.setKeyDesc(op0.getConf().getKeySerializeInfo());
  359. rWork.getTagToValueDesc().add(op0.getConf().getValueSerializeInfo());
  360. // reduce side work
  361. Operator<FileSinkDesc> op3 = OperatorFactory.get(ctx, new FileSinkDesc(new Path(TMPDIR + File.separator
  362. + "mapredplan5.out"), Utilities.defaultTd, false));
  363. List<ExprNodeDesc> cols = new ArrayList<ExprNodeDesc>();
  364. cols.add(getStringColumn(Utilities.ReduceField.KEY + ".reducesinkkey" + 0));
  365. cols.add(getStringColumn(Utilities.ReduceField.VALUE.toString()+"."+outputColumns.get(1)));
  366. Operator<SelectDesc> op2 = OperatorFactory.get(new SelectDesc(cols, outputColumns), op3);
  367. rWork.setReducer(op2);
  368. }
  369. @SuppressWarnings("unchecked")
  370. private void populateMapRedPlan6(Table src) throws Exception {
  371. // map-side work
  372. ArrayList<String> outputColumns = new ArrayList<String>();
  373. for (int i = 0; i < 2; i++) {
  374. outputColumns.add("_col" + i);
  375. }
  376. Operator<ReduceSinkDesc> op1 = OperatorFactory.get(ctx, PlanUtils
  377. .getReduceSinkDesc(Utilities.makeList(getStringColumn("tkey")),
  378. Utilities.makeList(getStringColumn("tkey"),
  379. getStringColumn("tvalue")), outputColumns, false, -1, 1, -1,
  380. AcidUtils.Operation.NOT_ACID, NullOrdering.NULLS_LAST));
  381. Operator<ScriptDesc> op0 = OperatorFactory.get(new ScriptDesc(
  382. "\'cat\'", PlanUtils.getDefaultTableDesc("" + Utilities.tabCode,
  383. "tkey,tvalue"), TextRecordWriter.class, PlanUtils
  384. .getDefaultTableDesc("" + Utilities.tabCode, "tkey,tvalue"),
  385. TextRecordReader.class,
  386. TextRecordReader.class, PlanUtils.getDefaultTableDesc("" + Utilities.tabCode, "key")), op1);
  387. Operator<SelectDesc> op4 = OperatorFactory.get(new SelectDesc(Utilities
  388. .makeList(getStringColumn("key"), getStringColumn("value")),
  389. outputColumns), op0);
  390. addMapWork(mr, src, "a", op4);
  391. ReduceWork rWork = new ReduceWork();
  392. mr.setReduceWork(rWork);
  393. rWork.setNumReduceTasks(Integer.valueOf(1));
  394. rWork.setKeyDesc(op1.getConf().getKeySerializeInfo());
  395. rWork.getTagToValueDesc().add(op1.getConf().getValueSerializeInfo());
  396. // reduce side work
  397. Operator<FileSinkDesc> op3 = OperatorFactory.get(ctx, new FileSinkDesc(new Path(TMPDIR + File.separator
  398. + "mapredplan6.out"), Utilities.defaultTd, false));
  399. Operator<FilterDesc> op2 = OperatorFactory.get(getTestFilterDesc("0"), op3);
  400. List<ExprNodeDesc> cols = new ArrayList<ExprNodeDesc>();
  401. cols.add(getStringColumn(Utilities.ReduceField.KEY + ".reducesinkkey" + 0));
  402. cols.add(getStringColumn(Utilities.ReduceField.VALUE.toString()+"."+outputColumns.get(1)));
  403. Operator<SelectDesc> op5 = OperatorFactory.get(new SelectDesc(cols, outputColumns), op2);
  404. rWork.setReducer(op5);
  405. }
  406. private void executePlan() throws Exception {
  407. String testName = new Exception().getStackTrace()[1].getMethodName();
  408. MapRedTask mrtask = new MapRedTask();
  409. TaskQueue taskQueue = new TaskQueue();
  410. mrtask.setWork(mr);
  411. mrtask.initialize(queryState, null, taskQueue, null);
  412. int exitVal = mrtask.execute();
  413. if (exitVal != 0) {
  414. LOG.error(testName + " execution failed with exit status: "
  415. + exitVal);
  416. assertEquals(true, false);
  417. }
  418. LOG.info(testName + " execution completed successfully");
  419. }
  420. @Test
  421. public void testMapPlan1() throws Exception {
  422. LOG.info("Beginning testMapPlan1");
  423. populateMapPlan1(db.getTable(Warehouse.DEFAULT_DATABASE_NAME, "src"));
  424. executePlan();
  425. fileDiff("lt100.txt.deflate", "mapplan1.out");
  426. }
  427. @Test
  428. public void testMapPlan2() throws Exception {
  429. LOG.info("Beginning testMapPlan2");
  430. populateMapPlan2(db.getTable(Warehouse.DEFAULT_DATABASE_NAME, "src"));
  431. executePlan();
  432. fileDiff("lt100.txt", "mapplan2.out");
  433. }
  434. @Test
  435. public void testMapRedPlan1() throws Exception {
  436. LOG.info("Beginning testMapRedPlan1");
  437. populateMapRedPlan1(db.getTable(Warehouse.DEFAULT_DATABASE_NAME,
  438. "src"));
  439. executePlan();
  440. fileDiff("kv1.val.sorted.txt", "mapredplan1.out");
  441. }
  442. @Test
  443. public void testMapRedPlan2() throws Exception {
  444. LOG.info("Beginning testMapPlan2");
  445. populateMapRedPlan2(db.getTable(Warehouse.DEFAULT_DATABASE_NAME,
  446. "src"));
  447. executePlan();
  448. fileDiff("lt100.sorted.txt", "mapredplan2.out");
  449. }
  450. @Test
  451. public void testMapRedPlan3() throws Exception {
  452. LOG.info("Beginning testMapPlan3");
  453. populateMapRedPlan3(db.getTable(Warehouse.DEFAULT_DATABASE_NAME,
  454. "src"), db.getTable(Warehouse.DEFAULT_DATABASE_NAME, "src2"));
  455. executePlan();
  456. fileDiff("kv1kv2.cogroup.txt", "mapredplan3.out");
  457. }
  458. @Test
  459. public void testMapRedPlan4() throws Exception {
  460. LOG.info("Beginning testMapPlan4");
  461. populateMapRedPlan4(db.getTable(Warehouse.DEFAULT_DATABASE_NAME,
  462. "src"));
  463. executePlan();
  464. fileDiff("kv1.string-sorted.txt", "mapredplan4.out");
  465. }
  466. @Test
  467. public void testMapRedPlan5() throws Exception {
  468. LOG.info("Beginning testMapPlan5");
  469. populateMapRedPlan5(db.getTable(Warehouse.DEFAULT_DATABASE_NAME,
  470. "src"));
  471. executePlan();
  472. fileDiff("kv1.string-sorted.txt", "mapredplan5.out");
  473. }
  474. @Test
  475. public void testMapRedPlan6() throws Exception {
  476. LOG.info("Beginning testMapPlan6");
  477. populateMapRedPlan6(db.getTable(Warehouse.DEFAULT_DATABASE_NAME,
  478. "src"));
  479. executePlan();
  480. fileDiff("lt100.sorted.txt", "mapredplan6.out");
  481. }
  482. }