Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: CoGroup SolutionSetFirst #10

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public boolean areCoFulfilled(RequestedLocalProperties requested1, RequestedLoca

@Override
public DualInputPlanNode instantiate(Channel in1, Channel in2, TwoInputNode node) {
boolean[] inputOrders = in1.getLocalProperties().getOrdering().getFieldSortDirections();
boolean[] inputOrders = in1.getLocalProperties().getOrdering() == null ? null : in1.getLocalProperties().getOrdering().getFieldSortDirections();

if (inputOrders == null || inputOrders.length < this.keys1.size()) {
throw new CompilerException("BUG: The input strategy does not sufficiently describe the sort orders for a CoGroup operator.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@
import java.util.List;

import eu.stratosphere.api.common.operators.util.FieldList;
import eu.stratosphere.compiler.CompilerException;
import eu.stratosphere.compiler.dag.TwoInputNode;
import eu.stratosphere.compiler.dataproperties.LocalProperties;
import eu.stratosphere.compiler.dataproperties.RequestedLocalProperties;
import eu.stratosphere.compiler.plan.Channel;
import eu.stratosphere.compiler.plan.DualInputPlanNode;
import eu.stratosphere.compiler.util.Utils;
import eu.stratosphere.pact.runtime.task.DriverStrategy;

/**
*
Expand All @@ -36,7 +41,22 @@ protected List<LocalPropertiesPair> createPossibleLocalProperties() {
RequestedLocalProperties sort = new RequestedLocalProperties(Utils.createOrdering(this.keys2));
return Collections.singletonList(new LocalPropertiesPair(none, sort));
}


@Override
public DualInputPlanNode instantiate(Channel in1, Channel in2, TwoInputNode node) {
boolean[] inputOrders = in2.getLocalProperties().getOrdering() == null ? null : in2.getLocalProperties().getOrdering().getFieldSortDirections();

if (inputOrders == null || inputOrders.length < this.keys2.size()) {
throw new CompilerException("BUG: The input strategy does not sufficiently describe the sort orders for a CoGroup operator.");
} else if (inputOrders.length > this.keys2.size()) {
boolean[] tmp = new boolean[this.keys2.size()];
System.arraycopy(inputOrders, 0, tmp, 0, tmp.length);
inputOrders = tmp;
}

return new DualInputPlanNode(node, "CoGroup ("+node.getPactContract().getName()+")", in1, in2, DriverStrategy.CO_GROUP, this.keys1, this.keys2, inputOrders);
}

@Override
public boolean areCoFulfilled(RequestedLocalProperties requested1, RequestedLocalProperties requested2,
LocalProperties produced1, LocalProperties produced2)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/***********************************************************************************************************************
* Copyright (C) 2010-2013 by the Stratosphere project (http://stratosphere.eu)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
**********************************************************************************************************************/

package eu.stratosphere.pact.compiler;

import eu.stratosphere.api.common.Plan;
import eu.stratosphere.api.java.DataSet;
import eu.stratosphere.api.java.DeltaIteration;
import eu.stratosphere.api.java.ExecutionEnvironment;
import eu.stratosphere.api.java.functions.CoGroupFunction;
import eu.stratosphere.api.java.functions.MapFunction;
import eu.stratosphere.api.java.tuple.Tuple1;
import eu.stratosphere.compiler.CompilerException;
import eu.stratosphere.compiler.plan.Channel;
import eu.stratosphere.compiler.plan.DualInputPlanNode;
import eu.stratosphere.compiler.plan.OptimizedPlan;
import eu.stratosphere.compiler.plan.PlanNode;
import eu.stratosphere.compiler.plan.WorksetIterationPlanNode;
import eu.stratosphere.pact.runtime.shipping.ShipStrategyType;
import eu.stratosphere.util.Collector;
import eu.stratosphere.util.Visitor;
import org.junit.Assert;
import org.junit.Test;

import java.util.Iterator;

public class CoGroupSolutionSetFirstTest extends CompilerTestBase {
public static class SimpleCGroup extends CoGroupFunction<Tuple1<Integer>, Tuple1<Integer>, Tuple1<Integer>> {
@Override
public void coGroup(Iterator<Tuple1<Integer>> first, Iterator<Tuple1<Integer>> second, Collector<Tuple1<Integer>> out) throws Exception {
}
}

public static class SimpleMap extends MapFunction<Tuple1<Integer>, Tuple1<Integer>> {
@Override
public Tuple1<Integer> map(Tuple1<Integer> value) throws Exception {
return null;
}
}

@Test
public void testCoGroupSolutionSet() {
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple1<Integer>> raw = env.readCsvFile(IN_FILE).types(Integer.class);

DeltaIteration<Tuple1<Integer>, Tuple1<Integer>> iteration = raw.iterateDelta(raw, 1000, 0);

DataSet<Tuple1<Integer>> test = iteration.getWorkset().map(new SimpleMap());
DataSet<Tuple1<Integer>> delta = iteration.getSolutionSet().coGroup(test).where(0).equalTo(0).with(new SimpleCGroup());
DataSet<Tuple1<Integer>> feedback = iteration.getWorkset().map(new SimpleMap());
DataSet<Tuple1<Integer>> result = iteration.closeWith(delta, feedback);

result.print();

Plan plan = env.createProgramPlan();
OptimizedPlan oPlan = null;
try {
oPlan = compileNoStats(plan);
} catch(CompilerException e) {
Assert.fail(e.getMessage());
}

oPlan.accept(new Visitor<PlanNode>() {
@Override
public boolean preVisit(PlanNode visitable) {
System.out.println(visitable);
if (visitable instanceof WorksetIterationPlanNode) {
PlanNode deltaNode = ((WorksetIterationPlanNode) visitable).getSolutionSetDeltaPlanNode();

//get the CoGroup
DualInputPlanNode dpn = (DualInputPlanNode) deltaNode.getInputs().next().getSource();
Channel in1 = dpn.getInput1();
Channel in2 = dpn.getInput2();

Assert.assertTrue(in1.getLocalProperties().getOrdering() == null);
Assert.assertTrue(in2.getLocalProperties().getOrdering() != null);
Assert.assertTrue(in2.getLocalProperties().getOrdering().getInvolvedIndexes().contains(0));
Assert.assertTrue(in1.getShipStrategy() == ShipStrategyType.FORWARD);
Assert.assertTrue(in2.getShipStrategy() == ShipStrategyType.PARTITION_HASH);
return false;
}
return true;
}

@Override
public void postVisit(PlanNode visitable) {

}
});

}

}