001/*
002 * Copyright (c) 2007-2022 The Cascading Authors. All Rights Reserved.
003 *
004 * Project and contact information: https://cascading.wensel.net/
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.flow.hadoop.stream.graph;
022
023import cascading.flow.FlowElement;
024import cascading.flow.FlowNode;
025import cascading.flow.hadoop.HadoopFlowProcess;
026import cascading.flow.hadoop.stream.element.HadoopCoGroupGate;
027import cascading.flow.hadoop.stream.element.HadoopGroupByGate;
028import cascading.flow.hadoop.stream.element.HadoopSinkStage;
029import cascading.flow.stream.duct.Duct;
030import cascading.flow.stream.duct.Gate;
031import cascading.flow.stream.element.SinkStage;
032import cascading.flow.stream.graph.IORole;
033import cascading.flow.stream.graph.NodeStreamGraph;
034import cascading.pipe.CoGroup;
035import cascading.pipe.Group;
036import cascading.pipe.GroupBy;
037import cascading.pipe.HashJoin;
038import cascading.tap.Tap;
039import cascading.util.Util;
040
041/**
042 *
043 */
044public class HadoopReduceStreamGraph extends NodeStreamGraph
045  {
046  public HadoopReduceStreamGraph( HadoopFlowProcess flowProcess, FlowNode node, FlowElement sourceElement )
047    {
048    super( flowProcess, node, sourceElement );
049
050    buildGraph();
051
052    setTraps();
053    setScopes();
054
055    printGraph( node.getID(), "reduce", flowProcess.getCurrentSliceNum() );
056
057    bind();
058
059    printBoundGraph( node.getID(), "reduce", flowProcess.getCurrentSliceNum() );
060    }
061
062  protected void buildGraph()
063    {
064    Group group = (Group) Util.getFirst( node.getSourceElements() );
065
066    Duct rhsDuct;
067
068    if( group.isGroupBy() )
069      rhsDuct = new HadoopGroupByGate( flowProcess, (GroupBy) group, IORole.source );
070    else
071      rhsDuct = new HadoopCoGroupGate( flowProcess, (CoGroup) group, IORole.source );
072
073    addHead( rhsDuct );
074
075    handleDuct( group, rhsDuct );
076    }
077
078  @Override
079  protected SinkStage createSinkStage( Tap element )
080    {
081    return new HadoopSinkStage( flowProcess, element );
082    }
083
084  protected Gate createCoGroupGate( CoGroup element, IORole role )
085    {
086    throw new IllegalStateException( "should not happen" );
087    }
088
089  @Override
090  protected Gate createGroupByGate( GroupBy element, IORole role )
091    {
092    throw new IllegalStateException( "should not happen" );
093    }
094
095  @Override
096  protected Gate createHashJoinGate( HashJoin join )
097    {
098    throw new IllegalStateException( "should not happen" );
099    }
100
101  }