All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.flink.runtime.operators.LeftOuterJoinDriver Maven / Gradle / Ivy

There is a newer version: 1.13.6
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.flink.runtime.operators;

import org.apache.flink.api.common.operators.base.OuterJoinOperatorBase.OuterJoinType;
import org.apache.flink.api.common.typeutils.TypeComparator;
import org.apache.flink.api.common.typeutils.TypePairComparatorFactory;
import org.apache.flink.api.common.typeutils.TypeSerializer;
import org.apache.flink.runtime.io.disk.iomanager.IOManager;
import org.apache.flink.runtime.memory.MemoryManager;
import org.apache.flink.runtime.operators.hash.NonReusingBuildFirstHashJoinIterator;
import org.apache.flink.runtime.operators.hash.NonReusingBuildSecondHashJoinIterator;
import org.apache.flink.runtime.operators.hash.ReusingBuildFirstHashJoinIterator;
import org.apache.flink.runtime.operators.hash.ReusingBuildSecondHashJoinIterator;
import org.apache.flink.runtime.operators.sort.NonReusingMergeOuterJoinIterator;
import org.apache.flink.runtime.operators.sort.ReusingMergeOuterJoinIterator;
import org.apache.flink.runtime.operators.util.JoinTaskIterator;
import org.apache.flink.util.MutableObjectIterator;

/**
 * The left outer join driver implements the logic of an outer join operator at runtime. It instantiates a sort-merge based strategy to find
 * joining pairs of records or joins records from the left side with null if no match is found.
 */
public class LeftOuterJoinDriver extends AbstractOuterJoinDriver {
	
	@Override
	protected JoinTaskIterator getReusingOuterJoinIterator(
			DriverStrategy driverStrategy,
			MutableObjectIterator in1,
			MutableObjectIterator in2,
			TypeSerializer serializer1,
			TypeComparator comparator1,
			TypeSerializer serializer2,
			TypeComparator comparator2,
			TypePairComparatorFactory 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());
		}
	}
	
	@Override
	protected JoinTaskIterator getNonReusingOuterJoinIterator(
			DriverStrategy driverStrategy,
			MutableObjectIterator in1,
			MutableObjectIterator in2,
			TypeSerializer serializer1,
			TypeComparator comparator1,
			TypeSerializer serializer2,
			TypeComparator comparator2,
			TypePairComparatorFactory 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());
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy