001 /* 002 * Copyright (c) 2007-2014 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 021 package cascading.flow.stream; 022 023 import cascading.CascadingException; 024 import cascading.flow.FlowProcess; 025 import cascading.operation.Filter; 026 import cascading.pipe.Each; 027 import cascading.pipe.OperatorException; 028 import cascading.tuple.Fields; 029 import cascading.tuple.TupleEntry; 030 031 /** 032 * 033 */ 034 public class FilterEachStage extends EachStage 035 { 036 private Filter filter; 037 038 public FilterEachStage( FlowProcess flowProcess, Each each ) 039 { 040 super( flowProcess, each ); 041 } 042 043 @Override 044 protected Fields getIncomingPassThroughFields() 045 { 046 return incomingScopes.get( 0 ).getIncomingFunctionPassThroughFields(); 047 } 048 049 @Override 050 protected Fields getIncomingArgumentsFields() 051 { 052 return incomingScopes.get( 0 ).getIncomingFunctionArgumentFields(); 053 } 054 055 @Override 056 public void initialize() 057 { 058 super.initialize(); 059 060 filter = each.getFilter(); 061 } 062 063 @Override 064 public void receive( Duct previous, TupleEntry incomingEntry ) 065 { 066 argumentsEntry.setTuple( argumentsBuilder.makeResult( incomingEntry.getTuple(), null ) ); 067 068 try 069 { 070 if( filter.isRemove( flowProcess, operationCall ) ) 071 return; 072 073 next.receive( this, incomingEntry ); 074 } 075 catch( CascadingException exception ) 076 { 077 handleException( exception, argumentsEntry ); 078 } 079 catch( Throwable throwable ) 080 { 081 handleException( new OperatorException( each, "operator Each failed executing operation", throwable ), argumentsEntry ); 082 } 083 } 084 }