Search in sources :

Example 1 with TypeComparator

use of org.apache.flink.api.common.typeutils.TypeComparator in project flink by apache.

the class BatchTask method initInputsSerializersAndComparators.

/**
 * Creates all the serializers and comparators.
 */
protected void initInputsSerializersAndComparators(int numInputs, int numComparators) {
    this.inputSerializers = new TypeSerializerFactory<?>[numInputs];
    this.inputComparators = numComparators > 0 ? new TypeComparator<?>[numComparators] : null;
    this.inputIterators = new MutableObjectIterator<?>[numInputs];
    ClassLoader userCodeClassLoader = getUserCodeClassLoader();
    for (int i = 0; i < numInputs; i++) {
        final TypeSerializerFactory<?> serializerFactory = this.config.getInputSerializer(i, userCodeClassLoader);
        this.inputSerializers[i] = serializerFactory;
        this.inputIterators[i] = createInputIterator(this.inputReaders[i], this.inputSerializers[i]);
    }
    // ---------------- create the driver's comparators ---------------------
    for (int i = 0; i < numComparators; i++) {
        if (this.inputComparators != null) {
            final TypeComparatorFactory<?> comparatorFactory = this.config.getDriverComparator(i, userCodeClassLoader);
            this.inputComparators[i] = comparatorFactory.createComparator();
        }
    }
}
Also used : TypeComparator(org.apache.flink.api.common.typeutils.TypeComparator) UserCodeClassLoader(org.apache.flink.util.UserCodeClassLoader)

Example 2 with TypeComparator

use of org.apache.flink.api.common.typeutils.TypeComparator in project flink by apache.

the class NonReusingSortMergeInnerJoinIteratorITCase method beforeTest.

@SuppressWarnings("unchecked")
@Before
public void beforeTest() {
    serializer1 = new TupleSerializer<Tuple2<Integer, String>>((Class<Tuple2<Integer, String>>) (Class<?>) Tuple2.class, new TypeSerializer<?>[] { IntSerializer.INSTANCE, StringSerializer.INSTANCE });
    serializer2 = new TupleSerializer<Tuple2<Integer, String>>((Class<Tuple2<Integer, String>>) (Class<?>) Tuple2.class, new TypeSerializer<?>[] { IntSerializer.INSTANCE, StringSerializer.INSTANCE });
    comparator1 = new TupleComparator<Tuple2<Integer, String>>(new int[] { 0 }, new TypeComparator<?>[] { new IntComparator(true) }, new TypeSerializer<?>[] { IntSerializer.INSTANCE });
    comparator2 = new TupleComparator<Tuple2<Integer, String>>(new int[] { 0 }, new TypeComparator<?>[] { new IntComparator(true) }, new TypeSerializer<?>[] { IntSerializer.INSTANCE });
    pairComparator = new GenericPairComparator<Tuple2<Integer, String>, Tuple2<Integer, String>>(comparator1, comparator2);
    this.memoryManager = MemoryManagerBuilder.newBuilder().setMemorySize(MEMORY_SIZE).build();
    this.ioManager = new IOManagerAsync();
}
Also used : TypeComparator(org.apache.flink.api.common.typeutils.TypeComparator) IOManagerAsync(org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync) Tuple2(org.apache.flink.api.java.tuple.Tuple2) TypeSerializer(org.apache.flink.api.common.typeutils.TypeSerializer) IntComparator(org.apache.flink.api.common.typeutils.base.IntComparator) Before(org.junit.Before)

Example 3 with TypeComparator

use of org.apache.flink.api.common.typeutils.TypeComparator in project flink by apache.

the class ReusingSortMergeInnerJoinIteratorITCase method beforeTest.

@SuppressWarnings("unchecked")
@Before
public void beforeTest() {
    serializer1 = new TupleSerializer<Tuple2<Integer, String>>((Class<Tuple2<Integer, String>>) (Class<?>) Tuple2.class, new TypeSerializer<?>[] { IntSerializer.INSTANCE, StringSerializer.INSTANCE });
    serializer2 = new TupleSerializer<Tuple2<Integer, String>>((Class<Tuple2<Integer, String>>) (Class<?>) Tuple2.class, new TypeSerializer<?>[] { IntSerializer.INSTANCE, StringSerializer.INSTANCE });
    comparator1 = new TupleComparator<Tuple2<Integer, String>>(new int[] { 0 }, new TypeComparator<?>[] { new IntComparator(true) }, new TypeSerializer<?>[] { IntSerializer.INSTANCE });
    comparator2 = new TupleComparator<Tuple2<Integer, String>>(new int[] { 0 }, new TypeComparator<?>[] { new IntComparator(true) }, new TypeSerializer<?>[] { IntSerializer.INSTANCE });
    pairComparator = new GenericPairComparator<Tuple2<Integer, String>, Tuple2<Integer, String>>(comparator1, comparator2);
    this.memoryManager = MemoryManagerBuilder.newBuilder().setMemorySize(MEMORY_SIZE).build();
    this.ioManager = new IOManagerAsync();
}
Also used : TypeComparator(org.apache.flink.api.common.typeutils.TypeComparator) IOManagerAsync(org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync) Tuple2(org.apache.flink.api.java.tuple.Tuple2) TypeSerializer(org.apache.flink.api.common.typeutils.TypeSerializer) IntComparator(org.apache.flink.api.common.typeutils.base.IntComparator) Before(org.junit.Before)

Example 4 with TypeComparator

use of org.apache.flink.api.common.typeutils.TypeComparator in project flink by apache.

the class MultiInputSortingDataInput method wrapInputs.

public static <K> SelectableSortingInputs wrapInputs(TaskInvokable containingTask, StreamTaskInput<Object>[] sortingInputs, KeySelector<Object, K>[] keySelectors, TypeSerializer<Object>[] inputSerializers, TypeSerializer<K> keySerializer, StreamTaskInput<Object>[] passThroughInputs, MemoryManager memoryManager, IOManager ioManager, boolean objectReuse, double managedMemoryFraction, Configuration jobConfiguration, ExecutionConfig executionConfig) {
    int keyLength = keySerializer.getLength();
    final TypeComparator<Tuple2<byte[], StreamRecord<Object>>> comparator;
    DataOutputSerializer dataOutputSerializer;
    if (keyLength > 0) {
        dataOutputSerializer = new DataOutputSerializer(keyLength);
        comparator = new FixedLengthByteKeyComparator<>(keyLength);
    } else {
        dataOutputSerializer = new DataOutputSerializer(64);
        comparator = new VariableLengthByteKeyComparator<>();
    }
    List<Integer> passThroughInputIndices = Arrays.stream(passThroughInputs).map(StreamTaskInput::getInputIndex).collect(Collectors.toList());
    int numberOfInputs = sortingInputs.length + passThroughInputs.length;
    CommonContext commonContext = new CommonContext(sortingInputs);
    InputSelector inputSelector = new InputSelector(commonContext, numberOfInputs, passThroughInputIndices);
    StreamTaskInput<?>[] wrappedSortingInputs = IntStream.range(0, sortingInputs.length).mapToObj(idx -> {
        try {
            KeyAndValueSerializer<Object> keyAndValueSerializer = new KeyAndValueSerializer<>(inputSerializers[idx], keyLength);
            return new MultiInputSortingDataInput<>(commonContext, sortingInputs[idx], sortingInputs[idx].getInputIndex(), ExternalSorter.newBuilder(memoryManager, containingTask, keyAndValueSerializer, comparator, executionConfig).memoryFraction(managedMemoryFraction / numberOfInputs).enableSpilling(ioManager, jobConfiguration.get(AlgorithmOptions.SORT_SPILLING_THRESHOLD)).maxNumFileHandles(jobConfiguration.get(AlgorithmOptions.SPILLING_MAX_FAN) / numberOfInputs).objectReuse(objectReuse).largeRecords(true).build(), keySelectors[idx], keySerializer, dataOutputSerializer);
        } catch (MemoryAllocationException e) {
            throw new RuntimeException();
        }
    }).toArray(StreamTaskInput[]::new);
    StreamTaskInput<?>[] wrappedPassThroughInputs = Arrays.stream(passThroughInputs).map(input -> new ObservableStreamTaskInput<>(input, inputSelector)).toArray(StreamTaskInput[]::new);
    return new SelectableSortingInputs(wrappedSortingInputs, wrappedPassThroughInputs, inputSelector);
}
Also used : IntStream(java.util.stream.IntStream) MemoryAllocationException(org.apache.flink.runtime.memory.MemoryAllocationException) StreamTaskInput(org.apache.flink.streaming.runtime.io.StreamTaskInput) Arrays(java.util.Arrays) InputSelectable(org.apache.flink.streaming.api.operators.InputSelectable) TaskInvokable(org.apache.flink.runtime.jobgraph.tasks.TaskInvokable) MemoryManager(org.apache.flink.runtime.memory.MemoryManager) Tuple2(org.apache.flink.api.java.tuple.Tuple2) PriorityQueue(java.util.PriorityQueue) AvailabilityProvider(org.apache.flink.runtime.io.AvailabilityProvider) IOManager(org.apache.flink.runtime.io.disk.iomanager.IOManager) Watermark(org.apache.flink.streaming.api.watermark.Watermark) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CompletableFuture(java.util.concurrent.CompletableFuture) PushingAsyncDataInput(org.apache.flink.streaming.runtime.io.PushingAsyncDataInput) StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) DataInputStatus(org.apache.flink.streaming.runtime.io.DataInputStatus) MutableObjectIterator(org.apache.flink.util.MutableObjectIterator) DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer) ChannelStateWriter(org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter) LinkedList(java.util.LinkedList) Nonnull(javax.annotation.Nonnull) StreamInputProcessor(org.apache.flink.streaming.runtime.io.StreamInputProcessor) WatermarkStatus(org.apache.flink.streaming.runtime.watermarkstatus.WatermarkStatus) TypeSerializer(org.apache.flink.api.common.typeutils.TypeSerializer) KeySelector(org.apache.flink.api.java.functions.KeySelector) BoundedMultiInput(org.apache.flink.streaming.api.operators.BoundedMultiInput) AlgorithmOptions(org.apache.flink.configuration.AlgorithmOptions) Configuration(org.apache.flink.configuration.Configuration) ExternalSorter(org.apache.flink.runtime.operators.sort.ExternalSorter) IOException(java.io.IOException) TypeComparator(org.apache.flink.api.common.typeutils.TypeComparator) Collectors(java.util.stream.Collectors) List(java.util.List) PushSorter(org.apache.flink.runtime.operators.sort.PushSorter) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) Queue(java.util.Queue) InputSelection(org.apache.flink.streaming.api.operators.InputSelection) LatencyMarker(org.apache.flink.streaming.runtime.streamrecord.LatencyMarker) DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer) MemoryAllocationException(org.apache.flink.runtime.memory.MemoryAllocationException) StreamTaskInput(org.apache.flink.streaming.runtime.io.StreamTaskInput) Tuple2(org.apache.flink.api.java.tuple.Tuple2)

Aggregations

TypeComparator (org.apache.flink.api.common.typeutils.TypeComparator)4 TypeSerializer (org.apache.flink.api.common.typeutils.TypeSerializer)3 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)3 IntComparator (org.apache.flink.api.common.typeutils.base.IntComparator)2 IOManagerAsync (org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync)2 Before (org.junit.Before)2 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 PriorityQueue (java.util.PriorityQueue)1 Queue (java.util.Queue)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Nonnull (javax.annotation.Nonnull)1 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)1 KeySelector (org.apache.flink.api.java.functions.KeySelector)1 AlgorithmOptions (org.apache.flink.configuration.AlgorithmOptions)1 Configuration (org.apache.flink.configuration.Configuration)1