@Test public void testEqual() throws Exception { if (conf.getBoolean("tajo.storage.manager.v2", false)) { return; } this.rndKey = rnd.nextInt(250); final String QUERY = "select * from employee where managerId = " + rndKey; FileFragment[] frags = StorageManager.splitNG(conf, "default.employee", meta, tablePath, Integer.MAX_VALUE); Path workDir = CommonTestingUtil.getTestDir("target/test-data/testEqual"); TaskAttemptContext ctx = new TaskAttemptContext( conf, LocalTajoTestingUtility.newQueryUnitAttemptId(), new FileFragment[] {frags[0]}, workDir); Expr expr = analyzer.parse(QUERY); LogicalPlan plan = planner.createPlan(LocalTajoTestingUtility.createDummySession(), expr); LogicalNode rootNode = optimizer.optimize(plan); TmpPlanner phyPlanner = new TmpPlanner(conf, sm); PhysicalExec exec = phyPlanner.createPlan(ctx, rootNode); int tupleCount = this.randomValues.get(rndKey); int counter = 0; exec.init(); while (exec.next() != null) { counter++; } exec.close(); assertEquals(tupleCount, counter); }
public BNLJoinExec( final TaskAttemptContext context, final JoinNode join, final PhysicalExec outer, PhysicalExec inner) { super( context, SchemaUtil.merge(outer.getSchema(), inner.getSchema()), SchemaUtil.merge(outer.getSchema(), inner.getSchema()), outer, inner); this.joinQual = join.getJoinQual(); this.qualCtx = this.joinQual.newContext(); this.outerTupleSlots = new ArrayList<Tuple>(TUPLE_SLOT_SIZE); this.innerTupleSlots = new ArrayList<Tuple>(TUPLE_SLOT_SIZE); this.outerIterator = outerTupleSlots.iterator(); this.innerIterator = innerTupleSlots.iterator(); this.innerEnd = false; this.outerEnd = false; // for projection targetIds = RowStoreUtil.getTargetIds(inSchema, outSchema); // for join frameTuple = new FrameTuple(); outputTuple = new VTuple(outSchema.getColumnNum()); }
@Test public final void testRightOuter_MergeJoin3() throws IOException, TajoException { Expr expr = analyzer.parse(QUERIES[3]); LogicalNode plan = planner.createPlan(defaultContext, expr).getRootBlock().getRoot(); JoinNode joinNode = PlannerUtil.findTopNode(plan, NodeType.JOIN); Enforcer enforcer = new Enforcer(); enforcer.enforceJoinAlgorithm(joinNode.getPID(), JoinAlgorithm.MERGE_JOIN); FileFragment[] emp3Frags = FileTablespace.splitNG( conf, EMP3_NAME, emp3.getMeta(), new Path(emp3.getUri()), Integer.MAX_VALUE); FileFragment[] dep4Frags = FileTablespace.splitNG( conf, DEP4_NAME, dep4.getMeta(), new Path(dep4.getUri()), Integer.MAX_VALUE); FileFragment[] merged = TUtil.concat(emp3Frags, dep4Frags); Path workDir = CommonTestingUtil.getTestDir( TajoTestingCluster.DEFAULT_TEST_DIRECTORY + "/testRightOuter_MergeJoin3"); TaskAttemptContext ctx = new TaskAttemptContext( new QueryContext(conf), LocalTajoTestingUtility.newTaskAttemptId(), merged, workDir); ctx.setEnforcer(enforcer); PhysicalPlanner phyPlanner = new PhysicalPlannerImpl(conf); PhysicalExec exec = phyPlanner.createPlan(ctx, plan); ProjectionExec proj = (ProjectionExec) exec; assertTrue(proj.getChild() instanceof RightOuterMergeJoinExec); int count = 0; exec.init(); while (exec.next() != null) { // TODO check contents count = count + 1; } assertNull(exec.next()); exec.close(); assertEquals(13, count); }
public MergeJoinExec( TaskAttemptContext context, JoinNode plan, PhysicalExec outer, PhysicalExec inner, SortSpec[] outerSortKey, SortSpec[] innerSortKey) { super(context, plan.getInSchema(), plan.getOutSchema(), outer, inner); Preconditions.checkArgument( plan.hasJoinQual(), "Sort-merge join is only used for the equi-join, " + "but there is no join condition"); this.joinNode = plan; this.joinQual = plan.getJoinQual(); this.qualCtx = this.joinQual.newContext(); this.outerTupleSlots = new ArrayList<Tuple>(INITIAL_TUPLE_SLOT); this.innerTupleSlots = new ArrayList<Tuple>(INITIAL_TUPLE_SLOT); SortSpec[][] sortSpecs = new SortSpec[2][]; sortSpecs[0] = outerSortKey; sortSpecs[1] = innerSortKey; this.joincomparator = new JoinTupleComparator(outer.getSchema(), inner.getSchema(), sortSpecs); this.tupleComparator = PlannerUtil.getComparatorsFromJoinQual( plan.getJoinQual(), outer.getSchema(), inner.getSchema()); this.outerIterator = outerTupleSlots.iterator(); this.innerIterator = innerTupleSlots.iterator(); // for projection this.projector = new Projector(inSchema, outSchema, plan.getTargets()); this.evalContexts = projector.renew(); // for join frameTuple = new FrameTuple(); outTuple = new VTuple(outSchema.getColumnNum()); }
public UnionExec(TaskAttemptContext context, PhysicalExec outer, PhysicalExec inner) { super(context, outer.getSchema(), inner.getSchema(), outer, inner); if (!outer.getSchema().equals(inner.getSchema())) { throw new InvalidQueryException("The both schemas are not same"); } }
@Test public final void testNext() throws IOException, PlanningException { FileFragment[] frags = StorageManager.splitNG( conf, "employee", employee.getMeta(), employee.getPath(), Integer.MAX_VALUE); Path workDir = new Path(testDir, TestExternalSortExec.class.getName()); TaskAttemptContext ctx = new TaskAttemptContext( conf, LocalTajoTestingUtility.newQueryUnitAttemptId(), new FileFragment[] {frags[0]}, workDir); ctx.setEnforcer(new Enforcer()); Expr expr = analyzer.parse(QUERIES[0]); LogicalPlan plan = planner.createPlan(expr); LogicalNode rootNode = plan.getRootBlock().getRoot(); PhysicalPlanner phyPlanner = new PhysicalPlannerImpl(conf, sm); PhysicalExec exec = phyPlanner.createPlan(ctx, rootNode); ProjectionExec proj = (ProjectionExec) exec; // TODO - should be planed with user's optimization hint if (!(proj.getChild() instanceof ExternalSortExec)) { UnaryPhysicalExec sortExec = proj.getChild(); SeqScanExec scan = sortExec.getChild(); ExternalSortExec extSort = new ExternalSortExec(ctx, sm, ((MemSortExec) sortExec).getPlan(), scan); proj.setChild(extSort); } Tuple tuple; Tuple preVal = null; Tuple curVal; int cnt = 0; exec.init(); long start = System.currentTimeMillis(); TupleComparator comparator = new TupleComparator( proj.getSchema(), new SortSpec[] { new SortSpec(new Column("managerId", Type.INT4)), new SortSpec(new Column("empId", Type.INT4)) }); while ((tuple = exec.next()) != null) { curVal = tuple; if (preVal != null) { assertTrue( "prev: " + preVal + ", but cur: " + curVal, comparator.compare(preVal, curVal) <= 0); } preVal = curVal; cnt++; } long end = System.currentTimeMillis(); assertEquals(numTuple, cnt); // for rescan test preVal = null; exec.rescan(); cnt = 0; while ((tuple = exec.next()) != null) { curVal = tuple; if (preVal != null) { assertTrue( "prev: " + preVal + ", but cur: " + curVal, comparator.compare(preVal, curVal) <= 0); } preVal = curVal; cnt++; } assertEquals(numTuple, cnt); exec.close(); System.out.println("Sort Time: " + (end - start) + " msc"); }