
eu.stratosphere.compiler.dag.CrossNode Maven / Gradle / Ivy
/***********************************************************************************************************************
* 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.compiler.dag;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import eu.stratosphere.api.common.operators.base.CrossOperatorBase;
import eu.stratosphere.api.common.operators.util.FieldSet;
import eu.stratosphere.compiler.CompilerException;
import eu.stratosphere.compiler.PactCompiler;
import eu.stratosphere.compiler.operators.CrossBlockOuterFirstDescriptor;
import eu.stratosphere.compiler.operators.CrossBlockOuterSecondDescriptor;
import eu.stratosphere.compiler.operators.CrossStreamOuterFirstDescriptor;
import eu.stratosphere.compiler.operators.CrossStreamOuterSecondDescriptor;
import eu.stratosphere.compiler.operators.OperatorDescriptorDual;
import eu.stratosphere.configuration.Configuration;
/**
* The Optimizer representation of a Cross contract node.
*/
public class CrossNode extends TwoInputNode {
/**
* Creates a new CrossNode for the given contract.
*
* @param pactContract The Cross contract object.
*/
public CrossNode(CrossOperatorBase> pactContract) {
super(pactContract);
}
// ------------------------------------------------------------------------
/**
* Gets the contract object for this Cross node.
*
* @return The contract.
*/
@Override
public CrossOperatorBase> getPactContract() {
return (CrossOperatorBase>) super.getPactContract();
}
@Override
public String getName() {
return "Cross";
}
@Override
protected List getPossibleProperties() {
CrossOperatorBase> operation = getPactContract();
if (operation instanceof CrossOperatorBase.CrossWithSmall) {
ArrayList list = new ArrayList();
list.add(new CrossBlockOuterSecondDescriptor(false, true));
list.add(new CrossStreamOuterFirstDescriptor(false, true));
return list;
}
else if (operation instanceof CrossOperatorBase.CrossWithLarge) {
ArrayList list = new ArrayList();
list.add(new CrossBlockOuterFirstDescriptor(true, false));
list.add(new CrossStreamOuterSecondDescriptor(true, false));
return list;
}
else {
Configuration conf = operation.getParameters();
String localStrategy = conf.getString(PactCompiler.HINT_LOCAL_STRATEGY, null);
if (localStrategy != null) {
final OperatorDescriptorDual fixedDriverStrat;
if (PactCompiler.HINT_LOCAL_STRATEGY_NESTEDLOOP_BLOCKED_OUTER_FIRST.equals(localStrategy)) {
fixedDriverStrat = new CrossBlockOuterFirstDescriptor();
} else if (PactCompiler.HINT_LOCAL_STRATEGY_NESTEDLOOP_BLOCKED_OUTER_SECOND.equals(localStrategy)) {
fixedDriverStrat = new CrossBlockOuterSecondDescriptor();
} else if (PactCompiler.HINT_LOCAL_STRATEGY_NESTEDLOOP_STREAMED_OUTER_FIRST.equals(localStrategy)) {
fixedDriverStrat = new CrossStreamOuterFirstDescriptor();
} else if (PactCompiler.HINT_LOCAL_STRATEGY_NESTEDLOOP_STREAMED_OUTER_SECOND.equals(localStrategy)) {
fixedDriverStrat = new CrossStreamOuterSecondDescriptor();
} else {
throw new CompilerException("Invalid local strategy hint for cross contract: " + localStrategy);
}
return Collections.singletonList(fixedDriverStrat);
} else {
ArrayList list = new ArrayList();
list.add(new CrossBlockOuterFirstDescriptor());
list.add(new CrossBlockOuterSecondDescriptor());
list.add(new CrossStreamOuterFirstDescriptor());
list.add(new CrossStreamOuterSecondDescriptor());
return list;
}
}
}
/**
* Computes the number of keys that are processed by the PACT.
*
* @return the number of keys processed by the PACT.
*/
protected long computeNumberOfProcessedKeys() {
// Match processes only keys that appear in both input sets
FieldSet fieldSet1 = new FieldSet(getPactContract().getKeyColumns(0));
FieldSet fieldSet2 = new FieldSet(getPactContract().getKeyColumns(1));
long numKey1 = this.getFirstPredecessorNode().getEstimatedCardinality(fieldSet1);
long numKey2 = this.getSecondPredecessorNode().getEstimatedCardinality(fieldSet2);
if(numKey1 == -1 || numKey2 == -1)
return -1;
return numKey1 * numKey2;
}
/**
* Computes the number of stub calls.
*
* @return the number of stub calls.
*/
protected long computeNumberOfStubCalls() {
long numRecords1 = this.getFirstPredecessorNode().estimatedNumRecords;
if(numRecords1 == -1) {
return -1;
}
long numRecords2 = this.getSecondPredecessorNode().estimatedNumRecords;
if(numRecords2 == -1) {
return -1;
}
return numRecords1 * numRecords2;
}
public boolean keepsUniqueProperty(FieldSet uniqueSet, int input) {
return false;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy