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

The following examples show how to use org.apache.flink.runtime.operators.shipping.ShipStrategyType#BROADCAST . 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: DualInputPlanNode.java    From flink with Apache License 2.0 6 votes vote down vote up
public DualInputPlanNode(OptimizerNode template, String nodeName, Channel input1, Channel input2, DriverStrategy diverStrategy,
		FieldList driverKeyFields1, FieldList driverKeyFields2, boolean[] driverSortOrders)
{
	super(template, nodeName, diverStrategy);
	this.input1 = input1;
	this.input2 = input2;
	this.keys1 = driverKeyFields1;
	this.keys2 = driverKeyFields2;
	this.sortOrders = driverSortOrders;
	
	if (this.input1.getShipStrategy() == ShipStrategyType.BROADCAST) {
		this.input1.setReplicationFactor(getParallelism());
	}
	if (this.input2.getShipStrategy() == ShipStrategyType.BROADCAST) {
		this.input2.setReplicationFactor(getParallelism());
	}
	
	mergeBranchPlanMaps(input1.getSource(), input2.getSource());
}
 
Example 2
Source File: OptimizerNode.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * This function connects the operators that produce the broadcast inputs to this operator.
 *
 * @param operatorToNode The map from program operators to optimizer nodes.
 * @param defaultExchangeMode The data exchange mode to use, if the operator does not
 *                            specify one.
 *
 * @throws CompilerException
 */
public void setBroadcastInputs(Map<Operator<?>, OptimizerNode> operatorToNode, ExecutionMode defaultExchangeMode) {
	// skip for Operators that don't support broadcast variables 
	if (!(getOperator() instanceof AbstractUdfOperator<?, ?>)) {
		return;
	}

	// get all broadcast inputs
	AbstractUdfOperator<?, ?> operator = ((AbstractUdfOperator<?, ?>) getOperator());

	// create connections and add them
	for (Map.Entry<String, Operator<?>> input : operator.getBroadcastInputs().entrySet()) {
		OptimizerNode predecessor = operatorToNode.get(input.getValue());
		DagConnection connection = new DagConnection(predecessor, this,
														ShipStrategyType.BROADCAST, defaultExchangeMode);
		addBroadcastConnection(input.getKey(), connection);
		predecessor.addOutgoingConnection(connection);
	}
}
 
Example 3
Source File: OptimizerNode.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * This function connects the operators that produce the broadcast inputs to this operator.
 *
 * @param operatorToNode The map from program operators to optimizer nodes.
 * @param defaultExchangeMode The data exchange mode to use, if the operator does not
 *                            specify one.
 *
 * @throws CompilerException
 */
public void setBroadcastInputs(Map<Operator<?>, OptimizerNode> operatorToNode, ExecutionMode defaultExchangeMode) {
	// skip for Operators that don't support broadcast variables 
	if (!(getOperator() instanceof AbstractUdfOperator<?, ?>)) {
		return;
	}

	// get all broadcast inputs
	AbstractUdfOperator<?, ?> operator = ((AbstractUdfOperator<?, ?>) getOperator());

	// create connections and add them
	for (Map.Entry<String, Operator<?>> input : operator.getBroadcastInputs().entrySet()) {
		OptimizerNode predecessor = operatorToNode.get(input.getValue());
		DagConnection connection = new DagConnection(predecessor, this,
														ShipStrategyType.BROADCAST, defaultExchangeMode);
		addBroadcastConnection(input.getKey(), connection);
		predecessor.addOutgoingConnection(connection);
	}
}
 
Example 4
Source File: DualInputPlanNode.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public DualInputPlanNode(OptimizerNode template, String nodeName, Channel input1, Channel input2, DriverStrategy diverStrategy,
		FieldList driverKeyFields1, FieldList driverKeyFields2, boolean[] driverSortOrders)
{
	super(template, nodeName, diverStrategy);
	this.input1 = input1;
	this.input2 = input2;
	this.keys1 = driverKeyFields1;
	this.keys2 = driverKeyFields2;
	this.sortOrders = driverSortOrders;
	
	if (this.input1.getShipStrategy() == ShipStrategyType.BROADCAST) {
		this.input1.setReplicationFactor(getParallelism());
	}
	if (this.input2.getShipStrategy() == ShipStrategyType.BROADCAST) {
		this.input2.setReplicationFactor(getParallelism());
	}
	
	mergeBranchPlanMaps(input1.getSource(), input2.getSource());
}
 
Example 5
Source File: DualInputPlanNode.java    From flink with Apache License 2.0 6 votes vote down vote up
public DualInputPlanNode(OptimizerNode template, String nodeName, Channel input1, Channel input2, DriverStrategy diverStrategy,
		FieldList driverKeyFields1, FieldList driverKeyFields2, boolean[] driverSortOrders)
{
	super(template, nodeName, diverStrategy);
	this.input1 = input1;
	this.input2 = input2;
	this.keys1 = driverKeyFields1;
	this.keys2 = driverKeyFields2;
	this.sortOrders = driverSortOrders;
	
	if (this.input1.getShipStrategy() == ShipStrategyType.BROADCAST) {
		this.input1.setReplicationFactor(getParallelism());
	}
	if (this.input2.getShipStrategy() == ShipStrategyType.BROADCAST) {
		this.input2.setReplicationFactor(getParallelism());
	}
	
	mergeBranchPlanMaps(input1.getSource(), input2.getSource());
}
 
Example 6
Source File: OptimizerNode.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * This function connects the operators that produce the broadcast inputs to this operator.
 *
 * @param operatorToNode The map from program operators to optimizer nodes.
 * @param defaultExchangeMode The data exchange mode to use, if the operator does not
 *                            specify one.
 *
 * @throws CompilerException
 */
public void setBroadcastInputs(Map<Operator<?>, OptimizerNode> operatorToNode, ExecutionMode defaultExchangeMode) {
	// skip for Operators that don't support broadcast variables 
	if (!(getOperator() instanceof AbstractUdfOperator<?, ?>)) {
		return;
	}

	// get all broadcast inputs
	AbstractUdfOperator<?, ?> operator = ((AbstractUdfOperator<?, ?>) getOperator());

	// create connections and add them
	for (Map.Entry<String, Operator<?>> input : operator.getBroadcastInputs().entrySet()) {
		OptimizerNode predecessor = operatorToNode.get(input.getValue());
		DagConnection connection = new DagConnection(predecessor, this,
														ShipStrategyType.BROADCAST, defaultExchangeMode);
		addBroadcastConnection(input.getKey(), connection);
		predecessor.addOutgoingConnection(connection);
	}
}
 
Example 7
Source File: SingleInputPlanNode.java    From flink with Apache License 2.0 5 votes vote down vote up
public SingleInputPlanNode(OptimizerNode template, String nodeName, Channel input, 
		DriverStrategy driverStrategy, FieldList driverKeyFields, boolean[] driverSortOrders)
{
	super(template, nodeName, driverStrategy);
	this.input = input;
	
	this.comparators = new TypeComparatorFactory<?>[driverStrategy.getNumRequiredComparators()];
	this.driverKeys = new FieldList[driverStrategy.getNumRequiredComparators()];
	this.driverSortOrders = new boolean[driverStrategy.getNumRequiredComparators()][];
	
	if(driverStrategy.getNumRequiredComparators() > 0) {
		this.driverKeys[0] = driverKeyFields;
		this.driverSortOrders[0] = driverSortOrders;
	}
	
	if (this.input.getShipStrategy() == ShipStrategyType.BROADCAST) {
		this.input.setReplicationFactor(getParallelism());
	}
	
	final PlanNode predNode = input.getSource();
	
	if (predNode.branchPlan != null && !predNode.branchPlan.isEmpty()) {
		
		if (this.branchPlan == null) {
			this.branchPlan = new HashMap<OptimizerNode, PlanNode>();
		}
		this.branchPlan.putAll(predNode.branchPlan);
	}
}
 
Example 8
Source File: RelationalQueryCompilerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private boolean checkBroadcastShipStrategies(DualInputPlanNode join, SingleInputPlanNode reducer,
		SingleInputPlanNode combiner) {
	if (ShipStrategyType.BROADCAST == join.getInput1().getShipStrategy() &&
		ShipStrategyType.FORWARD == join.getInput2().getShipStrategy() &&
		ShipStrategyType.PARTITION_HASH == reducer.getInput().getShipStrategy()) {

		// check combiner
		Assert.assertNotNull("Plan should have a combiner", combiner);
		Assert.assertEquals(ShipStrategyType.FORWARD, combiner.getInput().getShipStrategy());
		return true;
	} else {
		return false;
	}
}
 
Example 9
Source File: RelationalQueryCompilerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private boolean checkBroadcastShipStrategies(DualInputPlanNode join, SingleInputPlanNode reducer,
		SingleInputPlanNode combiner) {
	if (ShipStrategyType.BROADCAST == join.getInput1().getShipStrategy() &&
		ShipStrategyType.FORWARD == join.getInput2().getShipStrategy() &&
		ShipStrategyType.PARTITION_HASH == reducer.getInput().getShipStrategy()) {

		// check combiner
		Assert.assertNotNull("Plan should have a combiner", combiner);
		Assert.assertEquals(ShipStrategyType.FORWARD, combiner.getInput().getShipStrategy());
		return true;
	} else {
		return false;
	}
}
 
Example 10
Source File: SingleInputPlanNode.java    From flink with Apache License 2.0 5 votes vote down vote up
public SingleInputPlanNode(OptimizerNode template, String nodeName, Channel input, 
		DriverStrategy driverStrategy, FieldList driverKeyFields, boolean[] driverSortOrders)
{
	super(template, nodeName, driverStrategy);
	this.input = input;
	
	this.comparators = new TypeComparatorFactory<?>[driverStrategy.getNumRequiredComparators()];
	this.driverKeys = new FieldList[driverStrategy.getNumRequiredComparators()];
	this.driverSortOrders = new boolean[driverStrategy.getNumRequiredComparators()][];
	
	if(driverStrategy.getNumRequiredComparators() > 0) {
		this.driverKeys[0] = driverKeyFields;
		this.driverSortOrders[0] = driverSortOrders;
	}
	
	if (this.input.getShipStrategy() == ShipStrategyType.BROADCAST) {
		this.input.setReplicationFactor(getParallelism());
	}
	
	final PlanNode predNode = input.getSource();
	
	if (predNode.branchPlan != null && !predNode.branchPlan.isEmpty()) {
		
		if (this.branchPlan == null) {
			this.branchPlan = new HashMap<OptimizerNode, PlanNode>();
		}
		this.branchPlan.putAll(predNode.branchPlan);
	}
}
 
Example 11
Source File: RelationalQueryCompilerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private boolean checkBroadcastShipStrategies(DualInputPlanNode join, SingleInputPlanNode reducer,
		SingleInputPlanNode combiner) {
	if (ShipStrategyType.BROADCAST == join.getInput1().getShipStrategy() &&
		ShipStrategyType.FORWARD == join.getInput2().getShipStrategy() &&
		ShipStrategyType.PARTITION_HASH == reducer.getInput().getShipStrategy()) {

		// check combiner
		Assert.assertNotNull("Plan should have a combiner", combiner);
		Assert.assertEquals(ShipStrategyType.FORWARD, combiner.getInput().getShipStrategy());
		return true;
	} else {
		return false;
	}
}
 
Example 12
Source File: SingleInputPlanNode.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public SingleInputPlanNode(OptimizerNode template, String nodeName, Channel input, 
		DriverStrategy driverStrategy, FieldList driverKeyFields, boolean[] driverSortOrders)
{
	super(template, nodeName, driverStrategy);
	this.input = input;
	
	this.comparators = new TypeComparatorFactory<?>[driverStrategy.getNumRequiredComparators()];
	this.driverKeys = new FieldList[driverStrategy.getNumRequiredComparators()];
	this.driverSortOrders = new boolean[driverStrategy.getNumRequiredComparators()][];
	
	if(driverStrategy.getNumRequiredComparators() > 0) {
		this.driverKeys[0] = driverKeyFields;
		this.driverSortOrders[0] = driverSortOrders;
	}
	
	if (this.input.getShipStrategy() == ShipStrategyType.BROADCAST) {
		this.input.setReplicationFactor(getParallelism());
	}
	
	final PlanNode predNode = input.getSource();
	
	if (predNode.branchPlan != null && !predNode.branchPlan.isEmpty()) {
		
		if (this.branchPlan == null) {
			this.branchPlan = new HashMap<OptimizerNode, PlanNode>();
		}
		this.branchPlan.putAll(predNode.branchPlan);
	}
}
 
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: 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 15
Source File: RecordWriterTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * The results of emitting records via BroadcastPartitioner or broadcasting records directly are the same,
 * that is all the target channels can receive the whole outputs.
 *
 * @param isBroadcastEmit whether using {@link RecordWriter#broadcastEmit(IOReadableWritable)} or not
 */
private void emitRecordWithBroadcastPartitionerOrBroadcastEmitRecord(boolean isBroadcastEmit) throws Exception {
	final int numberOfChannels = 4;
	final int bufferSize = 32;
	final int numValues = 8;
	final int serializationLength = 4;

	@SuppressWarnings("unchecked")
	final Queue<BufferConsumer>[] queues = new Queue[numberOfChannels];
	for (int i = 0; i < numberOfChannels; i++) {
		queues[i] = new ArrayDeque<>();
	}

	final TestPooledBufferProvider bufferProvider = new TestPooledBufferProvider(Integer.MAX_VALUE, bufferSize);
	final ResultPartitionWriter partitionWriter = new CollectingPartitionWriter(queues, bufferProvider);
	final ChannelSelector selector = new OutputEmitter(ShipStrategyType.BROADCAST, 0);
	final RecordWriter<SerializationTestType> writer = new RecordWriterBuilder()
		.setChannelSelector(selector)
		.setTimeout(0)
		.build(partitionWriter);
	final RecordDeserializer<SerializationTestType> deserializer = new SpillingAdaptiveSpanningRecordDeserializer<>(
		new String[]{ tempFolder.getRoot().getAbsolutePath() });

	final ArrayDeque<SerializationTestType> serializedRecords = new ArrayDeque<>();
	final Iterable<SerializationTestType> records = Util.randomRecords(numValues, SerializationTestTypeFactory.INT);
	for (SerializationTestType record : records) {
		serializedRecords.add(record);

		if (isBroadcastEmit) {
			writer.broadcastEmit(record);
		} else {
			writer.emit(record);
		}
	}

	final int requiredBuffers = numValues / (bufferSize / (4 + serializationLength));
	for (int i = 0; i < numberOfChannels; i++) {
		assertEquals(requiredBuffers, queues[i].size());

		final ArrayDeque<SerializationTestType> expectedRecords = serializedRecords.clone();
		int assertRecords = 0;
		for (int j = 0; j < requiredBuffers; j++) {
			Buffer buffer = buildSingleBuffer(queues[i].remove());
			deserializer.setNextBuffer(buffer);

			assertRecords += DeserializationUtils.deserializeRecords(expectedRecords, deserializer);
		}
		Assert.assertEquals(numValues, assertRecords);
	}
}
 
Example 16
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 17
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 18
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 19
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 20
Source File: RecordWriterTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * The results of emitting records via BroadcastPartitioner or broadcasting records directly are the same,
 * that is all the target channels can receive the whole outputs.
 *
 * @param isBroadcastEmit whether using {@link RecordWriter#broadcastEmit(IOReadableWritable)} or not
 */
private void emitRecordWithBroadcastPartitionerOrBroadcastEmitRecord(boolean isBroadcastEmit) throws Exception {
	final int numberOfChannels = 4;
	final int bufferSize = 32;
	final int numValues = 8;
	final int serializationLength = 4;

	@SuppressWarnings("unchecked")
	final Queue<BufferConsumer>[] queues = new Queue[numberOfChannels];
	for (int i = 0; i < numberOfChannels; i++) {
		queues[i] = new ArrayDeque<>();
	}

	final TestPooledBufferProvider bufferProvider = new TestPooledBufferProvider(Integer.MAX_VALUE, bufferSize);
	final ResultPartitionWriter partitionWriter = new CollectingPartitionWriter(queues, bufferProvider);
	final ChannelSelector selector = new OutputEmitter(ShipStrategyType.BROADCAST, 0);
	final RecordWriter<SerializationTestType> writer = RecordWriter.createRecordWriter(partitionWriter, selector, 0, "test");
	final RecordDeserializer<SerializationTestType> deserializer = new SpillingAdaptiveSpanningRecordDeserializer<>(
		new String[]{ tempFolder.getRoot().getAbsolutePath() });

	final ArrayDeque<SerializationTestType> serializedRecords = new ArrayDeque<>();
	final Iterable<SerializationTestType> records = Util.randomRecords(numValues, SerializationTestTypeFactory.INT);
	for (SerializationTestType record : records) {
		serializedRecords.add(record);

		if (isBroadcastEmit) {
			writer.broadcastEmit(record);
		} else {
			writer.emit(record);
		}
	}

	final int requiredBuffers = numValues / (bufferSize / (4 + serializationLength));
	for (int i = 0; i < numberOfChannels; i++) {
		assertEquals(requiredBuffers, queues[i].size());

		final ArrayDeque<SerializationTestType> expectedRecords = serializedRecords.clone();
		int assertRecords = 0;
		for (int j = 0; j < requiredBuffers; j++) {
			Buffer buffer = buildSingleBuffer(queues[i].remove());
			deserializer.setNextBuffer(buffer);

			assertRecords += DeserializationUtils.deserializeRecords(expectedRecords, deserializer);
		}
		Assert.assertEquals(numValues, assertRecords);
	}
}