org.apache.flink.runtime.operators.util.metrics.CountingMutableObjectIterator Java Examples

The following examples show how to use org.apache.flink.runtime.operators.util.metrics.CountingMutableObjectIterator. 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: GroupReduceDriver.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void prepare() throws Exception {
	TaskConfig config = this.taskContext.getTaskConfig();
	if (config.getDriverStrategy() != DriverStrategy.SORTED_GROUP_REDUCE) {
		throw new Exception("Unrecognized driver strategy for GroupReduce driver: " + config.getDriverStrategy().name());
	}
	final Counter numRecordsIn = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsInCounter();
	
	this.serializer = this.taskContext.<IT>getInputSerializer(0).getSerializer();
	this.comparator = this.taskContext.getDriverComparator(0);
	this.input = new CountingMutableObjectIterator<>(this.taskContext.<IT>getInput(0), numRecordsIn);

	ExecutionConfig executionConfig = taskContext.getExecutionConfig();
	this.objectReuseEnabled = executionConfig.isObjectReuseEnabled();

	if (LOG.isDebugEnabled()) {
		LOG.debug("GroupReduceDriver object reuse: " + (this.objectReuseEnabled ? "ENABLED" : "DISABLED") + ".");
	}
}
 
Example #2
Source File: GroupReduceDriver.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void prepare() throws Exception {
	TaskConfig config = this.taskContext.getTaskConfig();
	if (config.getDriverStrategy() != DriverStrategy.SORTED_GROUP_REDUCE) {
		throw new Exception("Unrecognized driver strategy for GroupReduce driver: " + config.getDriverStrategy().name());
	}
	final Counter numRecordsIn = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsInCounter();
	
	this.serializer = this.taskContext.<IT>getInputSerializer(0).getSerializer();
	this.comparator = this.taskContext.getDriverComparator(0);
	this.input = new CountingMutableObjectIterator<>(this.taskContext.<IT>getInput(0), numRecordsIn);

	ExecutionConfig executionConfig = taskContext.getExecutionConfig();
	this.objectReuseEnabled = executionConfig.isObjectReuseEnabled();

	if (LOG.isDebugEnabled()) {
		LOG.debug("GroupReduceDriver object reuse: " + (this.objectReuseEnabled ? "ENABLED" : "DISABLED") + ".");
	}
}
 
Example #3
Source File: GroupReduceDriver.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void prepare() throws Exception {
	TaskConfig config = this.taskContext.getTaskConfig();
	if (config.getDriverStrategy() != DriverStrategy.SORTED_GROUP_REDUCE) {
		throw new Exception("Unrecognized driver strategy for GroupReduce driver: " + config.getDriverStrategy().name());
	}
	final Counter numRecordsIn = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsInCounter();
	
	this.serializer = this.taskContext.<IT>getInputSerializer(0).getSerializer();
	this.comparator = this.taskContext.getDriverComparator(0);
	this.input = new CountingMutableObjectIterator<>(this.taskContext.<IT>getInput(0), numRecordsIn);

	ExecutionConfig executionConfig = taskContext.getExecutionConfig();
	this.objectReuseEnabled = executionConfig.isObjectReuseEnabled();

	if (LOG.isDebugEnabled()) {
		LOG.debug("GroupReduceDriver object reuse: " + (this.objectReuseEnabled ? "ENABLED" : "DISABLED") + ".");
	}
}
 
Example #4
Source File: CoGroupDriver.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void prepare() throws Exception
{
	final TaskConfig config = this.taskContext.getTaskConfig();
	if (config.getDriverStrategy() != DriverStrategy.CO_GROUP) {
		throw new Exception("Unrecognized driver strategy for CoGoup driver: " + config.getDriverStrategy().name());
	}

	final Counter numRecordsIn = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsInCounter();
	
	final MutableObjectIterator<IT1> in1 = new CountingMutableObjectIterator<>(this.taskContext.<IT1>getInput(0), numRecordsIn);
	final MutableObjectIterator<IT2> in2 = new CountingMutableObjectIterator<>(this.taskContext.<IT2>getInput(1), numRecordsIn);
	
	// get the key positions and types
	final TypeSerializer<IT1> serializer1 = this.taskContext.<IT1>getInputSerializer(0).getSerializer();
	final TypeSerializer<IT2> serializer2 = this.taskContext.<IT2>getInputSerializer(1).getSerializer();
	final TypeComparator<IT1> groupComparator1 = this.taskContext.getDriverComparator(0);
	final TypeComparator<IT2> groupComparator2 = this.taskContext.getDriverComparator(1);
	
	final TypePairComparatorFactory<IT1, IT2> pairComparatorFactory = config.getPairComparatorFactory(
				this.taskContext.getUserCodeClassLoader());
	if (pairComparatorFactory == null) {
		throw new Exception("Missing pair comparator factory for CoGroup driver");
	}

	ExecutionConfig executionConfig = taskContext.getExecutionConfig();
	this.objectReuseEnabled = executionConfig.isObjectReuseEnabled();

	if (LOG.isDebugEnabled()) {
		LOG.debug("CoGroupDriver object reuse: " + (this.objectReuseEnabled ? "ENABLED" : "DISABLED") + ".");
	}

	if (objectReuseEnabled) {
		// create CoGroupTaskIterator according to provided local strategy.
		this.coGroupIterator = new ReusingSortMergeCoGroupIterator<IT1, IT2>(
				in1, in2,
				serializer1, groupComparator1,
				serializer2, groupComparator2,
				pairComparatorFactory.createComparator12(groupComparator1, groupComparator2));
	} else {
		// create CoGroupTaskIterator according to provided local strategy.
		this.coGroupIterator = new NonReusingSortMergeCoGroupIterator<IT1, IT2>(
				in1, in2,
				serializer1, groupComparator1,
				serializer2, groupComparator2,
				pairComparatorFactory.createComparator12(groupComparator1, groupComparator2));
	}
	
	// open CoGroupTaskIterator - this triggers the sorting and blocks until the iterator is ready
	this.coGroupIterator.open();
	
	if (LOG.isDebugEnabled()) {
		LOG.debug(this.taskContext.formatLogString("CoGroup task iterator ready."));
	}
}
 
Example #5
Source File: AbstractCachedBuildSideJoinDriver.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize() throws Exception {
	TaskConfig config = this.taskContext.getTaskConfig();

	final Counter numRecordsIn = taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsInCounter();
	
	TypeSerializer<IT1> serializer1 = this.taskContext.<IT1>getInputSerializer(0).getSerializer();
	TypeSerializer<IT2> serializer2 = this.taskContext.<IT2>getInputSerializer(1).getSerializer();
	TypeComparator<IT1> comparator1 = this.taskContext.getDriverComparator(0);
	TypeComparator<IT2> comparator2 = this.taskContext.getDriverComparator(1);
	MutableObjectIterator<IT1> input1 = new CountingMutableObjectIterator<>(this.taskContext.<IT1>getInput(0), numRecordsIn);
	MutableObjectIterator<IT2> input2 = new CountingMutableObjectIterator<>(this.taskContext.<IT2>getInput(1), numRecordsIn);

	TypePairComparatorFactory<IT1, IT2> pairComparatorFactory = 
			this.taskContext.getTaskConfig().getPairComparatorFactory(this.taskContext.getUserCodeClassLoader());

	double availableMemory = config.getRelativeMemoryDriver();
	boolean hashJoinUseBitMaps = taskContext.getTaskManagerInfo().getConfiguration()
		.getBoolean(AlgorithmOptions.HASH_JOIN_BLOOM_FILTERS);
	
	ExecutionConfig executionConfig = taskContext.getExecutionConfig();
	objectReuseEnabled = executionConfig.isObjectReuseEnabled();

	if (objectReuseEnabled) {
		if (buildSideIndex == 0 && probeSideIndex == 1) {

			matchIterator = new ReusingBuildFirstReOpenableHashJoinIterator<IT1, IT2, OT>(
					input1, input2,
					serializer1, comparator1,
					serializer2, comparator2,
					pairComparatorFactory.createComparator21(comparator1, comparator2),
					this.taskContext.getMemoryManager(),
					this.taskContext.getIOManager(),
					this.taskContext.getContainingTask(),
					availableMemory,
					false,
					false,
					hashJoinUseBitMaps);


		} else if (buildSideIndex == 1 && probeSideIndex == 0) {

			matchIterator = new ReusingBuildSecondReOpenableHashJoinIterator<IT1, IT2, OT>(
					input1, input2,
					serializer1, comparator1,
					serializer2, comparator2,
					pairComparatorFactory.createComparator12(comparator1, comparator2),
					this.taskContext.getMemoryManager(),
					this.taskContext.getIOManager(),
					this.taskContext.getContainingTask(),
					availableMemory,
					false,
					false,
					hashJoinUseBitMaps);

		} else {
			throw new Exception("Error: Inconsistent setup for repeatable hash join driver.");
		}
	} else {
		if (buildSideIndex == 0 && probeSideIndex == 1) {

			matchIterator = new NonReusingBuildFirstReOpenableHashJoinIterator<IT1, IT2, OT>(
					input1, input2,
					serializer1, comparator1,
					serializer2, comparator2,
					pairComparatorFactory.createComparator21(comparator1, comparator2),
					this.taskContext.getMemoryManager(),
					this.taskContext.getIOManager(),
					this.taskContext.getContainingTask(),
					availableMemory,
					false,
					false,
					hashJoinUseBitMaps);


		} else if (buildSideIndex == 1 && probeSideIndex == 0) {

			matchIterator = new NonReusingBuildSecondReOpenableHashJoinIterator<IT1, IT2, OT>(
					input1, input2,
					serializer1, comparator1,
					serializer2, comparator2,
					pairComparatorFactory.createComparator12(comparator1, comparator2),
					this.taskContext.getMemoryManager(),
					this.taskContext.getIOManager(),
					this.taskContext.getContainingTask(),
					availableMemory,
					false,
					false,
					hashJoinUseBitMaps);

		} else {
			throw new Exception("Error: Inconsistent setup for repeatable hash join driver.");
		}
	}
	
	this.matchIterator.open();
}
 
Example #6
Source File: AbstractOuterJoinDriver.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void prepare() throws Exception {
	final TaskConfig config = this.taskContext.getTaskConfig();
	
	// obtain task manager's memory manager and I/O manager
	final MemoryManager memoryManager = this.taskContext.getMemoryManager();
	final IOManager ioManager = this.taskContext.getIOManager();
	
	// set up memory and I/O parameters
	final double driverMemFraction = config.getRelativeMemoryDriver();
	
	final DriverStrategy ls = config.getDriverStrategy();

	final Counter numRecordsIn = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsInCounter();
	final MutableObjectIterator<IT1> in1 = new CountingMutableObjectIterator<>(this.taskContext.<IT1>getInput(0), numRecordsIn);
	final MutableObjectIterator<IT2> in2 = new CountingMutableObjectIterator<>(this.taskContext.<IT2>getInput(1), numRecordsIn);
	
	// get serializers and comparators
	final TypeSerializer<IT1> serializer1 = this.taskContext.<IT1>getInputSerializer(0).getSerializer();
	final TypeSerializer<IT2> serializer2 = this.taskContext.<IT2>getInputSerializer(1).getSerializer();
	final TypeComparator<IT1> comparator1 = this.taskContext.getDriverComparator(0);
	final TypeComparator<IT2> comparator2 = this.taskContext.getDriverComparator(1);
	
	final TypePairComparatorFactory<IT1, IT2> pairComparatorFactory = config.getPairComparatorFactory(this.taskContext.getUserCodeClassLoader());
	
	if (pairComparatorFactory == null) {
		throw new Exception("Missing pair comparator factory for outer join driver");
	}
	
	ExecutionConfig executionConfig = taskContext.getExecutionConfig();
	boolean objectReuseEnabled = executionConfig.isObjectReuseEnabled();
	
	if (LOG.isDebugEnabled()) {
		LOG.debug("Outer Join Driver object reuse: " + (objectReuseEnabled ? "ENABLED" : "DISABLED") + ".");
	}
	
	// create and return outer join iterator according to provided local strategy.
	if (objectReuseEnabled) {
		this.outerJoinIterator = getReusingOuterJoinIterator(
				ls,
				in1,
				in2,
				serializer1,
				comparator1,
				serializer2,
				comparator2,
				pairComparatorFactory,
				memoryManager,
				ioManager,
				driverMemFraction
		);
	} else {
		this.outerJoinIterator = getNonReusingOuterJoinIterator(
				ls,
				in1,
				in2,
				serializer1,
				comparator1,
				serializer2,
				comparator2,
				pairComparatorFactory,
				memoryManager,
				ioManager,
				driverMemFraction
		);
	}
	
	this.outerJoinIterator.open();
	
	if (LOG.isDebugEnabled()) {
		LOG.debug(this.taskContext.formatLogString("outer join task iterator ready."));
	}
}
 
Example #7
Source File: CoGroupDriver.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void prepare() throws Exception
{
	final TaskConfig config = this.taskContext.getTaskConfig();
	if (config.getDriverStrategy() != DriverStrategy.CO_GROUP) {
		throw new Exception("Unrecognized driver strategy for CoGoup driver: " + config.getDriverStrategy().name());
	}

	final Counter numRecordsIn = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsInCounter();
	
	final MutableObjectIterator<IT1> in1 = new CountingMutableObjectIterator<>(this.taskContext.<IT1>getInput(0), numRecordsIn);
	final MutableObjectIterator<IT2> in2 = new CountingMutableObjectIterator<>(this.taskContext.<IT2>getInput(1), numRecordsIn);
	
	// get the key positions and types
	final TypeSerializer<IT1> serializer1 = this.taskContext.<IT1>getInputSerializer(0).getSerializer();
	final TypeSerializer<IT2> serializer2 = this.taskContext.<IT2>getInputSerializer(1).getSerializer();
	final TypeComparator<IT1> groupComparator1 = this.taskContext.getDriverComparator(0);
	final TypeComparator<IT2> groupComparator2 = this.taskContext.getDriverComparator(1);
	
	final TypePairComparatorFactory<IT1, IT2> pairComparatorFactory = config.getPairComparatorFactory(
				this.taskContext.getUserCodeClassLoader());
	if (pairComparatorFactory == null) {
		throw new Exception("Missing pair comparator factory for CoGroup driver");
	}

	ExecutionConfig executionConfig = taskContext.getExecutionConfig();
	this.objectReuseEnabled = executionConfig.isObjectReuseEnabled();

	if (LOG.isDebugEnabled()) {
		LOG.debug("CoGroupDriver object reuse: " + (this.objectReuseEnabled ? "ENABLED" : "DISABLED") + ".");
	}

	if (objectReuseEnabled) {
		// create CoGroupTaskIterator according to provided local strategy.
		this.coGroupIterator = new ReusingSortMergeCoGroupIterator<IT1, IT2>(
				in1, in2,
				serializer1, groupComparator1,
				serializer2, groupComparator2,
				pairComparatorFactory.createComparator12(groupComparator1, groupComparator2));
	} else {
		// create CoGroupTaskIterator according to provided local strategy.
		this.coGroupIterator = new NonReusingSortMergeCoGroupIterator<IT1, IT2>(
				in1, in2,
				serializer1, groupComparator1,
				serializer2, groupComparator2,
				pairComparatorFactory.createComparator12(groupComparator1, groupComparator2));
	}
	
	// open CoGroupTaskIterator - this triggers the sorting and blocks until the iterator is ready
	this.coGroupIterator.open();
	
	if (LOG.isDebugEnabled()) {
		LOG.debug(this.taskContext.formatLogString("CoGroup task iterator ready."));
	}
}
 
Example #8
Source File: AbstractCachedBuildSideJoinDriver.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize() throws Exception {
	TaskConfig config = this.taskContext.getTaskConfig();

	final Counter numRecordsIn = taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsInCounter();
	
	TypeSerializer<IT1> serializer1 = this.taskContext.<IT1>getInputSerializer(0).getSerializer();
	TypeSerializer<IT2> serializer2 = this.taskContext.<IT2>getInputSerializer(1).getSerializer();
	TypeComparator<IT1> comparator1 = this.taskContext.getDriverComparator(0);
	TypeComparator<IT2> comparator2 = this.taskContext.getDriverComparator(1);
	MutableObjectIterator<IT1> input1 = new CountingMutableObjectIterator<>(this.taskContext.<IT1>getInput(0), numRecordsIn);
	MutableObjectIterator<IT2> input2 = new CountingMutableObjectIterator<>(this.taskContext.<IT2>getInput(1), numRecordsIn);

	TypePairComparatorFactory<IT1, IT2> pairComparatorFactory = 
			this.taskContext.getTaskConfig().getPairComparatorFactory(this.taskContext.getUserCodeClassLoader());

	double availableMemory = config.getRelativeMemoryDriver();
	boolean hashJoinUseBitMaps = taskContext.getTaskManagerInfo().getConfiguration()
		.getBoolean(AlgorithmOptions.HASH_JOIN_BLOOM_FILTERS);
	
	ExecutionConfig executionConfig = taskContext.getExecutionConfig();
	objectReuseEnabled = executionConfig.isObjectReuseEnabled();

	if (objectReuseEnabled) {
		if (buildSideIndex == 0 && probeSideIndex == 1) {

			matchIterator = new ReusingBuildFirstReOpenableHashJoinIterator<IT1, IT2, OT>(
					input1, input2,
					serializer1, comparator1,
					serializer2, comparator2,
					pairComparatorFactory.createComparator21(comparator1, comparator2),
					this.taskContext.getMemoryManager(),
					this.taskContext.getIOManager(),
					this.taskContext.getContainingTask(),
					availableMemory,
					false,
					false,
					hashJoinUseBitMaps);


		} else if (buildSideIndex == 1 && probeSideIndex == 0) {

			matchIterator = new ReusingBuildSecondReOpenableHashJoinIterator<IT1, IT2, OT>(
					input1, input2,
					serializer1, comparator1,
					serializer2, comparator2,
					pairComparatorFactory.createComparator12(comparator1, comparator2),
					this.taskContext.getMemoryManager(),
					this.taskContext.getIOManager(),
					this.taskContext.getContainingTask(),
					availableMemory,
					false,
					false,
					hashJoinUseBitMaps);

		} else {
			throw new Exception("Error: Inconsistent setup for repeatable hash join driver.");
		}
	} else {
		if (buildSideIndex == 0 && probeSideIndex == 1) {

			matchIterator = new NonReusingBuildFirstReOpenableHashJoinIterator<IT1, IT2, OT>(
					input1, input2,
					serializer1, comparator1,
					serializer2, comparator2,
					pairComparatorFactory.createComparator21(comparator1, comparator2),
					this.taskContext.getMemoryManager(),
					this.taskContext.getIOManager(),
					this.taskContext.getContainingTask(),
					availableMemory,
					false,
					false,
					hashJoinUseBitMaps);


		} else if (buildSideIndex == 1 && probeSideIndex == 0) {

			matchIterator = new NonReusingBuildSecondReOpenableHashJoinIterator<IT1, IT2, OT>(
					input1, input2,
					serializer1, comparator1,
					serializer2, comparator2,
					pairComparatorFactory.createComparator12(comparator1, comparator2),
					this.taskContext.getMemoryManager(),
					this.taskContext.getIOManager(),
					this.taskContext.getContainingTask(),
					availableMemory,
					false,
					false,
					hashJoinUseBitMaps);

		} else {
			throw new Exception("Error: Inconsistent setup for repeatable hash join driver.");
		}
	}
	
	this.matchIterator.open();
}
 
Example #9
Source File: AbstractOuterJoinDriver.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void prepare() throws Exception {
	final TaskConfig config = this.taskContext.getTaskConfig();
	
	// obtain task manager's memory manager and I/O manager
	final MemoryManager memoryManager = this.taskContext.getMemoryManager();
	final IOManager ioManager = this.taskContext.getIOManager();
	
	// set up memory and I/O parameters
	final double driverMemFraction = config.getRelativeMemoryDriver();
	
	final DriverStrategy ls = config.getDriverStrategy();

	final Counter numRecordsIn = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsInCounter();
	final MutableObjectIterator<IT1> in1 = new CountingMutableObjectIterator<>(this.taskContext.<IT1>getInput(0), numRecordsIn);
	final MutableObjectIterator<IT2> in2 = new CountingMutableObjectIterator<>(this.taskContext.<IT2>getInput(1), numRecordsIn);
	
	// get serializers and comparators
	final TypeSerializer<IT1> serializer1 = this.taskContext.<IT1>getInputSerializer(0).getSerializer();
	final TypeSerializer<IT2> serializer2 = this.taskContext.<IT2>getInputSerializer(1).getSerializer();
	final TypeComparator<IT1> comparator1 = this.taskContext.getDriverComparator(0);
	final TypeComparator<IT2> comparator2 = this.taskContext.getDriverComparator(1);
	
	final TypePairComparatorFactory<IT1, IT2> pairComparatorFactory = config.getPairComparatorFactory(this.taskContext.getUserCodeClassLoader());
	
	if (pairComparatorFactory == null) {
		throw new Exception("Missing pair comparator factory for outer join driver");
	}
	
	ExecutionConfig executionConfig = taskContext.getExecutionConfig();
	boolean objectReuseEnabled = executionConfig.isObjectReuseEnabled();
	
	if (LOG.isDebugEnabled()) {
		LOG.debug("Outer Join Driver object reuse: " + (objectReuseEnabled ? "ENABLED" : "DISABLED") + ".");
	}
	
	// create and return outer join iterator according to provided local strategy.
	if (objectReuseEnabled) {
		this.outerJoinIterator = getReusingOuterJoinIterator(
				ls,
				in1,
				in2,
				serializer1,
				comparator1,
				serializer2,
				comparator2,
				pairComparatorFactory,
				memoryManager,
				ioManager,
				driverMemFraction
		);
	} else {
		this.outerJoinIterator = getNonReusingOuterJoinIterator(
				ls,
				in1,
				in2,
				serializer1,
				comparator1,
				serializer2,
				comparator2,
				pairComparatorFactory,
				memoryManager,
				ioManager,
				driverMemFraction
		);
	}
	
	this.outerJoinIterator.open();
	
	if (LOG.isDebugEnabled()) {
		LOG.debug(this.taskContext.formatLogString("outer join task iterator ready."));
	}
}
 
Example #10
Source File: CoGroupDriver.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void prepare() throws Exception
{
	final TaskConfig config = this.taskContext.getTaskConfig();
	if (config.getDriverStrategy() != DriverStrategy.CO_GROUP) {
		throw new Exception("Unrecognized driver strategy for CoGoup driver: " + config.getDriverStrategy().name());
	}

	final Counter numRecordsIn = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsInCounter();
	
	final MutableObjectIterator<IT1> in1 = new CountingMutableObjectIterator<>(this.taskContext.<IT1>getInput(0), numRecordsIn);
	final MutableObjectIterator<IT2> in2 = new CountingMutableObjectIterator<>(this.taskContext.<IT2>getInput(1), numRecordsIn);
	
	// get the key positions and types
	final TypeSerializer<IT1> serializer1 = this.taskContext.<IT1>getInputSerializer(0).getSerializer();
	final TypeSerializer<IT2> serializer2 = this.taskContext.<IT2>getInputSerializer(1).getSerializer();
	final TypeComparator<IT1> groupComparator1 = this.taskContext.getDriverComparator(0);
	final TypeComparator<IT2> groupComparator2 = this.taskContext.getDriverComparator(1);
	
	final TypePairComparatorFactory<IT1, IT2> pairComparatorFactory = config.getPairComparatorFactory(
				this.taskContext.getUserCodeClassLoader());
	if (pairComparatorFactory == null) {
		throw new Exception("Missing pair comparator factory for CoGroup driver");
	}

	ExecutionConfig executionConfig = taskContext.getExecutionConfig();
	this.objectReuseEnabled = executionConfig.isObjectReuseEnabled();

	if (LOG.isDebugEnabled()) {
		LOG.debug("CoGroupDriver object reuse: " + (this.objectReuseEnabled ? "ENABLED" : "DISABLED") + ".");
	}

	if (objectReuseEnabled) {
		// create CoGroupTaskIterator according to provided local strategy.
		this.coGroupIterator = new ReusingSortMergeCoGroupIterator<IT1, IT2>(
				in1, in2,
				serializer1, groupComparator1,
				serializer2, groupComparator2,
				pairComparatorFactory.createComparator12(groupComparator1, groupComparator2));
	} else {
		// create CoGroupTaskIterator according to provided local strategy.
		this.coGroupIterator = new NonReusingSortMergeCoGroupIterator<IT1, IT2>(
				in1, in2,
				serializer1, groupComparator1,
				serializer2, groupComparator2,
				pairComparatorFactory.createComparator12(groupComparator1, groupComparator2));
	}
	
	// open CoGroupTaskIterator - this triggers the sorting and blocks until the iterator is ready
	this.coGroupIterator.open();
	
	if (LOG.isDebugEnabled()) {
		LOG.debug(this.taskContext.formatLogString("CoGroup task iterator ready."));
	}
}
 
Example #11
Source File: AbstractCachedBuildSideJoinDriver.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize() throws Exception {
	TaskConfig config = this.taskContext.getTaskConfig();

	final Counter numRecordsIn = taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsInCounter();
	
	TypeSerializer<IT1> serializer1 = this.taskContext.<IT1>getInputSerializer(0).getSerializer();
	TypeSerializer<IT2> serializer2 = this.taskContext.<IT2>getInputSerializer(1).getSerializer();
	TypeComparator<IT1> comparator1 = this.taskContext.getDriverComparator(0);
	TypeComparator<IT2> comparator2 = this.taskContext.getDriverComparator(1);
	MutableObjectIterator<IT1> input1 = new CountingMutableObjectIterator<>(this.taskContext.<IT1>getInput(0), numRecordsIn);
	MutableObjectIterator<IT2> input2 = new CountingMutableObjectIterator<>(this.taskContext.<IT2>getInput(1), numRecordsIn);

	TypePairComparatorFactory<IT1, IT2> pairComparatorFactory = 
			this.taskContext.getTaskConfig().getPairComparatorFactory(this.taskContext.getUserCodeClassLoader());

	double availableMemory = config.getRelativeMemoryDriver();
	boolean hashJoinUseBitMaps = taskContext.getTaskManagerInfo().getConfiguration()
		.getBoolean(AlgorithmOptions.HASH_JOIN_BLOOM_FILTERS);
	
	ExecutionConfig executionConfig = taskContext.getExecutionConfig();
	objectReuseEnabled = executionConfig.isObjectReuseEnabled();

	if (objectReuseEnabled) {
		if (buildSideIndex == 0 && probeSideIndex == 1) {

			matchIterator = new ReusingBuildFirstReOpenableHashJoinIterator<IT1, IT2, OT>(
					input1, input2,
					serializer1, comparator1,
					serializer2, comparator2,
					pairComparatorFactory.createComparator21(comparator1, comparator2),
					this.taskContext.getMemoryManager(),
					this.taskContext.getIOManager(),
					this.taskContext.getContainingTask(),
					availableMemory,
					false,
					false,
					hashJoinUseBitMaps);


		} else if (buildSideIndex == 1 && probeSideIndex == 0) {

			matchIterator = new ReusingBuildSecondReOpenableHashJoinIterator<IT1, IT2, OT>(
					input1, input2,
					serializer1, comparator1,
					serializer2, comparator2,
					pairComparatorFactory.createComparator12(comparator1, comparator2),
					this.taskContext.getMemoryManager(),
					this.taskContext.getIOManager(),
					this.taskContext.getContainingTask(),
					availableMemory,
					false,
					false,
					hashJoinUseBitMaps);

		} else {
			throw new Exception("Error: Inconsistent setup for repeatable hash join driver.");
		}
	} else {
		if (buildSideIndex == 0 && probeSideIndex == 1) {

			matchIterator = new NonReusingBuildFirstReOpenableHashJoinIterator<IT1, IT2, OT>(
					input1, input2,
					serializer1, comparator1,
					serializer2, comparator2,
					pairComparatorFactory.createComparator21(comparator1, comparator2),
					this.taskContext.getMemoryManager(),
					this.taskContext.getIOManager(),
					this.taskContext.getContainingTask(),
					availableMemory,
					false,
					false,
					hashJoinUseBitMaps);


		} else if (buildSideIndex == 1 && probeSideIndex == 0) {

			matchIterator = new NonReusingBuildSecondReOpenableHashJoinIterator<IT1, IT2, OT>(
					input1, input2,
					serializer1, comparator1,
					serializer2, comparator2,
					pairComparatorFactory.createComparator12(comparator1, comparator2),
					this.taskContext.getMemoryManager(),
					this.taskContext.getIOManager(),
					this.taskContext.getContainingTask(),
					availableMemory,
					false,
					false,
					hashJoinUseBitMaps);

		} else {
			throw new Exception("Error: Inconsistent setup for repeatable hash join driver.");
		}
	}
	
	this.matchIterator.open();
}
 
Example #12
Source File: AbstractOuterJoinDriver.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void prepare() throws Exception {
	final TaskConfig config = this.taskContext.getTaskConfig();
	
	// obtain task manager's memory manager and I/O manager
	final MemoryManager memoryManager = this.taskContext.getMemoryManager();
	final IOManager ioManager = this.taskContext.getIOManager();
	
	// set up memory and I/O parameters
	final double driverMemFraction = config.getRelativeMemoryDriver();
	
	final DriverStrategy ls = config.getDriverStrategy();

	final Counter numRecordsIn = this.taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsInCounter();
	final MutableObjectIterator<IT1> in1 = new CountingMutableObjectIterator<>(this.taskContext.<IT1>getInput(0), numRecordsIn);
	final MutableObjectIterator<IT2> in2 = new CountingMutableObjectIterator<>(this.taskContext.<IT2>getInput(1), numRecordsIn);
	
	// get serializers and comparators
	final TypeSerializer<IT1> serializer1 = this.taskContext.<IT1>getInputSerializer(0).getSerializer();
	final TypeSerializer<IT2> serializer2 = this.taskContext.<IT2>getInputSerializer(1).getSerializer();
	final TypeComparator<IT1> comparator1 = this.taskContext.getDriverComparator(0);
	final TypeComparator<IT2> comparator2 = this.taskContext.getDriverComparator(1);
	
	final TypePairComparatorFactory<IT1, IT2> pairComparatorFactory = config.getPairComparatorFactory(this.taskContext.getUserCodeClassLoader());
	
	if (pairComparatorFactory == null) {
		throw new Exception("Missing pair comparator factory for outer join driver");
	}
	
	ExecutionConfig executionConfig = taskContext.getExecutionConfig();
	boolean objectReuseEnabled = executionConfig.isObjectReuseEnabled();
	
	if (LOG.isDebugEnabled()) {
		LOG.debug("Outer Join Driver object reuse: " + (objectReuseEnabled ? "ENABLED" : "DISABLED") + ".");
	}
	
	// create and return outer join iterator according to provided local strategy.
	if (objectReuseEnabled) {
		this.outerJoinIterator = getReusingOuterJoinIterator(
				ls,
				in1,
				in2,
				serializer1,
				comparator1,
				serializer2,
				comparator2,
				pairComparatorFactory,
				memoryManager,
				ioManager,
				driverMemFraction
		);
	} else {
		this.outerJoinIterator = getNonReusingOuterJoinIterator(
				ls,
				in1,
				in2,
				serializer1,
				comparator1,
				serializer2,
				comparator2,
				pairComparatorFactory,
				memoryManager,
				ioManager,
				driverMemFraction
		);
	}
	
	this.outerJoinIterator.open();
	
	if (LOG.isDebugEnabled()) {
		LOG.debug(this.taskContext.formatLogString("outer join task iterator ready."));
	}
}