private NonDistinctHashAggregator(GroupbyNode groupbyNode) throws IOException { nonDistinctAggrDatas = new TupleMap<>(); if (groupbyNode.hasAggFunctions()) { aggFunctions = groupbyNode.getAggFunctions(); aggFunctionsNum = aggFunctions.size(); } else { aggFunctions = new ArrayList<>(); aggFunctionsNum = 0; } for (AggregationFunctionCallEval eachFunction: aggFunctions) { eachFunction.bind(context.getEvalContext(), inSchema); eachFunction.setFirstPhase(); } outTuple = new VTuple(aggFunctionsNum); dummyTuple = NullTuple.create(aggFunctionsNum); tupleLength = aggFunctionsNum; }
firstPhaseEvals.get(i).setFirstPhase(); firstPhaseEvalNames[i] = plan.generateUniqueColumnName(firstPhaseEvals.get(i)); FieldEval param = new FieldEval(firstPhaseEvalNames[i], firstPhaseEvals.get(i).getValueType());
private NonDistinctHashAggregator(GroupbyNode groupbyNode) throws IOException { nonDistinctAggrDatas = new TupleMap<FunctionContext[]>(); if (groupbyNode.hasAggFunctions()) { aggFunctions = groupbyNode.getAggFunctions(); aggFunctionsNum = aggFunctions.length; } else { aggFunctions = new AggregationFunctionCallEval[0]; aggFunctionsNum = 0; } for (AggregationFunctionCallEval eachFunction: aggFunctions) { eachFunction.bind(context.getEvalContext(), inSchema); eachFunction.setFirstPhase(); } outTuple = new VTuple(aggFunctionsNum); dummyTuple = NullTuple.create(aggFunctionsNum); tupleLength = aggFunctionsNum; }
for (int aggIdx = 0; aggIdx < aggFunctions.size(); aggIdx++) { AggregationFunctionCallEval aggFunction = aggFunctions.get(aggIdx); aggFunction.setFirstPhase(); Target originAggFunctionTarget = groupbyNode.getTargets().get(originalGroupingColumns.size() + aggIdx); Target aggFunctionTarget =
aggFunction.setFirstPhase(); String firstEvalNames = plan.generateUniqueColumnName(aggFunction); FieldEval firstEval = new FieldEval(firstEvalNames, aggFunction.getValueType());
for (int aggIdx = 0; aggIdx < aggFunctions.length; aggIdx++) { AggregationFunctionCallEval aggFunction = aggFunctions[aggIdx]; aggFunction.setFirstPhase(); Target originAggFunctionTarget = groupbyNode.getTargets()[originalGroupingColumns.size() + aggIdx]; Target aggFunctionTarget =
firstPhaseEvals[i].setFirstPhase(); firstPhaseEvalNames[i] = plan.generateUniqueColumnName(firstPhaseEvals[i]); FieldEval param = new FieldEval(firstPhaseEvalNames[i], firstPhaseEvals[i].getValueType());
aggFunction.setFirstPhase(); String firstEvalNames = plan.generateUniqueColumnName(aggFunction); FieldEval firstEval = new FieldEval(firstEvalNames, aggFunction.getValueType());
aggFunctions.get(i).setFirstPhase(); int index = 0; for (AggregationFunctionCallEval aggrFunction: lastGroupbyNode.getAggFunctions()) { aggrFunction.setFirstPhase(); aggrFunction.setArgs(new EvalNode[]{new FieldEval(lastGroupbyNode.getTargets().get(index).getNamedColumn())}); index++;
aggFunc.setFirstAndLastPhase(); } else if (aggFunctionProto.getFirstPhase()) { aggFunc.setFirstPhase(); } else if (aggFunctionProto.getLastPhase()) { aggFunc.setLastPhase();
aggFunc.setFirstAndLastPhase(); } else if (aggFunctionProto.getFirstPhase()) { aggFunc.setFirstPhase(); } else if (aggFunctionProto.getLastPhase()) { aggFunc.setLastPhase();
aggFunctions[i].setFirstPhase(); int index = 0; for (AggregationFunctionCallEval aggrFunction: lastGroupbyNode.getAggFunctions()) { aggrFunction.setFirstPhase(); aggrFunction.setArgs(new EvalNode[]{new FieldEval(lastGroupbyNode.getTargets()[index].getNamedColumn())}); index++;
@Test public final void testCountFunction() throws IOException, TajoException { FileFragment[] frags = FileTablespace.splitNG(conf, "default.score", score.getMeta(), new Path(score.getUri()), Integer.MAX_VALUE); Path workDir = CommonTestingUtil.getTestDir(TajoTestingCluster.DEFAULT_TEST_DIRECTORY + "/testCountFunction"); TaskAttemptContext ctx = new TaskAttemptContext(new QueryContext(conf), LocalTajoTestingUtility.newTaskAttemptId(masterPlan), new FileFragment[] { frags[0] }, workDir); ctx.setEnforcer(new Enforcer()); Expr context = analyzer.parse(QUERIES[9]); LogicalPlan plan = planner.createPlan(defaultContext, context); LogicalNode rootNode = optimizer.optimize(plan); // Set all aggregation functions to the first phase mode GroupbyNode groupbyNode = PlannerUtil.findTopNode(rootNode, NodeType.GROUP_BY); for (AggregationFunctionCallEval function : groupbyNode.getAggFunctions()) { function.setFirstPhase(); } PhysicalPlanner phyPlanner = new PhysicalPlannerImpl(conf); PhysicalExec exec = phyPlanner.createPlan(ctx, rootNode); exec.init(); Tuple tuple = exec.next(); assertEquals(30, tuple.getInt8(0)); assertNull(exec.next()); exec.close(); }
@Test public final void testAggregationFunction() throws IOException, TajoException { FileFragment[] frags = FileTablespace.splitNG(conf, "default.score", score.getMeta(), new Path(score.getUri()), Integer.MAX_VALUE); Path workDir = CommonTestingUtil.getTestDir(TajoTestingCluster.DEFAULT_TEST_DIRECTORY + "/testAggregationFunction"); TaskAttemptContext ctx = new TaskAttemptContext(new QueryContext(conf), LocalTajoTestingUtility.newTaskAttemptId(masterPlan), new FileFragment[] { frags[0] }, workDir); ctx.setEnforcer(new Enforcer()); Expr context = analyzer.parse(QUERIES[8]); LogicalPlan plan = planner.createPlan(defaultContext, context); LogicalNode rootNode = optimizer.optimize(plan); // Set all aggregation functions to the first phase mode GroupbyNode groupbyNode = PlannerUtil.findTopNode(rootNode, NodeType.GROUP_BY); for (AggregationFunctionCallEval function : groupbyNode.getAggFunctions()) { function.setFirstPhase(); } PhysicalPlanner phyPlanner = new PhysicalPlannerImpl(conf); PhysicalExec exec = phyPlanner.createPlan(ctx, rootNode); exec.init(); Tuple tuple = exec.next(); assertEquals(30, tuple.getInt8(0)); assertEquals(3, tuple.getInt4(1)); assertEquals(1, tuple.getInt4(2)); assertNull(exec.next()); exec.close(); }