Java Code Examples for org.apache.flink.api.common.typeutils.TypeSerializerFactory#getSerializer()

The following examples show how to use org.apache.flink.api.common.typeutils.TypeSerializerFactory#getSerializer() . 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: AllReduceDriver.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void prepare() throws Exception {
	final TaskConfig config = this.taskContext.getTaskConfig();
	if (config.getDriverStrategy() != DriverStrategy.ALL_REDUCE) {
		throw new Exception("Unrecognized driver strategy for AllReduce driver: " + config.getDriverStrategy().name());
	}
	
	TypeSerializerFactory<T> serializerFactory = this.taskContext.getInputSerializer(0);
	this.serializer = serializerFactory.getSerializer();
	this.input = this.taskContext.getInput(0);

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

	if (LOG.isDebugEnabled()) {
		LOG.debug("AllReduceDriver object reuse: " + (this.objectReuseEnabled ? "ENABLED" : "DISABLED") + ".");
	}
}
 
Example 2
Source File: SynchronousChainedCombineDriver.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void openTask() throws Exception {
	// open the stub first
	final Configuration stubConfig = this.config.getStubParameters();
	BatchTask.openUserCode(this.combiner, stubConfig);

	// ----------------- Set up the sorter -------------------------

	// instantiate the serializer / comparator
	final TypeSerializerFactory<IN> serializerFactory = this.config.getInputSerializer(0, this.userCodeClassLoader);
	final TypeComparatorFactory<IN> sortingComparatorFactory = this.config.getDriverComparator(0, this.userCodeClassLoader);
	final TypeComparatorFactory<IN> groupingComparatorFactory = this.config.getDriverComparator(1, this.userCodeClassLoader);
	
	this.serializer = serializerFactory.getSerializer();

	TypeComparator<IN> sortingComparator = sortingComparatorFactory.createComparator();
	this.groupingComparator = groupingComparatorFactory.createComparator();
	
	MemoryManager memManager = this.parent.getEnvironment().getMemoryManager();
	final int numMemoryPages = memManager.computeNumberOfPages(this.config.getRelativeMemoryDriver());
	this.memory = memManager.allocatePages(this.parent, numMemoryPages);

	// instantiate a fix-length in-place sorter, if possible, otherwise the out-of-place sorter
	if (sortingComparator.supportsSerializationWithKeyNormalization() &&
		this.serializer.getLength() > 0 && this.serializer.getLength() <= THRESHOLD_FOR_IN_PLACE_SORTING)
	{
		this.sorter = new FixedLengthRecordSorter<IN>(this.serializer, sortingComparator.duplicate(), this.memory);
	} else {
		this.sorter = new NormalizedKeySorter<IN>(this.serializer, sortingComparator.duplicate(), this.memory);
	}

	if (LOG.isDebugEnabled()) {
		LOG.debug("SynchronousChainedCombineDriver object reuse: " + (this.objectReuseEnabled ? "ENABLED" : "DISABLED") + ".");
	}
}
 
Example 3
Source File: ChainedAllReduceDriver.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void setup(AbstractInvokable parent) {
	final ReduceFunction<IT> red = BatchTask.instantiateUserCode(this.config, userCodeClassLoader, ReduceFunction.class);
	this.reducer = red;
	FunctionUtils.setFunctionRuntimeContext(red, getUdfRuntimeContext());

	TypeSerializerFactory<IT> serializerFactory = this.config.getInputSerializer(0, userCodeClassLoader);
	this.serializer = serializerFactory.getSerializer();

	if (LOG.isDebugEnabled()) {
		LOG.debug("ChainedAllReduceDriver object reuse: " + (this.objectReuseEnabled ? "ENABLED" : "DISABLED") + ".");
	}
}
 
Example 4
Source File: AbstractIterativeTask.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * @return output serializer of this task
 */
private TypeSerializer<OT> getOutputSerializer() {
	TypeSerializerFactory<OT> serializerFactory;

	if ((serializerFactory = getLastTasksConfig().getOutputSerializer(getUserCodeClassLoader())) ==
			null) {
		throw new RuntimeException("Missing output serializer for workset update.");
	}

	return serializerFactory.getSerializer();
}
 
Example 5
Source File: DefaultInMemorySorterFactory.java    From flink with Apache License 2.0 5 votes vote down vote up
DefaultInMemorySorterFactory(
		@Nonnull TypeSerializerFactory<T> typeSerializerFactory,
		@Nonnull TypeComparator<T> typeComparator,
		int thresholdForInPlaceSorting) {
	this.typeSerializerFactory = typeSerializerFactory;
	this.typeComparator = typeComparator;

	TypeSerializer<T> typeSerializer = typeSerializerFactory.getSerializer();

	this.useFixedLengthRecordSorter = typeComparator.supportsSerializationWithKeyNormalization() &&
		typeSerializer.getLength() > 0 && typeSerializer.getLength() <= thresholdForInPlaceSorting;
}
 
Example 6
Source File: UnilateralSortMerger.java    From flink with Apache License 2.0 5 votes vote down vote up
protected ThreadBase<E> getSpillingThread(ExceptionHandler<IOException> exceptionHandler, CircularQueues<E> queues,
		AbstractInvokable parentTask, MemoryManager memoryManager, IOManager ioManager, 
		TypeSerializerFactory<E> serializerFactory, TypeComparator<E> comparator,
		List<MemorySegment> sortReadMemory, List<MemorySegment> writeMemory, int maxFileHandles)
{
	return new SpillingThread(exceptionHandler, queues, parentTask,
		memoryManager, ioManager, serializerFactory.getSerializer(), comparator, sortReadMemory, writeMemory, maxFileHandles);
}
 
Example 7
Source File: AbstractIterativeTask.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * @return output serializer of this task
 */
private TypeSerializer<OT> getOutputSerializer() {
	TypeSerializerFactory<OT> serializerFactory;

	if ((serializerFactory = getLastTasksConfig().getOutputSerializer(getUserCodeClassLoader())) ==
			null) {
		throw new RuntimeException("Missing output serializer for workset update.");
	}

	return serializerFactory.getSerializer();
}
 
Example 8
Source File: IterationHeadTask.java    From flink with Apache License 2.0 5 votes vote down vote up
private <BT> JoinHashMap<BT> initJoinHashMap() {
	TypeSerializerFactory<BT> solutionTypeSerializerFactory = config.getSolutionSetSerializer
			(getUserCodeClassLoader());
	TypeComparatorFactory<BT> solutionTypeComparatorFactory = config.getSolutionSetComparator
			(getUserCodeClassLoader());

	TypeSerializer<BT> solutionTypeSerializer = solutionTypeSerializerFactory.getSerializer();
	TypeComparator<BT> solutionTypeComparator = solutionTypeComparatorFactory.createComparator();

	return new JoinHashMap<BT>(solutionTypeSerializer, solutionTypeComparator);
}
 
Example 9
Source File: GroupReduceCombineDriver.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare() throws Exception {
	final DriverStrategy driverStrategy = this.taskContext.getTaskConfig().getDriverStrategy();
	if (driverStrategy != DriverStrategy.SORTED_GROUP_COMBINE){
		throw new Exception("Invalid strategy " + driverStrategy + " for group reduce combiner.");
	}
	
	

	final TypeSerializerFactory<IN> serializerFactory = this.taskContext.getInputSerializer(0);
	this.serializer = serializerFactory.getSerializer();

	final TypeComparator<IN> sortingComparator = this.taskContext.getDriverComparator(0);
	
	this.groupingComparator = this.taskContext.getDriverComparator(1);
	this.combiner = this.taskContext.getStub();
	this.output = this.taskContext.getOutputCollector();

	MemoryManager memManager = this.taskContext.getMemoryManager();
	final int numMemoryPages = memManager.computeNumberOfPages(this.taskContext.getTaskConfig().getRelativeMemoryDriver());
	this.memory = memManager.allocatePages(this.taskContext.getContainingTask(), numMemoryPages);

	// instantiate a fix-length in-place sorter, if possible, otherwise the out-of-place sorter
	if (sortingComparator.supportsSerializationWithKeyNormalization() &&
			this.serializer.getLength() > 0 && this.serializer.getLength() <= THRESHOLD_FOR_IN_PLACE_SORTING)
	{
		this.sorter = new FixedLengthRecordSorter<IN>(this.serializer, sortingComparator.duplicate(), memory);
	} else {
		this.sorter = new NormalizedKeySorter<IN>(this.serializer, sortingComparator.duplicate(), memory);
	}

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

	if (LOG.isDebugEnabled()) {
		LOG.debug("GroupReduceCombineDriver object reuse: {}.", (this.objectReuseEnabled ? "ENABLED" : "DISABLED"));
	}
}
 
Example 10
Source File: GroupCombineChainedDriver.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void openTask() throws Exception {
	// open the stub first
	final Configuration stubConfig = this.config.getStubParameters();
	BatchTask.openUserCode(this.reducer, stubConfig);

	// ----------------- Set up the sorter -------------------------

	// instantiate the serializer / comparator
	final TypeSerializerFactory<IN> serializerFactory = this.config.getInputSerializer(0, this.userCodeClassLoader);
	final TypeComparatorFactory<IN> sortingComparatorFactory = this.config.getDriverComparator(0, this.userCodeClassLoader);
	final TypeComparatorFactory<IN> groupingComparatorFactory = this.config.getDriverComparator(1, this.userCodeClassLoader);
	this.serializer = serializerFactory.getSerializer();
	
	TypeComparator<IN> sortingComparator = sortingComparatorFactory.createComparator();
	this.groupingComparator = groupingComparatorFactory.createComparator();

	MemoryManager memManager = this.parent.getEnvironment().getMemoryManager();
	final int numMemoryPages = memManager.computeNumberOfPages(this.config.getRelativeMemoryDriver());
	this.memory = memManager.allocatePages(this.parent, numMemoryPages);

	// instantiate a fix-length in-place sorter, if possible, otherwise the out-of-place sorter
	if (sortingComparator.supportsSerializationWithKeyNormalization() &&
		this.serializer.getLength() > 0 && this.serializer.getLength() <= THRESHOLD_FOR_IN_PLACE_SORTING)
	{
		this.sorter = new FixedLengthRecordSorter<IN>(this.serializer, sortingComparator.duplicate(), memory);
	} else {
		this.sorter = new NormalizedKeySorter<IN>(this.serializer, sortingComparator.duplicate(), memory);
	}

	if (LOG.isDebugEnabled()) {
		LOG.debug("SynchronousChainedCombineDriver object reuse: " + (this.objectReuseEnabled ? "ENABLED" : "DISABLED") + ".");
	}
}
 
Example 11
Source File: ChainedAllReduceDriver.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void setup(AbstractInvokable parent) {
	@SuppressWarnings("unchecked")
	final ReduceFunction<IT> red = BatchTask.instantiateUserCode(this.config, userCodeClassLoader, ReduceFunction.class);
	this.reducer = red;
	FunctionUtils.setFunctionRuntimeContext(red, getUdfRuntimeContext());

	TypeSerializerFactory<IT> serializerFactory = this.config.getInputSerializer(0, userCodeClassLoader);
	this.serializer = serializerFactory.getSerializer();

	if (LOG.isDebugEnabled()) {
		LOG.debug("ChainedAllReduceDriver object reuse: " + (this.objectReuseEnabled ? "ENABLED" : "DISABLED") + ".");
	}
}
 
Example 12
Source File: IterationHeadTask.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private <BT> JoinHashMap<BT> initJoinHashMap() {
	TypeSerializerFactory<BT> solutionTypeSerializerFactory = config.getSolutionSetSerializer
			(getUserCodeClassLoader());
	TypeComparatorFactory<BT> solutionTypeComparatorFactory = config.getSolutionSetComparator
			(getUserCodeClassLoader());

	TypeSerializer<BT> solutionTypeSerializer = solutionTypeSerializerFactory.getSerializer();
	TypeComparator<BT> solutionTypeComparator = solutionTypeComparatorFactory.createComparator();

	return new JoinHashMap<BT>(solutionTypeSerializer, solutionTypeComparator);
}
 
Example 13
Source File: GroupReduceCombineDriver.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare() throws Exception {
	final DriverStrategy driverStrategy = this.taskContext.getTaskConfig().getDriverStrategy();
	if (driverStrategy != DriverStrategy.SORTED_GROUP_COMBINE){
		throw new Exception("Invalid strategy " + driverStrategy + " for group reduce combiner.");
	}
	
	

	final TypeSerializerFactory<IN> serializerFactory = this.taskContext.getInputSerializer(0);
	this.serializer = serializerFactory.getSerializer();

	final TypeComparator<IN> sortingComparator = this.taskContext.getDriverComparator(0);
	
	this.groupingComparator = this.taskContext.getDriverComparator(1);
	this.combiner = this.taskContext.getStub();
	this.output = this.taskContext.getOutputCollector();

	MemoryManager memManager = this.taskContext.getMemoryManager();
	final int numMemoryPages = memManager.computeNumberOfPages(this.taskContext.getTaskConfig().getRelativeMemoryDriver());
	this.memory = memManager.allocatePages(this.taskContext.getContainingTask(), numMemoryPages);

	// instantiate a fix-length in-place sorter, if possible, otherwise the out-of-place sorter
	if (sortingComparator.supportsSerializationWithKeyNormalization() &&
			this.serializer.getLength() > 0 && this.serializer.getLength() <= THRESHOLD_FOR_IN_PLACE_SORTING)
	{
		this.sorter = new FixedLengthRecordSorter<IN>(this.serializer, sortingComparator.duplicate(), memory);
	} else {
		this.sorter = new NormalizedKeySorter<IN>(this.serializer, sortingComparator.duplicate(), memory);
	}

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

	if (LOG.isDebugEnabled()) {
		LOG.debug("GroupReduceCombineDriver object reuse: {}.", (this.objectReuseEnabled ? "ENABLED" : "DISABLED"));
	}
}
 
Example 14
Source File: UnilateralSortMerger.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
protected ThreadBase<E> getSpillingThread(ExceptionHandler<IOException> exceptionHandler, CircularQueues<E> queues,
		AbstractInvokable parentTask, MemoryManager memoryManager, IOManager ioManager, 
		TypeSerializerFactory<E> serializerFactory, TypeComparator<E> comparator,
		List<MemorySegment> sortReadMemory, List<MemorySegment> writeMemory, int maxFileHandles)
{
	return new SpillingThread(exceptionHandler, queues, parentTask,
		memoryManager, ioManager, serializerFactory.getSerializer(), comparator, sortReadMemory, writeMemory, maxFileHandles);
}
 
Example 15
Source File: SynchronousChainedCombineDriver.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void openTask() throws Exception {
	// open the stub first
	final Configuration stubConfig = this.config.getStubParameters();
	BatchTask.openUserCode(this.combiner, stubConfig);

	// ----------------- Set up the sorter -------------------------

	// instantiate the serializer / comparator
	final TypeSerializerFactory<IN> serializerFactory = this.config.getInputSerializer(0, this.userCodeClassLoader);
	final TypeComparatorFactory<IN> sortingComparatorFactory = this.config.getDriverComparator(0, this.userCodeClassLoader);
	final TypeComparatorFactory<IN> groupingComparatorFactory = this.config.getDriverComparator(1, this.userCodeClassLoader);
	
	this.serializer = serializerFactory.getSerializer();

	TypeComparator<IN> sortingComparator = sortingComparatorFactory.createComparator();
	this.groupingComparator = groupingComparatorFactory.createComparator();
	
	MemoryManager memManager = this.parent.getEnvironment().getMemoryManager();
	final int numMemoryPages = memManager.computeNumberOfPages(this.config.getRelativeMemoryDriver());
	this.memory = memManager.allocatePages(this.parent, numMemoryPages);

	// instantiate a fix-length in-place sorter, if possible, otherwise the out-of-place sorter
	if (sortingComparator.supportsSerializationWithKeyNormalization() &&
		this.serializer.getLength() > 0 && this.serializer.getLength() <= THRESHOLD_FOR_IN_PLACE_SORTING)
	{
		this.sorter = new FixedLengthRecordSorter<IN>(this.serializer, sortingComparator.duplicate(), this.memory);
	} else {
		this.sorter = new NormalizedKeySorter<IN>(this.serializer, sortingComparator.duplicate(), this.memory);
	}

	if (LOG.isDebugEnabled()) {
		LOG.debug("SynchronousChainedCombineDriver object reuse: " + (this.objectReuseEnabled ? "ENABLED" : "DISABLED") + ".");
	}
}
 
Example 16
Source File: DefaultInMemorySorterFactory.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
DefaultInMemorySorterFactory(
		@Nonnull TypeSerializerFactory<T> typeSerializerFactory,
		@Nonnull TypeComparator<T> typeComparator,
		int thresholdForInPlaceSorting) {
	this.typeSerializerFactory = typeSerializerFactory;
	this.typeComparator = typeComparator;

	TypeSerializer<T> typeSerializer = typeSerializerFactory.getSerializer();

	this.useFixedLengthRecordSorter = typeComparator.supportsSerializationWithKeyNormalization() &&
		typeSerializer.getLength() > 0 && typeSerializer.getLength() <= thresholdForInPlaceSorting;
}
 
Example 17
Source File: GroupReduceCombineDriver.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare() throws Exception {
	final DriverStrategy driverStrategy = this.taskContext.getTaskConfig().getDriverStrategy();
	if (driverStrategy != DriverStrategy.SORTED_GROUP_COMBINE){
		throw new Exception("Invalid strategy " + driverStrategy + " for group reduce combiner.");
	}
	
	

	final TypeSerializerFactory<IN> serializerFactory = this.taskContext.getInputSerializer(0);
	this.serializer = serializerFactory.getSerializer();

	final TypeComparator<IN> sortingComparator = this.taskContext.getDriverComparator(0);
	
	this.groupingComparator = this.taskContext.getDriverComparator(1);
	this.combiner = this.taskContext.getStub();
	this.output = this.taskContext.getOutputCollector();

	MemoryManager memManager = this.taskContext.getMemoryManager();
	final int numMemoryPages = memManager.computeNumberOfPages(this.taskContext.getTaskConfig().getRelativeMemoryDriver());
	this.memory = memManager.allocatePages(this.taskContext.getContainingTask(), numMemoryPages);

	// instantiate a fix-length in-place sorter, if possible, otherwise the out-of-place sorter
	if (sortingComparator.supportsSerializationWithKeyNormalization() &&
			this.serializer.getLength() > 0 && this.serializer.getLength() <= THRESHOLD_FOR_IN_PLACE_SORTING)
	{
		this.sorter = new FixedLengthRecordSorter<IN>(this.serializer, sortingComparator.duplicate(), memory);
	} else {
		this.sorter = new NormalizedKeySorter<IN>(this.serializer, sortingComparator.duplicate(), memory);
	}

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

	if (LOG.isDebugEnabled()) {
		LOG.debug("GroupReduceCombineDriver object reuse: {}.", (this.objectReuseEnabled ? "ENABLED" : "DISABLED"));
	}
}
 
Example 18
Source File: BatchTask.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
protected MutableObjectIterator<?> createInputIterator(MutableReader<?> inputReader, TypeSerializerFactory<?> serializerFactory) {
	@SuppressWarnings("unchecked")
	MutableReader<DeserializationDelegate<?>> reader = (MutableReader<DeserializationDelegate<?>>) inputReader;
	@SuppressWarnings({ "unchecked", "rawtypes" })
	final MutableObjectIterator<?> iter = new ReaderIterator(reader, serializerFactory.getSerializer());
	return iter;
}
 
Example 19
Source File: AbstractIterativeTask.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * @return output serializer of this task
 */
private TypeSerializer<OT> getOutputSerializer() {
	TypeSerializerFactory<OT> serializerFactory;

	if ((serializerFactory = getLastTasksConfig().getOutputSerializer(getUserCodeClassLoader())) ==
			null) {
		throw new RuntimeException("Missing output serializer for workset update.");
	}

	return serializerFactory.getSerializer();
}
 
Example 20
Source File: ReduceCombineDriver.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void prepare() throws Exception {
	final Counter numRecordsOut = taskContext.getMetricGroup().getIOMetricGroup().getNumRecordsOutCounter();

	strategy = taskContext.getTaskConfig().getDriverStrategy();

	// instantiate the serializer / comparator
	final TypeSerializerFactory<T> serializerFactory = taskContext.getInputSerializer(0);
	comparator = taskContext.getDriverComparator(0);
	serializer = serializerFactory.getSerializer();
	reducer = taskContext.getStub();
	output = new CountingCollector<>(this.taskContext.getOutputCollector(), numRecordsOut);

	MemoryManager memManager = taskContext.getMemoryManager();
	final int numMemoryPages = memManager.computeNumberOfPages(
		taskContext.getTaskConfig().getRelativeMemoryDriver());
	memory = memManager.allocatePages(taskContext.getContainingTask(), numMemoryPages);

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

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

	switch (strategy) {
		case SORTED_PARTIAL_REDUCE:
			// instantiate a fix-length in-place sorter, if possible, otherwise the out-of-place sorter
			if (comparator.supportsSerializationWithKeyNormalization() &&
				serializer.getLength() > 0 && serializer.getLength() <= THRESHOLD_FOR_IN_PLACE_SORTING) {
				sorter = new FixedLengthRecordSorter<T>(serializer, comparator.duplicate(), memory);
			} else {
				sorter = new NormalizedKeySorter<T>(serializer, comparator.duplicate(), memory);
			}
			break;
		case HASHED_PARTIAL_REDUCE:
			table = new InPlaceMutableHashTable<T>(serializer, comparator, memory);
			reduceFacade = table.new ReduceFacade(reducer, output, objectReuseEnabled);
			break;
		default:
			throw new Exception("Invalid strategy " + taskContext.getTaskConfig().getDriverStrategy() + " for reduce combiner.");
	}
}