@Override public boolean equals(Object obj) { if (obj instanceof GroupbyNode) { GroupbyNode other = (GroupbyNode) obj; boolean eq = super.equals(other); eq = eq && isDistinct() == other.isDistinct(); eq = eq && TUtil.checkEquals(groupingKeys, other.groupingKeys); eq = eq && TUtil.checkEquals(aggrFunctions, other.aggrFunctions); eq = eq && TUtil.checkEquals(targets, other.targets); return eq; } else { return false; } }
@Override public boolean equals(Object obj) { if (obj instanceof GroupbyNode) { GroupbyNode other = (GroupbyNode) obj; boolean eq = super.equals(other); eq = eq && isDistinct() == other.isDistinct(); eq = eq && TUtil.checkEquals(groupingKeys, other.groupingKeys); eq = eq && TUtil.checkEquals(aggrFunctions, other.aggrFunctions); eq = eq && TUtil.checkEquals(targets, other.targets); return eq; } else { return false; } }
planStr.addDetail("\t").appendDetail("distinct: " + eachNode.isDistinct()) .appendDetail(", " + eachNode.getShortPlanString());
planStr.addDetail("\t").appendDetail("distinct: " + eachNode.isDistinct()) .appendDetail(", " + eachNode.getShortPlanString());
if (eachGroupby.isDistinct()) { aggregatorList.add(new DistinctFinalAggregator(distinctSeq, inTupleIndex, outTupleIndex, eachGroupby)); distinctSeq++;
if (eachGroupby.isDistinct()) { aggregatorList.add(new DistinctFinalAggregator(distinctSeq, inTupleIndex, outTupleIndex, eachGroupby)); distinctSeq++;
if (eachGroupby.isDistinct()) { numDistinct++; } else { distinctKeyIndexes = new int[numDistinct][]; for (GroupbyNode eachGroupby : groupbyNodes) { if (eachGroupby.isDistinct()) { List<Integer> distinctGroupingKeyIndex = new ArrayList<>(); Column[] distinctGroupingColumns = eachGroupby.getGroupingColumns();
@Override public void init() throws IOException { super.init(); // finding grouping column index Column[] groupingKeyColumns = plan.getGroupingColumns(); nonDistinctGroupingKeyProjector = new KeyProjector(inSchema, plan.getGroupingColumns()); resultTupleLength = groupingKeyColumns.length + 1; //1 is Sequence Datum which indicates sequence of DistinctNode. List<GroupbyNode> groupbyNodes = plan.getSubPlans(); int distinctSeq = 0; for (GroupbyNode eachGroupby: groupbyNodes) { if (eachGroupby.isDistinct()) { DistinctHashAggregator aggregator = new DistinctHashAggregator(eachGroupby, distinctSeq); nodeSeqToDistinctAggregators.put(distinctSeq++, aggregator); resultTupleLength += aggregator.getTupleLength(); } else { nonDistinctHashAggregator = new NonDistinctHashAggregator(eachGroupby); resultTupleLength += nonDistinctHashAggregator.getTupleLength(); } } }
@Override public void init() throws IOException { super.init(); // finding grouping column index Column[] groupingKeyColumns = plan.getGroupingColumns(); nonDistinctGroupingKeyProjector = new KeyProjector(inSchema, plan.getGroupingColumns()); resultTupleLength = groupingKeyColumns.length + 1; //1 is Sequence Datum which indicates sequence of DistinctNode. List<GroupbyNode> groupbyNodes = plan.getSubPlans(); int distinctSeq = 0; for (GroupbyNode eachGroupby: groupbyNodes) { if (eachGroupby.isDistinct()) { DistinctHashAggregator aggregator = new DistinctHashAggregator(eachGroupby, distinctSeq); nodeSeqToDistinctAggregators.put(distinctSeq++, aggregator); resultTupleLength += aggregator.getTupleLength(); } else { nonDistinctHashAggregator = new NonDistinctHashAggregator(eachGroupby); resultTupleLength += nonDistinctHashAggregator.getTupleLength(); } } }
if (eachGroupby.isDistinct()) { numDistinct++; } else { distinctKeyIndexes = new int[numDistinct][]; for (GroupbyNode eachGroupby : groupbyNodes) { if (eachGroupby.isDistinct()) { List<Integer> distinctGroupingKeyIndex = new ArrayList<Integer>(); Column[] distinctGroupingColumns = eachGroupby.getGroupingColumns();
private PlanProto.LogicalNode.Builder buildGroupby(SerializeContext context, GroupbyNode node) throws TajoException { int [] childIds = registerGetChildIds(context, node); PlanProto.GroupbyNode.Builder groupbyBuilder = PlanProto.GroupbyNode.newBuilder(); groupbyBuilder.setChildSeq(childIds[0]); groupbyBuilder.setDistinct(node.isDistinct()); if (node.groupingKeyNum() > 0) { groupbyBuilder.addAllGroupingKeys( ProtoUtil.<CatalogProtos.ColumnProto>toProtoObjects(node.getGroupingColumns())); } if (node.hasAggFunctions()) { groupbyBuilder.addAllAggFunctions( ProtoUtil.<PlanProto.EvalNodeTree>toProtoObjects(node.getAggFunctions().toArray(new ProtoObject[node.getAggFunctions().size()]))); } if (node.hasTargets()) { groupbyBuilder.addAllTargets(ProtoUtil.<PlanProto.Target>toProtoObjects(node.getTargets().toArray(new ProtoObject[node.getTargets().size()]))); } PlanProto.LogicalNode.Builder nodeBuilder = createNodeBuilder(context, node); nodeBuilder.setGroupby(groupbyBuilder); return nodeBuilder; }
GroupbyNode secondStageGroupbyNode = secondStageDistinctNode.getSubPlans().get(grpIdx); if (firstStageGroupbyNode.isDistinct()) { if (!lastSecondStageGroupbyNode.isDistinct() && lastSecondStageGroupbyNode.isEmptyGrouping()) { GroupbyNode otherGroupbyNode = lastSecondStageGroupbyNode; lastSecondStageGroupbyNode = secondStageGroupbyNodes.get(secondStageGroupbyNodes.size() - 2); List<Target> firstTargets = new ArrayList<>(); for (GroupbyNode firstStageGroupbyNode: firstStageDistinctNode.getSubPlans()) { if (firstStageGroupbyNode.isDistinct()) { for (Column column : firstStageGroupbyNode.getGroupingColumns()) { Target firstTarget = new Target(new FieldEval(column));
GroupbyNode secondStageGroupbyNode = secondStageDistinctNode.getSubPlans().get(grpIdx); if (firstStageGroupbyNode.isDistinct()) { if (!lastSecondStageGroupbyNode.isDistinct() && lastSecondStageGroupbyNode.isEmptyGrouping()) { GroupbyNode otherGroupbyNode = lastSecondStageGroupbyNode; lastSecondStageGroupbyNode = secondStageGroupbyNodes.get(secondStageGroupbyNodes.size() - 2); List<Target> firstTargets = new ArrayList<Target>(); for (GroupbyNode firstStageGroupbyNode: firstStageDistinctNode.getSubPlans()) { if (firstStageGroupbyNode.isDistinct()) { for (Column column : firstStageGroupbyNode.getGroupingColumns()) { Target firstTarget = new Target(new FieldEval(column));
if (!lastGroupbyNode.isDistinct()) { int index = 0; for (AggregationFunctionCallEval aggrFunction: lastGroupbyNode.getAggFunctions()) { if (!lastGroupbyNode.isDistinct()) { int index = 0; for (AggregationFunctionCallEval aggrFunction: lastGroupbyNode.getAggFunctions()) {
private ExecutionBlock buildGroupBy(GlobalPlanContext context, ExecutionBlock lastBlock, GroupbyNode groupbyNode) throws TajoException { MasterPlan masterPlan = context.plan; ExecutionBlock currentBlock; if (groupbyNode.isDistinct()) { // if there is at one distinct aggregation function boolean multiLevelEnabled = context.getPlan().getContext().getBool(SessionVars.GROUPBY_MULTI_LEVEL_ENABLED); if (multiLevelEnabled) { if (PlannerUtil.findTopNode(groupbyNode, NodeType.UNION) == null) { DistinctGroupbyBuilder builder = new DistinctGroupbyBuilder(this); return builder.buildMultiLevelPlan(context, lastBlock, groupbyNode); } else { DistinctGroupbyBuilder builder = new DistinctGroupbyBuilder(this); return builder.buildPlan(context, lastBlock, groupbyNode); } } else { DistinctGroupbyBuilder builder = new DistinctGroupbyBuilder(this); return builder.buildPlan(context, lastBlock, groupbyNode); } } else { GroupbyNode firstPhaseGroupby = createFirstPhaseGroupBy(masterPlan.getLogicalPlan(), groupbyNode); if (hasUnionChild(firstPhaseGroupby)) { currentBlock = buildGroupbyAndUnionPlan(masterPlan, lastBlock, firstPhaseGroupby, groupbyNode); } else { // general hash-shuffled aggregation currentBlock = buildTwoPhaseGroupby(masterPlan, lastBlock, firstPhaseGroupby, groupbyNode); } } return currentBlock; }
private ExecutionBlock buildGroupBy(GlobalPlanContext context, ExecutionBlock lastBlock, GroupbyNode groupbyNode) throws TajoException { MasterPlan masterPlan = context.plan; ExecutionBlock currentBlock; if (groupbyNode.isDistinct()) { // if there is at one distinct aggregation function boolean multiLevelEnabled = context.getPlan().getContext().getBool(SessionVars.GROUPBY_MULTI_LEVEL_ENABLED); if (multiLevelEnabled) { if (PlannerUtil.findTopNode(groupbyNode, NodeType.UNION) == null) { DistinctGroupbyBuilder builder = new DistinctGroupbyBuilder(this); return builder.buildMultiLevelPlan(context, lastBlock, groupbyNode); } else { DistinctGroupbyBuilder builder = new DistinctGroupbyBuilder(this); return builder.buildPlan(context, lastBlock, groupbyNode); } } else { DistinctGroupbyBuilder builder = new DistinctGroupbyBuilder(this); return builder.buildPlan(context, lastBlock, groupbyNode); } } else { GroupbyNode firstPhaseGroupby = createFirstPhaseGroupBy(masterPlan.getLogicalPlan(), groupbyNode); if (hasUnionChild(firstPhaseGroupby)) { currentBlock = buildGroupbyAndUnionPlan(masterPlan, lastBlock, firstPhaseGroupby, groupbyNode); } else { // general hash-shuffled aggregation currentBlock = buildTwoPhaseGroupby(masterPlan, lastBlock, firstPhaseGroupby, groupbyNode); } } return currentBlock; }
private PlanProto.LogicalNode.Builder buildGroupby(SerializeContext context, GroupbyNode node) throws TajoException { int [] childIds = registerGetChildIds(context, node); PlanProto.GroupbyNode.Builder groupbyBuilder = PlanProto.GroupbyNode.newBuilder(); groupbyBuilder.setChildSeq(childIds[0]); groupbyBuilder.setDistinct(node.isDistinct()); if (node.groupingKeyNum() > 0) { groupbyBuilder.addAllGroupingKeys( ProtoUtil.<CatalogProtos.ColumnProto>toProtoObjects(node.getGroupingColumns())); } if (node.hasAggFunctions()) { groupbyBuilder.addAllAggFunctions( ProtoUtil.<PlanProto.EvalNodeTree>toProtoObjects(node.getAggFunctions())); } if (node.hasTargets()) { groupbyBuilder.addAllTargets(ProtoUtil.<PlanProto.Target>toProtoObjects(node.getTargets())); } PlanProto.LogicalNode.Builder nodeBuilder = createNodeBuilder(context, node); nodeBuilder.setGroupby(groupbyBuilder); return nodeBuilder; }
if (!lastGroupbyNode.isDistinct()) { int index = 0; for (AggregationFunctionCallEval aggrFunction: lastGroupbyNode.getAggFunctions()) { if (!lastGroupbyNode.isDistinct()) { int index = 0; for (AggregationFunctionCallEval aggrFunction: lastGroupbyNode.getAggFunctions()) {