    001/*
    002 * Copyright (c) 2007-2016 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 LeftJoin will return an {@link Iterator} that will iterate over a given {@link Joiner} and return tuples that represent
    031 * a left inner, right outer join of the CoGrouper internal grouped tuple collections.
    032 * <p/>
    033 * Note only the farthest right tuple stream will be used as the outer join. All preceding joins to the left 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 LeftJoin extends BaseJoiner
    044  {
    045  public LeftJoin()
    046    {
    047    }
    048
    049  @ConstructorProperties({"fieldDeclaration"})
    050  public LeftJoin( 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 == closure.size() - 1 && super.isOuter( i );
    076      }
    077    }
    078  }