Java Code Examples for org.apache.flink.api.common.typeutils.TypePairComparatorFactory#createComparator21()

The following examples show how to use org.apache.flink.api.common.typeutils.TypePairComparatorFactory#createComparator21() . 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: CoGroupWithSolutionSetFirstDriver.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void initialize() {
	
	final TypeComparator<IT1> solutionSetComparator;
	
	// grab a handle to the hash table from the iteration broker
	if (taskContext instanceof AbstractIterativeTask) {
		AbstractIterativeTask<?, ?> iterativeTaskContext = (AbstractIterativeTask<?, ?>) taskContext;
		String identifier = iterativeTaskContext.brokerKey();
		
		Object table = SolutionSetBroker.instance().get(identifier);
		if (table instanceof CompactingHashTable) {
			this.hashTable = (CompactingHashTable<IT1>) table;
			solutionSetSerializer = this.hashTable.getBuildSideSerializer();
			solutionSetComparator = this.hashTable.getBuildSideComparator().duplicate();
		}
		else if (table instanceof JoinHashMap) {
			this.objectMap = (JoinHashMap<IT1>) table;
			solutionSetSerializer = this.objectMap.getBuildSerializer();
			solutionSetComparator = this.objectMap.getBuildComparator().duplicate();
		}
		else {
			throw new RuntimeException("Unrecognized solution set index: " + table);
		}
	} else {
		throw new RuntimeException("The task context of this driver is no iterative task context.");
	}
	
	TaskConfig config = taskContext.getTaskConfig();
	ClassLoader classLoader = taskContext.getUserCodeClassLoader();
	
	TypeComparatorFactory<IT2> probeSideComparatorFactory = config.getDriverComparator(0, classLoader);
	
	this.probeSideSerializer = taskContext.<IT2>getInputSerializer(0).getSerializer();
	this.probeSideComparator = probeSideComparatorFactory.createComparator();
	
	ExecutionConfig executionConfig = taskContext.getExecutionConfig();
	objectReuseEnabled = executionConfig.isObjectReuseEnabled();

	if (objectReuseEnabled) {
		solutionSideRecord = solutionSetSerializer.createInstance();
	}
	
	TypePairComparatorFactory<IT1, IT2> factory = taskContext.getTaskConfig().getPairComparatorFactory(taskContext.getUserCodeClassLoader());
	pairComparator = factory.createComparator21(solutionSetComparator, this.probeSideComparator);
}
 
Example 2
Source File: LeftOuterJoinDriver.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected JoinTaskIterator<IT1, IT2, OT> getNonReusingOuterJoinIterator(
		DriverStrategy driverStrategy,
		MutableObjectIterator<IT1> in1,
		MutableObjectIterator<IT2> in2,
		TypeSerializer<IT1> serializer1,
		TypeComparator<IT1> comparator1,
		TypeSerializer<IT2> serializer2,
		TypeComparator<IT2> comparator2,
		TypePairComparatorFactory<IT1, IT2> pairComparatorFactory,
		MemoryManager memoryManager,
		IOManager ioManager,
		double driverMemFraction
) throws Exception {
	switch (driverStrategy) {
		case LEFT_OUTER_MERGE:
			int numPages = memoryManager.computeNumberOfPages(driverMemFraction);
			return new NonReusingMergeOuterJoinIterator<>(
					OuterJoinType.LEFT,
					in1,
					in2,
					serializer1,
					comparator1,
					serializer2,
					comparator2,
					pairComparatorFactory.createComparator12(comparator1, comparator2),
					memoryManager,
					ioManager,
					numPages,
					super.taskContext.getContainingTask()
			);
		case LEFT_HYBRIDHASH_BUILD_FIRST:
			return new NonReusingBuildFirstHashJoinIterator<>(in1, in2,
					serializer1, comparator1,
					serializer2, comparator2,
					pairComparatorFactory.createComparator21(comparator1, comparator2),
					memoryManager, ioManager,
					this.taskContext.getContainingTask(),
					driverMemFraction,
					false,
					true,
					false);
		case LEFT_HYBRIDHASH_BUILD_SECOND:
			return new NonReusingBuildSecondHashJoinIterator<>(in1, in2,
					serializer1, comparator1,
					serializer2, comparator2,
					pairComparatorFactory.createComparator12(comparator1, comparator2),
					memoryManager, ioManager,
					this.taskContext.getContainingTask(),
					driverMemFraction,
					true,
					false,
					false);
		default:
			throw new Exception("Unsupported driver strategy for left outer join driver: " + driverStrategy.name());
	}
}
 
Example 3
Source File: LeftOuterJoinDriver.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected JoinTaskIterator<IT1, IT2, OT> getReusingOuterJoinIterator(
		DriverStrategy driverStrategy,
		MutableObjectIterator<IT1> in1,
		MutableObjectIterator<IT2> in2,
		TypeSerializer<IT1> serializer1,
		TypeComparator<IT1> comparator1,
		TypeSerializer<IT2> serializer2,
		TypeComparator<IT2> comparator2,
		TypePairComparatorFactory<IT1, IT2> pairComparatorFactory,
		MemoryManager memoryManager,
		IOManager ioManager,
		double driverMemFraction
) throws Exception {
	switch (driverStrategy) {
		case LEFT_OUTER_MERGE:
			int numPages = memoryManager.computeNumberOfPages(driverMemFraction);
			return new ReusingMergeOuterJoinIterator<>(
					OuterJoinType.LEFT,
					in1,
					in2,
					serializer1,
					comparator1,
					serializer2,
					comparator2,
					pairComparatorFactory.createComparator12(comparator1, comparator2),
					memoryManager,
					ioManager,
					numPages,
					super.taskContext.getContainingTask()
			);
		case LEFT_HYBRIDHASH_BUILD_FIRST:
			return new ReusingBuildFirstHashJoinIterator<>(in1, in2,
					serializer1, comparator1,
					serializer2, comparator2,
					pairComparatorFactory.createComparator21(comparator1, comparator2),
					memoryManager, ioManager,
					this.taskContext.getContainingTask(),
					driverMemFraction,
					false,
					true,
					false);
		case LEFT_HYBRIDHASH_BUILD_SECOND:
			return new ReusingBuildSecondHashJoinIterator<>(in1, in2,
					serializer1, comparator1,
					serializer2, comparator2,
					pairComparatorFactory.createComparator12(comparator1, comparator2),
					memoryManager, ioManager,
					this.taskContext.getContainingTask(),
					driverMemFraction,
					true,
					false,
					false);
		default:
			throw new Exception("Unsupported driver strategy for left outer join driver: " + driverStrategy.name());
	}
}
 
Example 4
Source File: RightOuterJoinDriver.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected JoinTaskIterator<IT1, IT2, OT> getReusingOuterJoinIterator(
		DriverStrategy driverStrategy,
		MutableObjectIterator<IT1> in1,
		MutableObjectIterator<IT2> in2,
		TypeSerializer<IT1> serializer1,
		TypeComparator<IT1> comparator1,
		TypeSerializer<IT2> serializer2,
		TypeComparator<IT2> comparator2,
		TypePairComparatorFactory<IT1, IT2> pairComparatorFactory,
		MemoryManager memoryManager,
		IOManager ioManager,
		double driverMemFraction
) throws Exception {
	switch (driverStrategy) {
		case RIGHT_OUTER_MERGE:
			int numPages = memoryManager.computeNumberOfPages(driverMemFraction);
			return new ReusingMergeOuterJoinIterator<>(
					OuterJoinType.RIGHT,
					in1,
					in2,
					serializer1,
					comparator1,
					serializer2,
					comparator2,
					pairComparatorFactory.createComparator12(comparator1, comparator2),
					memoryManager,
					ioManager,
					numPages,
					super.taskContext.getContainingTask()
			);
		case RIGHT_HYBRIDHASH_BUILD_FIRST:
			return new ReusingBuildFirstHashJoinIterator<>(in1, in2,
					serializer1, comparator1,
					serializer2, comparator2,
					pairComparatorFactory.createComparator21(comparator1, comparator2),
					memoryManager, ioManager,
					this.taskContext.getContainingTask(),
					driverMemFraction,
					true,
					false,
					false);
		case RIGHT_HYBRIDHASH_BUILD_SECOND:
			return new ReusingBuildSecondHashJoinIterator<>(in1, in2,
					serializer1, comparator1,
					serializer2, comparator2,
					pairComparatorFactory.createComparator12(comparator1, comparator2),
					memoryManager, ioManager,
					this.taskContext.getContainingTask(),
					driverMemFraction,
					false,
					true,
					false);
		default:
			throw new Exception("Unsupported driver strategy for right outer join driver: " + driverStrategy.name());
	}
}
 
Example 5
Source File: RightOuterJoinDriver.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected JoinTaskIterator<IT1, IT2, OT> getNonReusingOuterJoinIterator(
		DriverStrategy driverStrategy,
		MutableObjectIterator<IT1> in1,
		MutableObjectIterator<IT2> in2,
		TypeSerializer<IT1> serializer1,
		TypeComparator<IT1> comparator1,
		TypeSerializer<IT2> serializer2,
		TypeComparator<IT2> comparator2,
		TypePairComparatorFactory<IT1, IT2> pairComparatorFactory,
		MemoryManager memoryManager,
		IOManager ioManager,
		double driverMemFraction
) throws Exception {
	switch (driverStrategy) {
		case RIGHT_OUTER_MERGE:
			int numPages = memoryManager.computeNumberOfPages(driverMemFraction);
			return new NonReusingMergeOuterJoinIterator<>(
					OuterJoinType.RIGHT,
					in1,
					in2,
					serializer1,
					comparator1,
					serializer2,
					comparator2,
					pairComparatorFactory.createComparator12(comparator1, comparator2),
					memoryManager,
					ioManager,
					numPages,
					super.taskContext.getContainingTask()
			);
		case RIGHT_HYBRIDHASH_BUILD_FIRST:
			return new NonReusingBuildFirstHashJoinIterator<>(in1, in2,
					serializer1, comparator1,
					serializer2, comparator2,
					pairComparatorFactory.createComparator21(comparator1, comparator2),
					memoryManager, ioManager,
					this.taskContext.getContainingTask(),
					driverMemFraction,
					true,
					false,
					false);
		case RIGHT_HYBRIDHASH_BUILD_SECOND:
			return new NonReusingBuildSecondHashJoinIterator<>(in1, in2,
					serializer1, comparator1,
					serializer2, comparator2,
					pairComparatorFactory.createComparator12(comparator1, comparator2),
					memoryManager, ioManager,
					this.taskContext.getContainingTask(),
					driverMemFraction,
					false,
					true,
					false);
		default:
			throw new Exception("Unsupported driver strategy for right outer join driver: " + driverStrategy.name());
	}
}
 
Example 6
Source File: FullOuterJoinDriver.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected JoinTaskIterator<IT1, IT2, OT> getReusingOuterJoinIterator(
		DriverStrategy driverStrategy,
		MutableObjectIterator<IT1> in1,
		MutableObjectIterator<IT2> in2,
		TypeSerializer<IT1> serializer1,
		TypeComparator<IT1> comparator1,
		TypeSerializer<IT2> serializer2,
		TypeComparator<IT2> comparator2,
		TypePairComparatorFactory<IT1, IT2> pairComparatorFactory,
		MemoryManager memoryManager,
		IOManager ioManager,
		double driverMemFraction
) throws Exception {
	switch (driverStrategy) {
		case FULL_OUTER_MERGE:
			int numPages = memoryManager.computeNumberOfPages(driverMemFraction);
			return new ReusingMergeOuterJoinIterator<>(
					OuterJoinType.FULL,
					in1,
					in2,
					serializer1,
					comparator1,
					serializer2,
					comparator2,
					pairComparatorFactory.createComparator12(comparator1, comparator2),
					memoryManager,
					ioManager,
					numPages,
					super.taskContext.getContainingTask()
			);
	case FULL_OUTER_HYBRIDHASH_BUILD_FIRST:
		return new ReusingBuildFirstHashJoinIterator<>(in1, in2,
				serializer1, comparator1,
				serializer2, comparator2,
				pairComparatorFactory.createComparator21(comparator1, comparator2),
				memoryManager, ioManager,
				this.taskContext.getContainingTask(),
				driverMemFraction,
				true,
				true,
				false);
	case FULL_OUTER_HYBRIDHASH_BUILD_SECOND:
		return new ReusingBuildSecondHashJoinIterator<>(in1, in2,
				serializer1, comparator1,
				serializer2, comparator2,
				pairComparatorFactory.createComparator12(comparator1, comparator2),
				memoryManager, ioManager,
				this.taskContext.getContainingTask(),
				driverMemFraction,
				true,
				true,
				false);
		default:
			throw new Exception("Unsupported driver strategy for full outer join driver: " + driverStrategy.name());
	}
}
 
Example 7
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 8
Source File: FullOuterJoinDriver.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected JoinTaskIterator<IT1, IT2, OT> getNonReusingOuterJoinIterator(
		DriverStrategy driverStrategy,
		MutableObjectIterator<IT1> in1,
		MutableObjectIterator<IT2> in2,
		TypeSerializer<IT1> serializer1,
		TypeComparator<IT1> comparator1,
		TypeSerializer<IT2> serializer2,
		TypeComparator<IT2> comparator2,
		TypePairComparatorFactory<IT1, IT2> pairComparatorFactory,
		MemoryManager memoryManager,
		IOManager ioManager,
		double driverMemFraction
) throws Exception {
	switch (driverStrategy) {
		case FULL_OUTER_MERGE:
			int numPages = memoryManager.computeNumberOfPages(driverMemFraction);
			return new NonReusingMergeOuterJoinIterator<>(
					OuterJoinType.FULL,
					in1,
					in2,
					serializer1,
					comparator1,
					serializer2,
					comparator2,
					pairComparatorFactory.createComparator12(comparator1, comparator2),
					memoryManager,
					ioManager,
					numPages,
					super.taskContext.getContainingTask()
			);
		case FULL_OUTER_HYBRIDHASH_BUILD_FIRST:
			return new NonReusingBuildFirstHashJoinIterator<>(in1, in2,
				serializer1, comparator1,
				serializer2, comparator2,
				pairComparatorFactory.createComparator21(comparator1, comparator2),
				memoryManager, ioManager,
				this.taskContext.getContainingTask(),
				driverMemFraction,
				true,
				true,
				false);
		case FULL_OUTER_HYBRIDHASH_BUILD_SECOND:
			return new NonReusingBuildSecondHashJoinIterator<>(in1, in2,
				serializer1, comparator1,
				serializer2, comparator2,
				pairComparatorFactory.createComparator12(comparator1, comparator2),
				memoryManager, ioManager,
				this.taskContext.getContainingTask(),
				driverMemFraction,
				true,
				true,
				false);
		default:
			throw new Exception("Unsupported driver strategy for full outer join driver: " + driverStrategy.name());
	}
}
 
Example 9
Source File: FullOuterJoinDriver.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected JoinTaskIterator<IT1, IT2, OT> getReusingOuterJoinIterator(
		DriverStrategy driverStrategy,
		MutableObjectIterator<IT1> in1,
		MutableObjectIterator<IT2> in2,
		TypeSerializer<IT1> serializer1,
		TypeComparator<IT1> comparator1,
		TypeSerializer<IT2> serializer2,
		TypeComparator<IT2> comparator2,
		TypePairComparatorFactory<IT1, IT2> pairComparatorFactory,
		MemoryManager memoryManager,
		IOManager ioManager,
		double driverMemFraction
) throws Exception {
	switch (driverStrategy) {
		case FULL_OUTER_MERGE:
			int numPages = memoryManager.computeNumberOfPages(driverMemFraction);
			return new ReusingMergeOuterJoinIterator<>(
					OuterJoinType.FULL,
					in1,
					in2,
					serializer1,
					comparator1,
					serializer2,
					comparator2,
					pairComparatorFactory.createComparator12(comparator1, comparator2),
					memoryManager,
					ioManager,
					numPages,
					super.taskContext.getContainingTask()
			);
	case FULL_OUTER_HYBRIDHASH_BUILD_FIRST:
		return new ReusingBuildFirstHashJoinIterator<>(in1, in2,
				serializer1, comparator1,
				serializer2, comparator2,
				pairComparatorFactory.createComparator21(comparator1, comparator2),
				memoryManager, ioManager,
				this.taskContext.getContainingTask(),
				driverMemFraction,
				true,
				true,
				false);
	case FULL_OUTER_HYBRIDHASH_BUILD_SECOND:
		return new ReusingBuildSecondHashJoinIterator<>(in1, in2,
				serializer1, comparator1,
				serializer2, comparator2,
				pairComparatorFactory.createComparator12(comparator1, comparator2),
				memoryManager, ioManager,
				this.taskContext.getContainingTask(),
				driverMemFraction,
				true,
				true,
				false);
		default:
			throw new Exception("Unsupported driver strategy for full outer join driver: " + driverStrategy.name());
	}
}
 
Example 10
Source File: CoGroupWithSolutionSetFirstDriver.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void initialize() {
	
	final TypeComparator<IT1> solutionSetComparator;
	
	// grab a handle to the hash table from the iteration broker
	if (taskContext instanceof AbstractIterativeTask) {
		AbstractIterativeTask<?, ?> iterativeTaskContext = (AbstractIterativeTask<?, ?>) taskContext;
		String identifier = iterativeTaskContext.brokerKey();
		
		Object table = SolutionSetBroker.instance().get(identifier);
		if (table instanceof CompactingHashTable) {
			this.hashTable = (CompactingHashTable<IT1>) table;
			solutionSetSerializer = this.hashTable.getBuildSideSerializer();
			solutionSetComparator = this.hashTable.getBuildSideComparator().duplicate();
		}
		else if (table instanceof JoinHashMap) {
			this.objectMap = (JoinHashMap<IT1>) table;
			solutionSetSerializer = this.objectMap.getBuildSerializer();
			solutionSetComparator = this.objectMap.getBuildComparator().duplicate();
		}
		else {
			throw new RuntimeException("Unrecognized solution set index: " + table);
		}
	} else {
		throw new RuntimeException("The task context of this driver is no iterative task context.");
	}
	
	TaskConfig config = taskContext.getTaskConfig();
	ClassLoader classLoader = taskContext.getUserCodeClassLoader();
	
	TypeComparatorFactory<IT2> probeSideComparatorFactory = config.getDriverComparator(0, classLoader);
	
	this.probeSideSerializer = taskContext.<IT2>getInputSerializer(0).getSerializer();
	this.probeSideComparator = probeSideComparatorFactory.createComparator();
	
	ExecutionConfig executionConfig = taskContext.getExecutionConfig();
	objectReuseEnabled = executionConfig.isObjectReuseEnabled();

	if (objectReuseEnabled) {
		solutionSideRecord = solutionSetSerializer.createInstance();
	}
	
	TypePairComparatorFactory<IT1, IT2> factory = taskContext.getTaskConfig().getPairComparatorFactory(taskContext.getUserCodeClassLoader());
	pairComparator = factory.createComparator21(solutionSetComparator, this.probeSideComparator);
}
 
Example 11
Source File: JoinWithSolutionSetFirstDriver.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void initialize() {
	
	final TypeSerializer<IT1> solutionSetSerializer;
	final TypeComparator<IT1> solutionSetComparator;
	
	// grab a handle to the hash table from the iteration broker
	if (taskContext instanceof AbstractIterativeTask) {
		AbstractIterativeTask<?, ?> iterativeTaskContext = (AbstractIterativeTask<?, ?>) taskContext;
		String identifier = iterativeTaskContext.brokerKey();
		
		Object table = SolutionSetBroker.instance().get(identifier);
		if (table instanceof CompactingHashTable) {
			this.hashTable = (CompactingHashTable<IT1>) table;
			solutionSetSerializer = this.hashTable.getBuildSideSerializer();
			solutionSetComparator = this.hashTable.getBuildSideComparator().duplicate();
		}
		else if (table instanceof JoinHashMap) {
			this.objectMap = (JoinHashMap<IT1>) table;
			solutionSetSerializer = this.objectMap.getBuildSerializer();
			solutionSetComparator = this.objectMap.getBuildComparator().duplicate();
		}
		else {
			throw new RuntimeException("Unrecognized solution set index: " + table);
		}
	} else {
		throw new RuntimeException("The task context of this driver is no iterative task context.");
	}
	
	TaskConfig config = taskContext.getTaskConfig();
	ClassLoader classLoader = taskContext.getUserCodeClassLoader();
	
	TypeSerializer<IT2> probeSideSerializer = taskContext.<IT2>getInputSerializer(0).getSerializer();
	
	TypeComparatorFactory<IT2> probeSideComparatorFactory = config.getDriverComparator(0, classLoader);
	this.probeSideComparator = probeSideComparatorFactory.createComparator();

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

	if (objectReuseEnabled) {
		solutionSideRecord = solutionSetSerializer.createInstance();
		probeSideRecord = probeSideSerializer.createInstance();
	}

	TypePairComparatorFactory<IT1, IT2> factory = taskContext.getTaskConfig().getPairComparatorFactory(taskContext.getUserCodeClassLoader());
	pairComparator = factory.createComparator21(solutionSetComparator, this.probeSideComparator);
}
 
Example 12
Source File: LeftOuterJoinDriver.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected JoinTaskIterator<IT1, IT2, OT> getReusingOuterJoinIterator(
		DriverStrategy driverStrategy,
		MutableObjectIterator<IT1> in1,
		MutableObjectIterator<IT2> in2,
		TypeSerializer<IT1> serializer1,
		TypeComparator<IT1> comparator1,
		TypeSerializer<IT2> serializer2,
		TypeComparator<IT2> comparator2,
		TypePairComparatorFactory<IT1, IT2> pairComparatorFactory,
		MemoryManager memoryManager,
		IOManager ioManager,
		double driverMemFraction
) throws Exception {
	switch (driverStrategy) {
		case LEFT_OUTER_MERGE:
			int numPages = memoryManager.computeNumberOfPages(driverMemFraction);
			return new ReusingMergeOuterJoinIterator<>(
					OuterJoinType.LEFT,
					in1,
					in2,
					serializer1,
					comparator1,
					serializer2,
					comparator2,
					pairComparatorFactory.createComparator12(comparator1, comparator2),
					memoryManager,
					ioManager,
					numPages,
					super.taskContext.getContainingTask()
			);
		case LEFT_HYBRIDHASH_BUILD_FIRST:
			return new ReusingBuildFirstHashJoinIterator<>(in1, in2,
					serializer1, comparator1,
					serializer2, comparator2,
					pairComparatorFactory.createComparator21(comparator1, comparator2),
					memoryManager, ioManager,
					this.taskContext.getContainingTask(),
					driverMemFraction,
					false,
					true,
					false);
		case LEFT_HYBRIDHASH_BUILD_SECOND:
			return new ReusingBuildSecondHashJoinIterator<>(in1, in2,
					serializer1, comparator1,
					serializer2, comparator2,
					pairComparatorFactory.createComparator12(comparator1, comparator2),
					memoryManager, ioManager,
					this.taskContext.getContainingTask(),
					driverMemFraction,
					true,
					false,
					false);
		default:
			throw new Exception("Unsupported driver strategy for left outer join driver: " + driverStrategy.name());
	}
}
 
Example 13
Source File: JoinWithSolutionSetFirstDriver.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void initialize() {
	
	final TypeSerializer<IT1> solutionSetSerializer;
	final TypeComparator<IT1> solutionSetComparator;
	
	// grab a handle to the hash table from the iteration broker
	if (taskContext instanceof AbstractIterativeTask) {
		AbstractIterativeTask<?, ?> iterativeTaskContext = (AbstractIterativeTask<?, ?>) taskContext;
		String identifier = iterativeTaskContext.brokerKey();
		
		Object table = SolutionSetBroker.instance().get(identifier);
		if (table instanceof CompactingHashTable) {
			this.hashTable = (CompactingHashTable<IT1>) table;
			solutionSetSerializer = this.hashTable.getBuildSideSerializer();
			solutionSetComparator = this.hashTable.getBuildSideComparator().duplicate();
		}
		else if (table instanceof JoinHashMap) {
			this.objectMap = (JoinHashMap<IT1>) table;
			solutionSetSerializer = this.objectMap.getBuildSerializer();
			solutionSetComparator = this.objectMap.getBuildComparator().duplicate();
		}
		else {
			throw new RuntimeException("Unrecognized solution set index: " + table);
		}
	} else {
		throw new RuntimeException("The task context of this driver is no iterative task context.");
	}
	
	TaskConfig config = taskContext.getTaskConfig();
	ClassLoader classLoader = taskContext.getUserCodeClassLoader();
	
	TypeSerializer<IT2> probeSideSerializer = taskContext.<IT2>getInputSerializer(0).getSerializer();
	
	TypeComparatorFactory<IT2> probeSideComparatorFactory = config.getDriverComparator(0, classLoader);
	this.probeSideComparator = probeSideComparatorFactory.createComparator();

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

	if (objectReuseEnabled) {
		solutionSideRecord = solutionSetSerializer.createInstance();
		probeSideRecord = probeSideSerializer.createInstance();
	}

	TypePairComparatorFactory<IT1, IT2> factory = taskContext.getTaskConfig().getPairComparatorFactory(taskContext.getUserCodeClassLoader());
	pairComparator = factory.createComparator21(solutionSetComparator, this.probeSideComparator);
}
 
Example 14
Source File: FullOuterJoinDriver.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected JoinTaskIterator<IT1, IT2, OT> getNonReusingOuterJoinIterator(
		DriverStrategy driverStrategy,
		MutableObjectIterator<IT1> in1,
		MutableObjectIterator<IT2> in2,
		TypeSerializer<IT1> serializer1,
		TypeComparator<IT1> comparator1,
		TypeSerializer<IT2> serializer2,
		TypeComparator<IT2> comparator2,
		TypePairComparatorFactory<IT1, IT2> pairComparatorFactory,
		MemoryManager memoryManager,
		IOManager ioManager,
		double driverMemFraction
) throws Exception {
	switch (driverStrategy) {
		case FULL_OUTER_MERGE:
			int numPages = memoryManager.computeNumberOfPages(driverMemFraction);
			return new NonReusingMergeOuterJoinIterator<>(
					OuterJoinType.FULL,
					in1,
					in2,
					serializer1,
					comparator1,
					serializer2,
					comparator2,
					pairComparatorFactory.createComparator12(comparator1, comparator2),
					memoryManager,
					ioManager,
					numPages,
					super.taskContext.getContainingTask()
			);
		case FULL_OUTER_HYBRIDHASH_BUILD_FIRST:
			return new NonReusingBuildFirstHashJoinIterator<>(in1, in2,
				serializer1, comparator1,
				serializer2, comparator2,
				pairComparatorFactory.createComparator21(comparator1, comparator2),
				memoryManager, ioManager,
				this.taskContext.getContainingTask(),
				driverMemFraction,
				true,
				true,
				false);
		case FULL_OUTER_HYBRIDHASH_BUILD_SECOND:
			return new NonReusingBuildSecondHashJoinIterator<>(in1, in2,
				serializer1, comparator1,
				serializer2, comparator2,
				pairComparatorFactory.createComparator12(comparator1, comparator2),
				memoryManager, ioManager,
				this.taskContext.getContainingTask(),
				driverMemFraction,
				true,
				true,
				false);
		default:
			throw new Exception("Unsupported driver strategy for full outer join driver: " + driverStrategy.name());
	}
}
 
Example 15
Source File: RightOuterJoinDriver.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
protected JoinTaskIterator<IT1, IT2, OT> getReusingOuterJoinIterator(
		DriverStrategy driverStrategy,
		MutableObjectIterator<IT1> in1,
		MutableObjectIterator<IT2> in2,
		TypeSerializer<IT1> serializer1,
		TypeComparator<IT1> comparator1,
		TypeSerializer<IT2> serializer2,
		TypeComparator<IT2> comparator2,
		TypePairComparatorFactory<IT1, IT2> pairComparatorFactory,
		MemoryManager memoryManager,
		IOManager ioManager,
		double driverMemFraction
) throws Exception {
	switch (driverStrategy) {
		case RIGHT_OUTER_MERGE:
			int numPages = memoryManager.computeNumberOfPages(driverMemFraction);
			return new ReusingMergeOuterJoinIterator<>(
					OuterJoinType.RIGHT,
					in1,
					in2,
					serializer1,
					comparator1,
					serializer2,
					comparator2,
					pairComparatorFactory.createComparator12(comparator1, comparator2),
					memoryManager,
					ioManager,
					numPages,
					super.taskContext.getContainingTask()
			);
		case RIGHT_HYBRIDHASH_BUILD_FIRST:
			return new ReusingBuildFirstHashJoinIterator<>(in1, in2,
					serializer1, comparator1,
					serializer2, comparator2,
					pairComparatorFactory.createComparator21(comparator1, comparator2),
					memoryManager, ioManager,
					this.taskContext.getContainingTask(),
					driverMemFraction,
					true,
					false,
					false);
		case RIGHT_HYBRIDHASH_BUILD_SECOND:
			return new ReusingBuildSecondHashJoinIterator<>(in1, in2,
					serializer1, comparator1,
					serializer2, comparator2,
					pairComparatorFactory.createComparator12(comparator1, comparator2),
					memoryManager, ioManager,
					this.taskContext.getContainingTask(),
					driverMemFraction,
					false,
					true,
					false);
		default:
			throw new Exception("Unsupported driver strategy for right outer join driver: " + driverStrategy.name());
	}
}
 
Example 16
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 17
Source File: FullOuterJoinDriver.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
protected JoinTaskIterator<IT1, IT2, OT> getNonReusingOuterJoinIterator(
		DriverStrategy driverStrategy,
		MutableObjectIterator<IT1> in1,
		MutableObjectIterator<IT2> in2,
		TypeSerializer<IT1> serializer1,
		TypeComparator<IT1> comparator1,
		TypeSerializer<IT2> serializer2,
		TypeComparator<IT2> comparator2,
		TypePairComparatorFactory<IT1, IT2> pairComparatorFactory,
		MemoryManager memoryManager,
		IOManager ioManager,
		double driverMemFraction
) throws Exception {
	switch (driverStrategy) {
		case FULL_OUTER_MERGE:
			int numPages = memoryManager.computeNumberOfPages(driverMemFraction);
			return new NonReusingMergeOuterJoinIterator<>(
					OuterJoinType.FULL,
					in1,
					in2,
					serializer1,
					comparator1,
					serializer2,
					comparator2,
					pairComparatorFactory.createComparator12(comparator1, comparator2),
					memoryManager,
					ioManager,
					numPages,
					super.taskContext.getContainingTask()
			);
		case FULL_OUTER_HYBRIDHASH_BUILD_FIRST:
			return new NonReusingBuildFirstHashJoinIterator<>(in1, in2,
				serializer1, comparator1,
				serializer2, comparator2,
				pairComparatorFactory.createComparator21(comparator1, comparator2),
				memoryManager, ioManager,
				this.taskContext.getContainingTask(),
				driverMemFraction,
				true,
				true,
				false);
		case FULL_OUTER_HYBRIDHASH_BUILD_SECOND:
			return new NonReusingBuildSecondHashJoinIterator<>(in1, in2,
				serializer1, comparator1,
				serializer2, comparator2,
				pairComparatorFactory.createComparator12(comparator1, comparator2),
				memoryManager, ioManager,
				this.taskContext.getContainingTask(),
				driverMemFraction,
				true,
				true,
				false);
		default:
			throw new Exception("Unsupported driver strategy for full outer join driver: " + driverStrategy.name());
	}
}
 
Example 18
Source File: FullOuterJoinDriver.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
protected JoinTaskIterator<IT1, IT2, OT> getReusingOuterJoinIterator(
		DriverStrategy driverStrategy,
		MutableObjectIterator<IT1> in1,
		MutableObjectIterator<IT2> in2,
		TypeSerializer<IT1> serializer1,
		TypeComparator<IT1> comparator1,
		TypeSerializer<IT2> serializer2,
		TypeComparator<IT2> comparator2,
		TypePairComparatorFactory<IT1, IT2> pairComparatorFactory,
		MemoryManager memoryManager,
		IOManager ioManager,
		double driverMemFraction
) throws Exception {
	switch (driverStrategy) {
		case FULL_OUTER_MERGE:
			int numPages = memoryManager.computeNumberOfPages(driverMemFraction);
			return new ReusingMergeOuterJoinIterator<>(
					OuterJoinType.FULL,
					in1,
					in2,
					serializer1,
					comparator1,
					serializer2,
					comparator2,
					pairComparatorFactory.createComparator12(comparator1, comparator2),
					memoryManager,
					ioManager,
					numPages,
					super.taskContext.getContainingTask()
			);
	case FULL_OUTER_HYBRIDHASH_BUILD_FIRST:
		return new ReusingBuildFirstHashJoinIterator<>(in1, in2,
				serializer1, comparator1,
				serializer2, comparator2,
				pairComparatorFactory.createComparator21(comparator1, comparator2),
				memoryManager, ioManager,
				this.taskContext.getContainingTask(),
				driverMemFraction,
				true,
				true,
				false);
	case FULL_OUTER_HYBRIDHASH_BUILD_SECOND:
		return new ReusingBuildSecondHashJoinIterator<>(in1, in2,
				serializer1, comparator1,
				serializer2, comparator2,
				pairComparatorFactory.createComparator12(comparator1, comparator2),
				memoryManager, ioManager,
				this.taskContext.getContainingTask(),
				driverMemFraction,
				true,
				true,
				false);
		default:
			throw new Exception("Unsupported driver strategy for full outer join driver: " + driverStrategy.name());
	}
}
 
Example 19
Source File: CoGroupWithSolutionSetFirstDriver.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void initialize() {
	
	final TypeComparator<IT1> solutionSetComparator;
	
	// grab a handle to the hash table from the iteration broker
	if (taskContext instanceof AbstractIterativeTask) {
		AbstractIterativeTask<?, ?> iterativeTaskContext = (AbstractIterativeTask<?, ?>) taskContext;
		String identifier = iterativeTaskContext.brokerKey();
		
		Object table = SolutionSetBroker.instance().get(identifier);
		if (table instanceof CompactingHashTable) {
			this.hashTable = (CompactingHashTable<IT1>) table;
			solutionSetSerializer = this.hashTable.getBuildSideSerializer();
			solutionSetComparator = this.hashTable.getBuildSideComparator().duplicate();
		}
		else if (table instanceof JoinHashMap) {
			this.objectMap = (JoinHashMap<IT1>) table;
			solutionSetSerializer = this.objectMap.getBuildSerializer();
			solutionSetComparator = this.objectMap.getBuildComparator().duplicate();
		}
		else {
			throw new RuntimeException("Unrecognized solution set index: " + table);
		}
	} else {
		throw new RuntimeException("The task context of this driver is no iterative task context.");
	}
	
	TaskConfig config = taskContext.getTaskConfig();
	ClassLoader classLoader = taskContext.getUserCodeClassLoader();
	
	TypeComparatorFactory<IT2> probeSideComparatorFactory = config.getDriverComparator(0, classLoader);
	
	this.probeSideSerializer = taskContext.<IT2>getInputSerializer(0).getSerializer();
	this.probeSideComparator = probeSideComparatorFactory.createComparator();
	
	ExecutionConfig executionConfig = taskContext.getExecutionConfig();
	objectReuseEnabled = executionConfig.isObjectReuseEnabled();

	if (objectReuseEnabled) {
		solutionSideRecord = solutionSetSerializer.createInstance();
	}
	
	TypePairComparatorFactory<IT1, IT2> factory = taskContext.getTaskConfig().getPairComparatorFactory(taskContext.getUserCodeClassLoader());
	pairComparator = factory.createComparator21(solutionSetComparator, this.probeSideComparator);
}
 
Example 20
Source File: LeftOuterJoinDriver.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
protected JoinTaskIterator<IT1, IT2, OT> getNonReusingOuterJoinIterator(
		DriverStrategy driverStrategy,
		MutableObjectIterator<IT1> in1,
		MutableObjectIterator<IT2> in2,
		TypeSerializer<IT1> serializer1,
		TypeComparator<IT1> comparator1,
		TypeSerializer<IT2> serializer2,
		TypeComparator<IT2> comparator2,
		TypePairComparatorFactory<IT1, IT2> pairComparatorFactory,
		MemoryManager memoryManager,
		IOManager ioManager,
		double driverMemFraction
) throws Exception {
	switch (driverStrategy) {
		case LEFT_OUTER_MERGE:
			int numPages = memoryManager.computeNumberOfPages(driverMemFraction);
			return new NonReusingMergeOuterJoinIterator<>(
					OuterJoinType.LEFT,
					in1,
					in2,
					serializer1,
					comparator1,
					serializer2,
					comparator2,
					pairComparatorFactory.createComparator12(comparator1, comparator2),
					memoryManager,
					ioManager,
					numPages,
					super.taskContext.getContainingTask()
			);
		case LEFT_HYBRIDHASH_BUILD_FIRST:
			return new NonReusingBuildFirstHashJoinIterator<>(in1, in2,
					serializer1, comparator1,
					serializer2, comparator2,
					pairComparatorFactory.createComparator21(comparator1, comparator2),
					memoryManager, ioManager,
					this.taskContext.getContainingTask(),
					driverMemFraction,
					false,
					true,
					false);
		case LEFT_HYBRIDHASH_BUILD_SECOND:
			return new NonReusingBuildSecondHashJoinIterator<>(in1, in2,
					serializer1, comparator1,
					serializer2, comparator2,
					pairComparatorFactory.createComparator12(comparator1, comparator2),
					memoryManager, ioManager,
					this.taskContext.getContainingTask(),
					driverMemFraction,
					true,
					false,
					false);
		default:
			throw new Exception("Unsupported driver strategy for left outer join driver: " + driverStrategy.name());
	}
}