001/* 002 * Copyright (c) 2007-2015 Concurrent, Inc. All Rights Reserved. 003 * 004 * Project and contact information: http://www.cascading.org/ 005 * 006 * This file is part of the Cascading project. 007 * 008 * Licensed under the Apache License, Version 2.0 (the "License"); 009 * you may not use this file except in compliance with the License. 010 * You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, software 015 * distributed under the License is distributed on an "AS IS" BASIS, 016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017 * See the License for the specific language governing permissions and 018 * limitations under the License. 019 */ 020 021package cascading.pipe.joiner; 022 023import java.beans.ConstructorProperties; 024import java.util.Iterator; 025 026import cascading.tuple.Fields; 027import cascading.tuple.Tuple; 028 029/** 030 * Class RightJoin will return an {@link Iterator} that will iterate over a given {@link Joiner} and return tuples that represent 031 * a left outer, right inner join of the CoGrouper internal grouped tuple collections. 032 * <p/> 033 * Note only the farthest left tuple stream will be used as the outer join. All following joins to the right will 034 * be inner joins. See {@link MixedJoin} for more flexibility. 035 * <p/> 036 * Joins perform based on the equality of the join keys. In the case of null values, Java treats two 037 * null values as equivalent. SQL does not treat null values as equal. To produce SQL like results in a given 038 * join, a new {@link java.util.Comparator} will need to be used on the joined values to prevent null from 039 * equaling null. As a convenience, see the {@link cascading.util.NullNotEquivalentComparator} class. 040 * 041 * @see MixedJoin 042 */ 043public class RightJoin extends BaseJoiner 044 { 045 public RightJoin() 046 { 047 } 048 049 @ConstructorProperties({"fieldDeclaration"}) 050 public RightJoin( Fields fieldDeclaration ) 051 { 052 super( fieldDeclaration ); 053 } 054 055 public Iterator<Tuple> getIterator( JoinerClosure closure ) 056 { 057 return new JoinIterator( closure ); 058 } 059 060 public int numJoins() 061 { 062 return -1; 063 } 064 065 public static class JoinIterator extends OuterJoin.JoinIterator 066 { 067 public JoinIterator( JoinerClosure closure ) 068 { 069 super( closure ); 070 } 071 072 @Override 073 protected boolean isOuter( int i ) 074 { 075 return i == 0 && super.isOuter( i ); 076 } 077 } 078 }