@Override public RESULT visitGroupBy(CONTEXT context, LogicalPlan plan, LogicalPlan.QueryBlock block, GroupbyNode node, Stack<LogicalNode> stack) throws TajoException { stack.push(node); RESULT result = visit(context, plan, block, node.getChild(), stack); stack.pop(); return result; }
@Override public RESULT visitGroupBy(CONTEXT context, LogicalPlan plan, LogicalPlan.QueryBlock block, GroupbyNode node, Stack<LogicalNode> stack) throws TajoException { stack.push(node); RESULT result = visit(context, plan, block, node.getChild(), stack); stack.pop(); return result; }
public void visitGroupBy(SQLBuilderContext ctx, GroupbyNode groupby, Stack<LogicalNode> stack) { visit(ctx, groupby.getChild(), stack); ctx.sb.append("GROUP BY ").append(StringUtils.join(groupby.getGroupingColumns(), ",", 0)).append(" "); }
public void visitGroupBy(SQLBuilderContext ctx, GroupbyNode groupby, Stack<LogicalNode> stack) { visit(ctx, groupby.getChild(), stack); ctx.sb.append("GROUP BY ").append(StringUtils.join(groupby.getGroupingColumns(), ",", 0)).append(" "); }
@Override public LogicalNode visitGroupBy(FilterPushDownContext context, LogicalPlan plan, LogicalPlan.QueryBlock block, GroupbyNode groupbyNode, Stack<LogicalNode> stack) throws TajoException { LogicalNode parentNode = stack.peek(); List<EvalNode> aggrEvals; if (parentNode.getType() == NodeType.HAVING) { aggrEvals = addHavingNode(context, plan, block, null, (HavingNode)parentNode, groupbyNode); } else { aggrEvals = addHavingNode(context, plan, block, (UnaryNode)parentNode, null, groupbyNode); } if (aggrEvals != null) { // remove aggregation eval from conext context.pushingDownFilters.removeAll(aggrEvals); } List<EvalNode> notMatched = new ArrayList<>(); // transform Map<EvalNode, EvalNode> transformed = findCanPushdownAndTransform(context, block, groupbyNode,groupbyNode.getChild(), notMatched, null, 0); context.setFiltersTobePushed(transformed.keySet()); LogicalNode current = super.visitGroupBy(context, plan, block, groupbyNode, stack); context.setToOrigin(transformed); context.addFiltersTobePushed(notMatched); return current; }
private PhysicalExec createBestAggregationPlan(TaskAttemptContext context, GroupbyNode groupbyNode, PhysicalExec subOp) throws IOException { Column[] grpColumns = groupbyNode.getGroupingColumns(); if (grpColumns.length == 0) { return createInMemoryHashAggregation(context, groupbyNode, subOp); } String [] outerLineage = PlannerUtil.getRelationLineage(groupbyNode.getChild()); long estimatedSize = estimateSizeRecursive(context, outerLineage); final long threshold = context.getQueryContext().getLong(SessionVars.HASH_GROUPBY_SIZE_LIMIT) * StorageUnit.MB; // if the relation size is less than the threshold, // the hash aggregation will be used. LOG.info("Aggregation:estimatedSize=" + estimatedSize + ", threshold=" + threshold); if (estimatedSize <= threshold) { LOG.info("The planner chooses [Hash Aggregation]"); return createInMemoryHashAggregation(context, groupbyNode, subOp); } else { return createSortAggregation(context, null, groupbyNode, subOp); } }
private PhysicalExec createBestAggregationPlan(TaskAttemptContext context, GroupbyNode groupbyNode, PhysicalExec subOp) throws IOException { Column[] grpColumns = groupbyNode.getGroupingColumns(); if (grpColumns.length == 0) { return createInMemoryHashAggregation(context, groupbyNode, subOp); } String [] outerLineage = PlannerUtil.getRelationLineage(groupbyNode.getChild()); long estimatedSize = estimateSizeRecursive(context, outerLineage); final long threshold = context.getQueryContext().getLong(SessionVars.HASH_GROUPBY_SIZE_LIMIT) * StorageUnit.MB; // if the relation size is less than the threshold, // the hash aggregation will be used. LOG.info("Aggregation:estimatedSize=" + estimatedSize + ", threshold=" + threshold); if (estimatedSize <= threshold) { LOG.info("The planner chooses [Hash Aggregation]"); return createInMemoryHashAggregation(context, groupbyNode, subOp); } else { return createSortAggregation(context, null, groupbyNode, subOp); } }
@Override public LogicalNode visitGroupBy(FilterPushDownContext context, LogicalPlan plan, LogicalPlan.QueryBlock block, GroupbyNode groupbyNode, Stack<LogicalNode> stack) throws TajoException { LogicalNode parentNode = stack.peek(); List<EvalNode> aggrEvals; if (parentNode.getType() == NodeType.HAVING) { aggrEvals = addHavingNode(context, plan, block, null, (HavingNode)parentNode, groupbyNode); } else { aggrEvals = addHavingNode(context, plan, block, (UnaryNode)parentNode, null, groupbyNode); } if (aggrEvals != null) { // remove aggregation eval from conext context.pushingDownFilters.removeAll(aggrEvals); } List<EvalNode> notMatched = TUtil.newList(); // transform Map<EvalNode, EvalNode> transformed = findCanPushdownAndTransform(context, block, groupbyNode,groupbyNode.getChild(), notMatched, null, 0); context.setFiltersTobePushed(transformed.keySet()); LogicalNode current = super.visitGroupBy(context, plan, block, groupbyNode, stack); context.setToOrigin(transformed); context.addFiltersTobePushed(notMatched); return current; }
baseDistinctNode.setGroupingColumns(groupbyNode.getGroupingColumns()); baseDistinctNode.setInSchema(groupbyNode.getInSchema()); baseDistinctNode.setChild(groupbyNode.getChild());
GroupbyNode grpNode = (GroupbyNode) logicalNode; stack.push(grpNode); leftExec = createPlanRecursive(ctx, grpNode.getChild(), stack); stack.pop(); return createGroupByPlan(ctx, grpNode, leftExec);
GroupbyNode grpNode = (GroupbyNode) logicalNode; stack.push(grpNode); leftExec = createPlanRecursive(ctx, grpNode.getChild(), stack); stack.pop(); return createGroupByPlan(ctx, grpNode, leftExec);
baseDistinctNode.setGroupingColumns(groupbyNode.getGroupingColumns()); baseDistinctNode.setInSchema(groupbyNode.getInSchema()); baseDistinctNode.setChild(groupbyNode.getChild());
baseDistinctNode.setGroupingColumns(groupbyNode.getGroupingColumns()); baseDistinctNode.setInSchema(groupbyNode.getInSchema()); baseDistinctNode.setChild(groupbyNode.getChild());
baseDistinctNode.setGroupingColumns(groupbyNode.getGroupingColumns()); baseDistinctNode.setInSchema(groupbyNode.getInSchema()); baseDistinctNode.setChild(groupbyNode.getChild());
firstStageGroupby.setAggFunctions(firstStageAggFunctions); firstStageGroupby.setTargets(firstStageTargets); firstStageGroupby.setChild(groupbyNode.getChild()); firstStageGroupby.setInSchema(groupbyNode.getInSchema());
firstStageGroupby.setAggFunctions(TUtil.toArray(firstStageAggFunctions, AggregationFunctionCallEval.class)); firstStageGroupby.setTargets(firstStageTargets); firstStageGroupby.setChild(groupbyNode.getChild()); firstStageGroupby.setInSchema(groupbyNode.getInSchema());
static void testQuery7(LogicalNode plan) { assertEquals(NodeType.PROJECTION, plan.getType()); ProjectionNode projNode = (ProjectionNode) plan; assertEquals(NodeType.GROUP_BY, projNode.getChild().getType()); GroupbyNode groupByNode = projNode.getChild(); assertEquals(NodeType.JOIN, groupByNode.getChild().getType()); JoinNode joinNode = groupByNode.getChild(); assertEquals(NodeType.SCAN, joinNode.getLeftChild().getType()); ScanNode leftNode = joinNode.getLeftChild(); assertEquals(IdentifierUtil.buildFQName(DEFAULT_DATABASE_NAME, "dept"), leftNode.getTableName()); assertEquals(NodeType.SCAN, joinNode.getRightChild().getType()); ScanNode rightNode = joinNode.getRightChild(); assertEquals(IdentifierUtil.buildFQName(DEFAULT_DATABASE_NAME, "score"), rightNode.getTableName()); }
@Test public final void testOptimizeWithGroupBy() throws CloneNotSupportedException, TajoException { Expr expr = sqlAnalyzer.parse(QUERIES[3]); LogicalPlan newPlan = planner.createPlan(defaultContext, expr); LogicalNode plan = newPlan.getRootBlock().getRoot(); assertEquals(NodeType.ROOT, plan.getType()); LogicalRootNode root = (LogicalRootNode) plan; TestLogicalPlanner.testCloneLogicalNode(root); assertEquals(NodeType.PROJECTION, root.getChild().getType()); ProjectionNode projNode = root.getChild(); assertEquals(NodeType.GROUP_BY, projNode.getChild().getType()); GroupbyNode groupbyNode = projNode.getChild(); assertEquals(NodeType.SELECTION, groupbyNode.getChild().getType()); SelectionNode selNode = groupbyNode.getChild(); assertEquals(NodeType.SCAN, selNode.getChild().getType()); LogicalNode optimized = optimizer.optimize(newPlan); assertEquals(NodeType.ROOT, optimized.getType()); root = (LogicalRootNode) optimized; TestLogicalPlanner.testCloneLogicalNode(root); assertEquals(NodeType.GROUP_BY, root.getChild().getType()); groupbyNode = root.getChild(); assertEquals(NodeType.SCAN, groupbyNode.getChild().getType()); }