Java Code Examples for org.apache.flink.runtime.operators.shipping.ShipStrategyType#PARTITION_RANGE

The following examples show how to use org.apache.flink.runtime.operators.shipping.ShipStrategyType#PARTITION_RANGE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RangePartitionRewriter.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void postVisit(PlanNode node) {

	if(node instanceof IterationPlanNode) {
		IterationPlanNode iNode = (IterationPlanNode)node;
		if(!visitedIterationNodes.contains(iNode)) {
			visitedIterationNodes.add(iNode);
			iNode.acceptForStepFunction(this);
		}
	}

	final Iterable<Channel> inputChannels = node.getInputs();
	for (Channel channel : inputChannels) {
		ShipStrategyType shipStrategy = channel.getShipStrategy();
		// Make sure we only optimize the DAG for range partition, and do not optimize multi times.
		if (shipStrategy == ShipStrategyType.PARTITION_RANGE) {

			if(channel.getDataDistribution() == null) {
				if (node.isOnDynamicPath()) {
					throw new InvalidProgramException("Range Partitioning not supported within iterations if users do not supply the data distribution.");
				}

				PlanNode channelSource = channel.getSource();
				List<Channel> newSourceOutputChannels = rewriteRangePartitionChannel(channel);
				channelSource.getOutgoingChannels().remove(channel);
				channelSource.getOutgoingChannels().addAll(newSourceOutputChannels);
			}
		}
	}
}
 
Example 2
Source File: RangePartitionRewriter.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void postVisit(PlanNode node) {

	if(node instanceof IterationPlanNode) {
		IterationPlanNode iNode = (IterationPlanNode)node;
		if(!visitedIterationNodes.contains(iNode)) {
			visitedIterationNodes.add(iNode);
			iNode.acceptForStepFunction(this);
		}
	}

	final Iterable<Channel> inputChannels = node.getInputs();
	for (Channel channel : inputChannels) {
		ShipStrategyType shipStrategy = channel.getShipStrategy();
		// Make sure we only optimize the DAG for range partition, and do not optimize multi times.
		if (shipStrategy == ShipStrategyType.PARTITION_RANGE) {

			if(channel.getDataDistribution() == null) {
				if (node.isOnDynamicPath()) {
					throw new InvalidProgramException("Range Partitioning not supported within iterations if users do not supply the data distribution.");
				}

				PlanNode channelSource = channel.getSource();
				List<Channel> newSourceOutputChannels = rewriteRangePartitionChannel(channel);
				channelSource.getOutgoingChannels().remove(channel);
				channelSource.getOutgoingChannels().addAll(newSourceOutputChannels);
			}
		}
	}
}
 
Example 3
Source File: RangePartitionRewriter.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void postVisit(PlanNode node) {

	if(node instanceof IterationPlanNode) {
		IterationPlanNode iNode = (IterationPlanNode)node;
		if(!visitedIterationNodes.contains(iNode)) {
			visitedIterationNodes.add(iNode);
			iNode.acceptForStepFunction(this);
		}
	}

	final Iterable<Channel> inputChannels = node.getInputs();
	for (Channel channel : inputChannels) {
		ShipStrategyType shipStrategy = channel.getShipStrategy();
		// Make sure we only optimize the DAG for range partition, and do not optimize multi times.
		if (shipStrategy == ShipStrategyType.PARTITION_RANGE) {

			if(channel.getDataDistribution() == null) {
				if (node.isOnDynamicPath()) {
					throw new InvalidProgramException("Range Partitioning not supported within iterations if users do not supply the data distribution.");
				}

				PlanNode channelSource = channel.getSource();
				List<Channel> newSourceOutputChannels = rewriteRangePartitionChannel(channel);
				channelSource.getOutgoingChannels().remove(channel);
				channelSource.getOutgoingChannels().addAll(newSourceOutputChannels);
			}
		}
	}
}
 
Example 4
Source File: GroupReduceWithCombineProperties.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public SingleInputPlanNode instantiate(Channel in, SingleInputNode node) {
	if (in.getShipStrategy() == ShipStrategyType.FORWARD) {
		if(in.getSource().getOptimizerNode() instanceof PartitionNode) {
			LOG.warn("Cannot automatically inject combiner for GroupReduceFunction. Please add an explicit combiner with combineGroup() in front of the partition operator.");
		}
		// adjust a sort (changes grouping, so it must be for this driver to combining sort
		if (in.getLocalStrategy() == LocalStrategy.SORT) {
			if (!in.getLocalStrategyKeys().isValidUnorderedPrefix(this.keys)) {
				throw new RuntimeException("Bug: Inconsistent sort for group strategy.");
			}
			in.setLocalStrategy(LocalStrategy.COMBININGSORT, in.getLocalStrategyKeys(),
								in.getLocalStrategySortOrder());
		}
		return new SingleInputPlanNode(node, "Reduce ("+node.getOperator().getName()+")", in,
										DriverStrategy.SORTED_GROUP_REDUCE, this.keyList);
	} else {
		// non forward case. all local properties are killed anyways, so we can safely plug in a combiner
		Channel toCombiner = new Channel(in.getSource());
		toCombiner.setShipStrategy(ShipStrategyType.FORWARD, DataExchangeMode.PIPELINED);

		// create an input node for combine with same parallelism as input node
		GroupReduceNode combinerNode = ((GroupReduceNode) node).getCombinerUtilityNode();
		combinerNode.setParallelism(in.getSource().getParallelism());

		SingleInputPlanNode combiner = new SingleInputPlanNode(combinerNode, "Combine ("+node.getOperator()
				.getName()+")", toCombiner, DriverStrategy.SORTED_GROUP_COMBINE);
		combiner.setCosts(new Costs(0, 0));
		combiner.initProperties(toCombiner.getGlobalProperties(), toCombiner.getLocalProperties());
		// set sorting comparator key info
		combiner.setDriverKeyInfo(in.getLocalStrategyKeys(), in.getLocalStrategySortOrder(), 0);
		// set grouping comparator key info
		combiner.setDriverKeyInfo(this.keyList, 1);
		
		Channel toReducer = new Channel(combiner);
		toReducer.setShipStrategy(in.getShipStrategy(), in.getShipStrategyKeys(),
								in.getShipStrategySortOrder(), in.getDataExchangeMode());
		if (in.getShipStrategy() == ShipStrategyType.PARTITION_RANGE) {
			toReducer.setDataDistribution(in.getDataDistribution());
		}
		toReducer.setLocalStrategy(LocalStrategy.COMBININGSORT, in.getLocalStrategyKeys(),
									in.getLocalStrategySortOrder());

		return new SingleInputPlanNode(node, "Reduce ("+node.getOperator().getName()+")",
										toReducer, DriverStrategy.SORTED_GROUP_REDUCE, this.keyList);
	}
}
 
Example 5
Source File: GlobalProperties.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public void parameterizeChannel(Channel channel, boolean globalDopChange,
								ExecutionMode exchangeMode, boolean breakPipeline) {

	ShipStrategyType shipType;
	FieldList partitionKeys;
	boolean[] sortDirection;
	Partitioner<?> partitioner;

	switch (this.partitioning) {
		case RANDOM_PARTITIONED:
			shipType = globalDopChange ? ShipStrategyType.PARTITION_RANDOM : ShipStrategyType.FORWARD;
			partitionKeys = null;
			sortDirection = null;
			partitioner = null;
			break;

		case FULL_REPLICATION:
			shipType = ShipStrategyType.BROADCAST;
			partitionKeys = null;
			sortDirection = null;
			partitioner = null;
			break;

		case ANY_PARTITIONING:
		case HASH_PARTITIONED:
			shipType = ShipStrategyType.PARTITION_HASH;
			partitionKeys = Utils.createOrderedFromSet(this.partitioningFields);
			sortDirection = null;
			partitioner = null;
			break;

		case RANGE_PARTITIONED:
			shipType = ShipStrategyType.PARTITION_RANGE;
			partitionKeys = this.ordering.getInvolvedIndexes();
			sortDirection = this.ordering.getFieldSortDirections();
			partitioner = null;
			break;

		case FORCED_REBALANCED:
			shipType = ShipStrategyType.PARTITION_RANDOM;
			partitionKeys = null;
			sortDirection = null;
			partitioner = null;
			break;

		case CUSTOM_PARTITIONING:
			shipType = ShipStrategyType.PARTITION_CUSTOM;
			partitionKeys = this.partitioningFields;
			sortDirection = null;
			partitioner = this.customPartitioner;
			break;

		default:
			throw new CompilerException("Unsupported partitioning strategy");
	}

	channel.setDataDistribution(this.distribution);
	DataExchangeMode exMode = DataExchangeMode.select(exchangeMode, shipType, breakPipeline);
	channel.setShipStrategy(shipType, partitionKeys, sortDirection, partitioner, exMode);
}
 
Example 6
Source File: SingleInputNode.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void setInput(Map<Operator<?>, OptimizerNode> contractToNode, ExecutionMode defaultExchangeMode)
		throws CompilerException
{
	// see if an internal hint dictates the strategy to use
	final Configuration conf = getOperator().getParameters();
	final String shipStrategy = conf.getString(Optimizer.HINT_SHIP_STRATEGY, null);
	final ShipStrategyType preSet;
	
	if (shipStrategy != null) {
		if (shipStrategy.equalsIgnoreCase(Optimizer.HINT_SHIP_STRATEGY_REPARTITION_HASH)) {
			preSet = ShipStrategyType.PARTITION_HASH;
		} else if (shipStrategy.equalsIgnoreCase(Optimizer.HINT_SHIP_STRATEGY_REPARTITION_RANGE)) {
			preSet = ShipStrategyType.PARTITION_RANGE;
		} else if (shipStrategy.equalsIgnoreCase(Optimizer.HINT_SHIP_STRATEGY_FORWARD)) {
			preSet = ShipStrategyType.FORWARD;
		} else if (shipStrategy.equalsIgnoreCase(Optimizer.HINT_SHIP_STRATEGY_REPARTITION)) {
			preSet = ShipStrategyType.PARTITION_RANDOM;
		} else {
			throw new CompilerException("Unrecognized ship strategy hint: " + shipStrategy);
		}
	} else {
		preSet = null;
	}
	
	// get the predecessor node
	Operator<?> children = ((SingleInputOperator<?, ?, ?>) getOperator()).getInput();
	
	OptimizerNode pred;
	DagConnection conn;
	if (children == null) {
		throw new CompilerException("Error: Node for '" + getOperator().getName() + "' has no input.");
	} else {
		pred = contractToNode.get(children);
		conn = new DagConnection(pred, this, defaultExchangeMode);
		if (preSet != null) {
			conn.setShipStrategy(preSet);
		}
	}
	
	// create the connection and add it
	setIncomingConnection(conn);
	pred.addOutgoingConnection(conn);
}
 
Example 7
Source File: TwoInputNode.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void setInput(Map<Operator<?>, OptimizerNode> contractToNode, ExecutionMode defaultExecutionMode) {
	// see if there is a hint that dictates which shipping strategy to use for BOTH inputs
	final Configuration conf = getOperator().getParameters();
	ShipStrategyType preSet1 = null;
	ShipStrategyType preSet2 = null;
	
	String shipStrategy = conf.getString(Optimizer.HINT_SHIP_STRATEGY, null);
	if (shipStrategy != null) {
		if (Optimizer.HINT_SHIP_STRATEGY_FORWARD.equals(shipStrategy)) {
			preSet1 = preSet2 = ShipStrategyType.FORWARD;
		} else if (Optimizer.HINT_SHIP_STRATEGY_BROADCAST.equals(shipStrategy)) {
			preSet1 = preSet2 = ShipStrategyType.BROADCAST;
		} else if (Optimizer.HINT_SHIP_STRATEGY_REPARTITION_HASH.equals(shipStrategy)) {
			preSet1 = preSet2 = ShipStrategyType.PARTITION_HASH;
		} else if (Optimizer.HINT_SHIP_STRATEGY_REPARTITION_RANGE.equals(shipStrategy)) {
			preSet1 = preSet2 = ShipStrategyType.PARTITION_RANGE;
		} else if (shipStrategy.equalsIgnoreCase(Optimizer.HINT_SHIP_STRATEGY_REPARTITION)) {
			preSet1 = preSet2 = ShipStrategyType.PARTITION_RANDOM;
		} else {
			throw new CompilerException("Unknown hint for shipping strategy: " + shipStrategy);
		}
	}

	// see if there is a hint that dictates which shipping strategy to use for the FIRST input
	shipStrategy = conf.getString(Optimizer.HINT_SHIP_STRATEGY_FIRST_INPUT, null);
	if (shipStrategy != null) {
		if (Optimizer.HINT_SHIP_STRATEGY_FORWARD.equals(shipStrategy)) {
			preSet1 = ShipStrategyType.FORWARD;
		} else if (Optimizer.HINT_SHIP_STRATEGY_BROADCAST.equals(shipStrategy)) {
			preSet1 = ShipStrategyType.BROADCAST;
		} else if (Optimizer.HINT_SHIP_STRATEGY_REPARTITION_HASH.equals(shipStrategy)) {
			preSet1 = ShipStrategyType.PARTITION_HASH;
		} else if (Optimizer.HINT_SHIP_STRATEGY_REPARTITION_RANGE.equals(shipStrategy)) {
			preSet1 = ShipStrategyType.PARTITION_RANGE;
		} else if (shipStrategy.equalsIgnoreCase(Optimizer.HINT_SHIP_STRATEGY_REPARTITION)) {
			preSet1 = ShipStrategyType.PARTITION_RANDOM;
		} else {
			throw new CompilerException("Unknown hint for shipping strategy of input one: " + shipStrategy);
		}
	}

	// see if there is a hint that dictates which shipping strategy to use for the SECOND input
	shipStrategy = conf.getString(Optimizer.HINT_SHIP_STRATEGY_SECOND_INPUT, null);
	if (shipStrategy != null) {
		if (Optimizer.HINT_SHIP_STRATEGY_FORWARD.equals(shipStrategy)) {
			preSet2 = ShipStrategyType.FORWARD;
		} else if (Optimizer.HINT_SHIP_STRATEGY_BROADCAST.equals(shipStrategy)) {
			preSet2 = ShipStrategyType.BROADCAST;
		} else if (Optimizer.HINT_SHIP_STRATEGY_REPARTITION_HASH.equals(shipStrategy)) {
			preSet2 = ShipStrategyType.PARTITION_HASH;
		} else if (Optimizer.HINT_SHIP_STRATEGY_REPARTITION_RANGE.equals(shipStrategy)) {
			preSet2 = ShipStrategyType.PARTITION_RANGE;
		} else if (shipStrategy.equalsIgnoreCase(Optimizer.HINT_SHIP_STRATEGY_REPARTITION)) {
			preSet2 = ShipStrategyType.PARTITION_RANDOM;
		} else {
			throw new CompilerException("Unknown hint for shipping strategy of input two: " + shipStrategy);
		}
	}
	
	// get the predecessors
	DualInputOperator<?, ?, ?, ?> contr = getOperator();
	
	Operator<?> leftPred = contr.getFirstInput();
	Operator<?> rightPred = contr.getSecondInput();
	
	OptimizerNode pred1;
	DagConnection conn1;
	if (leftPred == null) {
		throw new CompilerException("Error: Node for '" + getOperator().getName() + "' has no input set for first input.");
	} else {
		pred1 = contractToNode.get(leftPred);
		conn1 = new DagConnection(pred1, this, defaultExecutionMode);
		if (preSet1 != null) {
			conn1.setShipStrategy(preSet1);
		}
	} 
	
	// create the connection and add it
	this.input1 = conn1;
	pred1.addOutgoingConnection(conn1);
	
	OptimizerNode pred2;
	DagConnection conn2;
	if (rightPred == null) {
		throw new CompilerException("Error: Node for '" + getOperator().getName() + "' has no input set for second input.");
	} else {
		pred2 = contractToNode.get(rightPred);
		conn2 = new DagConnection(pred2, this, defaultExecutionMode);
		if (preSet2 != null) {
			conn2.setShipStrategy(preSet2);
		}
	}
	
	// create the connection and add it
	this.input2 = conn2;
	pred2.addOutgoingConnection(conn2);
}
 
Example 8
Source File: GroupReduceWithCombineProperties.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public SingleInputPlanNode instantiate(Channel in, SingleInputNode node) {
	if (in.getShipStrategy() == ShipStrategyType.FORWARD) {
		if(in.getSource().getOptimizerNode() instanceof PartitionNode) {
			LOG.warn("Cannot automatically inject combiner for GroupReduceFunction. Please add an explicit combiner with combineGroup() in front of the partition operator.");
		}
		// adjust a sort (changes grouping, so it must be for this driver to combining sort
		if (in.getLocalStrategy() == LocalStrategy.SORT) {
			if (!in.getLocalStrategyKeys().isValidUnorderedPrefix(this.keys)) {
				throw new RuntimeException("Bug: Inconsistent sort for group strategy.");
			}
			in.setLocalStrategy(LocalStrategy.COMBININGSORT, in.getLocalStrategyKeys(),
								in.getLocalStrategySortOrder());
		}
		return new SingleInputPlanNode(node, "Reduce ("+node.getOperator().getName()+")", in,
										DriverStrategy.SORTED_GROUP_REDUCE, this.keyList);
	} else {
		// non forward case. all local properties are killed anyways, so we can safely plug in a combiner
		Channel toCombiner = new Channel(in.getSource());
		toCombiner.setShipStrategy(ShipStrategyType.FORWARD, DataExchangeMode.PIPELINED);

		// create an input node for combine with same parallelism as input node
		GroupReduceNode combinerNode = ((GroupReduceNode) node).getCombinerUtilityNode();
		combinerNode.setParallelism(in.getSource().getParallelism());

		SingleInputPlanNode combiner = new SingleInputPlanNode(combinerNode, "Combine ("+node.getOperator()
				.getName()+")", toCombiner, DriverStrategy.SORTED_GROUP_COMBINE);
		combiner.setCosts(new Costs(0, 0));
		combiner.initProperties(toCombiner.getGlobalProperties(), toCombiner.getLocalProperties());
		// set sorting comparator key info
		combiner.setDriverKeyInfo(in.getLocalStrategyKeys(), in.getLocalStrategySortOrder(), 0);
		// set grouping comparator key info
		combiner.setDriverKeyInfo(this.keyList, 1);
		
		Channel toReducer = new Channel(combiner);
		toReducer.setShipStrategy(in.getShipStrategy(), in.getShipStrategyKeys(),
								in.getShipStrategySortOrder(), in.getDataExchangeMode());
		if (in.getShipStrategy() == ShipStrategyType.PARTITION_RANGE) {
			toReducer.setDataDistribution(in.getDataDistribution());
		}
		toReducer.setLocalStrategy(LocalStrategy.COMBININGSORT, in.getLocalStrategyKeys(),
									in.getLocalStrategySortOrder());

		return new SingleInputPlanNode(node, "Reduce ("+node.getOperator().getName()+")",
										toReducer, DriverStrategy.SORTED_GROUP_REDUCE, this.keyList);
	}
}
 
Example 9
Source File: GlobalProperties.java    From flink with Apache License 2.0 4 votes vote down vote up
public void parameterizeChannel(Channel channel, boolean globalDopChange,
								ExecutionMode exchangeMode, boolean breakPipeline) {

	ShipStrategyType shipType;
	FieldList partitionKeys;
	boolean[] sortDirection;
	Partitioner<?> partitioner;

	switch (this.partitioning) {
		case RANDOM_PARTITIONED:
			shipType = globalDopChange ? ShipStrategyType.PARTITION_RANDOM : ShipStrategyType.FORWARD;
			partitionKeys = null;
			sortDirection = null;
			partitioner = null;
			break;

		case FULL_REPLICATION:
			shipType = ShipStrategyType.BROADCAST;
			partitionKeys = null;
			sortDirection = null;
			partitioner = null;
			break;

		case ANY_PARTITIONING:
		case HASH_PARTITIONED:
			shipType = ShipStrategyType.PARTITION_HASH;
			partitionKeys = Utils.createOrderedFromSet(this.partitioningFields);
			sortDirection = null;
			partitioner = null;
			break;

		case RANGE_PARTITIONED:
			shipType = ShipStrategyType.PARTITION_RANGE;
			partitionKeys = this.ordering.getInvolvedIndexes();
			sortDirection = this.ordering.getFieldSortDirections();
			partitioner = null;
			break;

		case FORCED_REBALANCED:
			shipType = ShipStrategyType.PARTITION_RANDOM;
			partitionKeys = null;
			sortDirection = null;
			partitioner = null;
			break;

		case CUSTOM_PARTITIONING:
			shipType = ShipStrategyType.PARTITION_CUSTOM;
			partitionKeys = this.partitioningFields;
			sortDirection = null;
			partitioner = this.customPartitioner;
			break;

		default:
			throw new CompilerException("Unsupported partitioning strategy");
	}

	channel.setDataDistribution(this.distribution);
	DataExchangeMode exMode = DataExchangeMode.select(exchangeMode, shipType, breakPipeline);
	channel.setShipStrategy(shipType, partitionKeys, sortDirection, partitioner, exMode);
}
 
Example 10
Source File: SingleInputNode.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void setInput(Map<Operator<?>, OptimizerNode> contractToNode, ExecutionMode defaultExchangeMode)
		throws CompilerException
{
	// see if an internal hint dictates the strategy to use
	final Configuration conf = getOperator().getParameters();
	final String shipStrategy = conf.getString(Optimizer.HINT_SHIP_STRATEGY, null);
	final ShipStrategyType preSet;
	
	if (shipStrategy != null) {
		if (shipStrategy.equalsIgnoreCase(Optimizer.HINT_SHIP_STRATEGY_REPARTITION_HASH)) {
			preSet = ShipStrategyType.PARTITION_HASH;
		} else if (shipStrategy.equalsIgnoreCase(Optimizer.HINT_SHIP_STRATEGY_REPARTITION_RANGE)) {
			preSet = ShipStrategyType.PARTITION_RANGE;
		} else if (shipStrategy.equalsIgnoreCase(Optimizer.HINT_SHIP_STRATEGY_FORWARD)) {
			preSet = ShipStrategyType.FORWARD;
		} else if (shipStrategy.equalsIgnoreCase(Optimizer.HINT_SHIP_STRATEGY_REPARTITION)) {
			preSet = ShipStrategyType.PARTITION_RANDOM;
		} else {
			throw new CompilerException("Unrecognized ship strategy hint: " + shipStrategy);
		}
	} else {
		preSet = null;
	}
	
	// get the predecessor node
	Operator<?> children = ((SingleInputOperator<?, ?, ?>) getOperator()).getInput();
	
	OptimizerNode pred;
	DagConnection conn;
	if (children == null) {
		throw new CompilerException("Error: Node for '" + getOperator().getName() + "' has no input.");
	} else {
		pred = contractToNode.get(children);
		conn = new DagConnection(pred, this, defaultExchangeMode);
		if (preSet != null) {
			conn.setShipStrategy(preSet);
		}
	}
	
	// create the connection and add it
	setIncomingConnection(conn);
	pred.addOutgoingConnection(conn);
}
 
Example 11
Source File: TwoInputNode.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void setInput(Map<Operator<?>, OptimizerNode> contractToNode, ExecutionMode defaultExecutionMode) {
	// see if there is a hint that dictates which shipping strategy to use for BOTH inputs
	final Configuration conf = getOperator().getParameters();
	ShipStrategyType preSet1 = null;
	ShipStrategyType preSet2 = null;
	
	String shipStrategy = conf.getString(Optimizer.HINT_SHIP_STRATEGY, null);
	if (shipStrategy != null) {
		if (Optimizer.HINT_SHIP_STRATEGY_FORWARD.equals(shipStrategy)) {
			preSet1 = preSet2 = ShipStrategyType.FORWARD;
		} else if (Optimizer.HINT_SHIP_STRATEGY_BROADCAST.equals(shipStrategy)) {
			preSet1 = preSet2 = ShipStrategyType.BROADCAST;
		} else if (Optimizer.HINT_SHIP_STRATEGY_REPARTITION_HASH.equals(shipStrategy)) {
			preSet1 = preSet2 = ShipStrategyType.PARTITION_HASH;
		} else if (Optimizer.HINT_SHIP_STRATEGY_REPARTITION_RANGE.equals(shipStrategy)) {
			preSet1 = preSet2 = ShipStrategyType.PARTITION_RANGE;
		} else if (shipStrategy.equalsIgnoreCase(Optimizer.HINT_SHIP_STRATEGY_REPARTITION)) {
			preSet1 = preSet2 = ShipStrategyType.PARTITION_RANDOM;
		} else {
			throw new CompilerException("Unknown hint for shipping strategy: " + shipStrategy);
		}
	}

	// see if there is a hint that dictates which shipping strategy to use for the FIRST input
	shipStrategy = conf.getString(Optimizer.HINT_SHIP_STRATEGY_FIRST_INPUT, null);
	if (shipStrategy != null) {
		if (Optimizer.HINT_SHIP_STRATEGY_FORWARD.equals(shipStrategy)) {
			preSet1 = ShipStrategyType.FORWARD;
		} else if (Optimizer.HINT_SHIP_STRATEGY_BROADCAST.equals(shipStrategy)) {
			preSet1 = ShipStrategyType.BROADCAST;
		} else if (Optimizer.HINT_SHIP_STRATEGY_REPARTITION_HASH.equals(shipStrategy)) {
			preSet1 = ShipStrategyType.PARTITION_HASH;
		} else if (Optimizer.HINT_SHIP_STRATEGY_REPARTITION_RANGE.equals(shipStrategy)) {
			preSet1 = ShipStrategyType.PARTITION_RANGE;
		} else if (shipStrategy.equalsIgnoreCase(Optimizer.HINT_SHIP_STRATEGY_REPARTITION)) {
			preSet1 = ShipStrategyType.PARTITION_RANDOM;
		} else {
			throw new CompilerException("Unknown hint for shipping strategy of input one: " + shipStrategy);
		}
	}

	// see if there is a hint that dictates which shipping strategy to use for the SECOND input
	shipStrategy = conf.getString(Optimizer.HINT_SHIP_STRATEGY_SECOND_INPUT, null);
	if (shipStrategy != null) {
		if (Optimizer.HINT_SHIP_STRATEGY_FORWARD.equals(shipStrategy)) {
			preSet2 = ShipStrategyType.FORWARD;
		} else if (Optimizer.HINT_SHIP_STRATEGY_BROADCAST.equals(shipStrategy)) {
			preSet2 = ShipStrategyType.BROADCAST;
		} else if (Optimizer.HINT_SHIP_STRATEGY_REPARTITION_HASH.equals(shipStrategy)) {
			preSet2 = ShipStrategyType.PARTITION_HASH;
		} else if (Optimizer.HINT_SHIP_STRATEGY_REPARTITION_RANGE.equals(shipStrategy)) {
			preSet2 = ShipStrategyType.PARTITION_RANGE;
		} else if (shipStrategy.equalsIgnoreCase(Optimizer.HINT_SHIP_STRATEGY_REPARTITION)) {
			preSet2 = ShipStrategyType.PARTITION_RANDOM;
		} else {
			throw new CompilerException("Unknown hint for shipping strategy of input two: " + shipStrategy);
		}
	}
	
	// get the predecessors
	DualInputOperator<?, ?, ?, ?> contr = getOperator();
	
	Operator<?> leftPred = contr.getFirstInput();
	Operator<?> rightPred = contr.getSecondInput();
	
	OptimizerNode pred1;
	DagConnection conn1;
	if (leftPred == null) {
		throw new CompilerException("Error: Node for '" + getOperator().getName() + "' has no input set for first input.");
	} else {
		pred1 = contractToNode.get(leftPred);
		conn1 = new DagConnection(pred1, this, defaultExecutionMode);
		if (preSet1 != null) {
			conn1.setShipStrategy(preSet1);
		}
	} 
	
	// create the connection and add it
	this.input1 = conn1;
	pred1.addOutgoingConnection(conn1);
	
	OptimizerNode pred2;
	DagConnection conn2;
	if (rightPred == null) {
		throw new CompilerException("Error: Node for '" + getOperator().getName() + "' has no input set for second input.");
	} else {
		pred2 = contractToNode.get(rightPred);
		conn2 = new DagConnection(pred2, this, defaultExecutionMode);
		if (preSet2 != null) {
			conn2.setShipStrategy(preSet2);
		}
	}
	
	// create the connection and add it
	this.input2 = conn2;
	pred2.addOutgoingConnection(conn2);
}
 
Example 12
Source File: GroupReduceWithCombineProperties.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public SingleInputPlanNode instantiate(Channel in, SingleInputNode node) {
	if (in.getShipStrategy() == ShipStrategyType.FORWARD) {
		if(in.getSource().getOptimizerNode() instanceof PartitionNode) {
			LOG.warn("Cannot automatically inject combiner for GroupReduceFunction. Please add an explicit combiner with combineGroup() in front of the partition operator.");
		}
		// adjust a sort (changes grouping, so it must be for this driver to combining sort
		if (in.getLocalStrategy() == LocalStrategy.SORT) {
			if (!in.getLocalStrategyKeys().isValidUnorderedPrefix(this.keys)) {
				throw new RuntimeException("Bug: Inconsistent sort for group strategy.");
			}
			in.setLocalStrategy(LocalStrategy.COMBININGSORT, in.getLocalStrategyKeys(),
								in.getLocalStrategySortOrder());
		}
		return new SingleInputPlanNode(node, "Reduce ("+node.getOperator().getName()+")", in,
										DriverStrategy.SORTED_GROUP_REDUCE, this.keyList);
	} else {
		// non forward case. all local properties are killed anyways, so we can safely plug in a combiner
		Channel toCombiner = new Channel(in.getSource());
		toCombiner.setShipStrategy(ShipStrategyType.FORWARD, DataExchangeMode.PIPELINED);

		// create an input node for combine with same parallelism as input node
		GroupReduceNode combinerNode = ((GroupReduceNode) node).getCombinerUtilityNode();
		combinerNode.setParallelism(in.getSource().getParallelism());

		SingleInputPlanNode combiner = new SingleInputPlanNode(combinerNode, "Combine ("+node.getOperator()
				.getName()+")", toCombiner, DriverStrategy.SORTED_GROUP_COMBINE);
		combiner.setCosts(new Costs(0, 0));
		combiner.initProperties(toCombiner.getGlobalProperties(), toCombiner.getLocalProperties());
		// set sorting comparator key info
		combiner.setDriverKeyInfo(in.getLocalStrategyKeys(), in.getLocalStrategySortOrder(), 0);
		// set grouping comparator key info
		combiner.setDriverKeyInfo(this.keyList, 1);
		
		Channel toReducer = new Channel(combiner);
		toReducer.setShipStrategy(in.getShipStrategy(), in.getShipStrategyKeys(),
								in.getShipStrategySortOrder(), in.getDataExchangeMode());
		if (in.getShipStrategy() == ShipStrategyType.PARTITION_RANGE) {
			toReducer.setDataDistribution(in.getDataDistribution());
		}
		toReducer.setLocalStrategy(LocalStrategy.COMBININGSORT, in.getLocalStrategyKeys(),
									in.getLocalStrategySortOrder());

		return new SingleInputPlanNode(node, "Reduce ("+node.getOperator().getName()+")",
										toReducer, DriverStrategy.SORTED_GROUP_REDUCE, this.keyList);
	}
}
 
Example 13
Source File: GlobalProperties.java    From flink with Apache License 2.0 4 votes vote down vote up
public void parameterizeChannel(Channel channel, boolean globalDopChange,
								ExecutionMode exchangeMode, boolean breakPipeline) {

	ShipStrategyType shipType;
	FieldList partitionKeys;
	boolean[] sortDirection;
	Partitioner<?> partitioner;

	switch (this.partitioning) {
		case RANDOM_PARTITIONED:
			shipType = globalDopChange ? ShipStrategyType.PARTITION_RANDOM : ShipStrategyType.FORWARD;
			partitionKeys = null;
			sortDirection = null;
			partitioner = null;
			break;

		case FULL_REPLICATION:
			shipType = ShipStrategyType.BROADCAST;
			partitionKeys = null;
			sortDirection = null;
			partitioner = null;
			break;

		case ANY_PARTITIONING:
		case HASH_PARTITIONED:
			shipType = ShipStrategyType.PARTITION_HASH;
			partitionKeys = Utils.createOrderedFromSet(this.partitioningFields);
			sortDirection = null;
			partitioner = null;
			break;

		case RANGE_PARTITIONED:
			shipType = ShipStrategyType.PARTITION_RANGE;
			partitionKeys = this.ordering.getInvolvedIndexes();
			sortDirection = this.ordering.getFieldSortDirections();
			partitioner = null;
			break;

		case FORCED_REBALANCED:
			shipType = ShipStrategyType.PARTITION_RANDOM;
			partitionKeys = null;
			sortDirection = null;
			partitioner = null;
			break;

		case CUSTOM_PARTITIONING:
			shipType = ShipStrategyType.PARTITION_CUSTOM;
			partitionKeys = this.partitioningFields;
			sortDirection = null;
			partitioner = this.customPartitioner;
			break;

		default:
			throw new CompilerException("Unsupported partitioning strategy");
	}

	channel.setDataDistribution(this.distribution);
	DataExchangeMode exMode = DataExchangeMode.select(exchangeMode, shipType, breakPipeline);
	channel.setShipStrategy(shipType, partitionKeys, sortDirection, partitioner, exMode);
}
 
Example 14
Source File: SingleInputNode.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void setInput(Map<Operator<?>, OptimizerNode> contractToNode, ExecutionMode defaultExchangeMode)
		throws CompilerException
{
	// see if an internal hint dictates the strategy to use
	final Configuration conf = getOperator().getParameters();
	final String shipStrategy = conf.getString(Optimizer.HINT_SHIP_STRATEGY, null);
	final ShipStrategyType preSet;
	
	if (shipStrategy != null) {
		if (shipStrategy.equalsIgnoreCase(Optimizer.HINT_SHIP_STRATEGY_REPARTITION_HASH)) {
			preSet = ShipStrategyType.PARTITION_HASH;
		} else if (shipStrategy.equalsIgnoreCase(Optimizer.HINT_SHIP_STRATEGY_REPARTITION_RANGE)) {
			preSet = ShipStrategyType.PARTITION_RANGE;
		} else if (shipStrategy.equalsIgnoreCase(Optimizer.HINT_SHIP_STRATEGY_FORWARD)) {
			preSet = ShipStrategyType.FORWARD;
		} else if (shipStrategy.equalsIgnoreCase(Optimizer.HINT_SHIP_STRATEGY_REPARTITION)) {
			preSet = ShipStrategyType.PARTITION_RANDOM;
		} else {
			throw new CompilerException("Unrecognized ship strategy hint: " + shipStrategy);
		}
	} else {
		preSet = null;
	}
	
	// get the predecessor node
	Operator<?> children = ((SingleInputOperator<?, ?, ?>) getOperator()).getInput();
	
	OptimizerNode pred;
	DagConnection conn;
	if (children == null) {
		throw new CompilerException("Error: Node for '" + getOperator().getName() + "' has no input.");
	} else {
		pred = contractToNode.get(children);
		conn = new DagConnection(pred, this, defaultExchangeMode);
		if (preSet != null) {
			conn.setShipStrategy(preSet);
		}
	}
	
	// create the connection and add it
	setIncomingConnection(conn);
	pred.addOutgoingConnection(conn);
}
 
Example 15
Source File: TwoInputNode.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void setInput(Map<Operator<?>, OptimizerNode> contractToNode, ExecutionMode defaultExecutionMode) {
	// see if there is a hint that dictates which shipping strategy to use for BOTH inputs
	final Configuration conf = getOperator().getParameters();
	ShipStrategyType preSet1 = null;
	ShipStrategyType preSet2 = null;
	
	String shipStrategy = conf.getString(Optimizer.HINT_SHIP_STRATEGY, null);
	if (shipStrategy != null) {
		if (Optimizer.HINT_SHIP_STRATEGY_FORWARD.equals(shipStrategy)) {
			preSet1 = preSet2 = ShipStrategyType.FORWARD;
		} else if (Optimizer.HINT_SHIP_STRATEGY_BROADCAST.equals(shipStrategy)) {
			preSet1 = preSet2 = ShipStrategyType.BROADCAST;
		} else if (Optimizer.HINT_SHIP_STRATEGY_REPARTITION_HASH.equals(shipStrategy)) {
			preSet1 = preSet2 = ShipStrategyType.PARTITION_HASH;
		} else if (Optimizer.HINT_SHIP_STRATEGY_REPARTITION_RANGE.equals(shipStrategy)) {
			preSet1 = preSet2 = ShipStrategyType.PARTITION_RANGE;
		} else if (shipStrategy.equalsIgnoreCase(Optimizer.HINT_SHIP_STRATEGY_REPARTITION)) {
			preSet1 = preSet2 = ShipStrategyType.PARTITION_RANDOM;
		} else {
			throw new CompilerException("Unknown hint for shipping strategy: " + shipStrategy);
		}
	}

	// see if there is a hint that dictates which shipping strategy to use for the FIRST input
	shipStrategy = conf.getString(Optimizer.HINT_SHIP_STRATEGY_FIRST_INPUT, null);
	if (shipStrategy != null) {
		if (Optimizer.HINT_SHIP_STRATEGY_FORWARD.equals(shipStrategy)) {
			preSet1 = ShipStrategyType.FORWARD;
		} else if (Optimizer.HINT_SHIP_STRATEGY_BROADCAST.equals(shipStrategy)) {
			preSet1 = ShipStrategyType.BROADCAST;
		} else if (Optimizer.HINT_SHIP_STRATEGY_REPARTITION_HASH.equals(shipStrategy)) {
			preSet1 = ShipStrategyType.PARTITION_HASH;
		} else if (Optimizer.HINT_SHIP_STRATEGY_REPARTITION_RANGE.equals(shipStrategy)) {
			preSet1 = ShipStrategyType.PARTITION_RANGE;
		} else if (shipStrategy.equalsIgnoreCase(Optimizer.HINT_SHIP_STRATEGY_REPARTITION)) {
			preSet1 = ShipStrategyType.PARTITION_RANDOM;
		} else {
			throw new CompilerException("Unknown hint for shipping strategy of input one: " + shipStrategy);
		}
	}

	// see if there is a hint that dictates which shipping strategy to use for the SECOND input
	shipStrategy = conf.getString(Optimizer.HINT_SHIP_STRATEGY_SECOND_INPUT, null);
	if (shipStrategy != null) {
		if (Optimizer.HINT_SHIP_STRATEGY_FORWARD.equals(shipStrategy)) {
			preSet2 = ShipStrategyType.FORWARD;
		} else if (Optimizer.HINT_SHIP_STRATEGY_BROADCAST.equals(shipStrategy)) {
			preSet2 = ShipStrategyType.BROADCAST;
		} else if (Optimizer.HINT_SHIP_STRATEGY_REPARTITION_HASH.equals(shipStrategy)) {
			preSet2 = ShipStrategyType.PARTITION_HASH;
		} else if (Optimizer.HINT_SHIP_STRATEGY_REPARTITION_RANGE.equals(shipStrategy)) {
			preSet2 = ShipStrategyType.PARTITION_RANGE;
		} else if (shipStrategy.equalsIgnoreCase(Optimizer.HINT_SHIP_STRATEGY_REPARTITION)) {
			preSet2 = ShipStrategyType.PARTITION_RANDOM;
		} else {
			throw new CompilerException("Unknown hint for shipping strategy of input two: " + shipStrategy);
		}
	}
	
	// get the predecessors
	DualInputOperator<?, ?, ?, ?> contr = getOperator();
	
	Operator<?> leftPred = contr.getFirstInput();
	Operator<?> rightPred = contr.getSecondInput();
	
	OptimizerNode pred1;
	DagConnection conn1;
	if (leftPred == null) {
		throw new CompilerException("Error: Node for '" + getOperator().getName() + "' has no input set for first input.");
	} else {
		pred1 = contractToNode.get(leftPred);
		conn1 = new DagConnection(pred1, this, defaultExecutionMode);
		if (preSet1 != null) {
			conn1.setShipStrategy(preSet1);
		}
	} 
	
	// create the connection and add it
	this.input1 = conn1;
	pred1.addOutgoingConnection(conn1);
	
	OptimizerNode pred2;
	DagConnection conn2;
	if (rightPred == null) {
		throw new CompilerException("Error: Node for '" + getOperator().getName() + "' has no input set for second input.");
	} else {
		pred2 = contractToNode.get(rightPred);
		conn2 = new DagConnection(pred2, this, defaultExecutionMode);
		if (preSet2 != null) {
			conn2.setShipStrategy(preSet2);
		}
	}
	
	// create the connection and add it
	this.input2 = conn2;
	pred2.addOutgoingConnection(conn2);
}