Github user atsikiridis commented on a diff in the pull request:

    https://github.com/apache/incubator-flink/pull/37#discussion_r15544868
  
    --- Diff: 
flink-addons/flink-hadoop-compatibility/src/main/java/org/apache/flink/hadoopcompatibility/mapred/HadoopReduceFunction.java
 ---
    @@ -0,0 +1,199 @@
    +/**
    + * 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.hadoopcompatibility.mapred;
    +
    +import org.apache.flink.api.java.functions.GroupReduceFunction;
    +import 
org.apache.flink.api.java.operators.translation.TupleUnwrappingIterator;
    +import org.apache.flink.api.java.tuple.Tuple2;
    +import org.apache.flink.api.java.typeutils.ResultTypeQueryable;
    +import org.apache.flink.api.java.typeutils.TupleTypeInfo;
    +import org.apache.flink.api.java.typeutils.WritableTypeInfo;
    +import 
org.apache.flink.hadoopcompatibility.mapred.utils.HadoopConfiguration;
    +import 
org.apache.flink.hadoopcompatibility.mapred.wrapper.HadoopDummyReporter;
    +import 
org.apache.flink.hadoopcompatibility.mapred.wrapper.HadoopOutputCollector;
    +import org.apache.flink.types.TypeInformation;
    +import org.apache.flink.util.Collector;
    +import org.apache.flink.util.InstantiationUtil;
    +import org.apache.hadoop.io.Writable;
    +import org.apache.hadoop.io.WritableComparable;
    +import org.apache.hadoop.io.WritableUtils;
    +import org.apache.hadoop.mapred.JobConf;
    +import org.apache.hadoop.mapred.Reducer;
    +import org.apache.hadoop.mapred.Reporter;
    +
    +import java.io.IOException;
    +import java.io.ObjectInputStream;
    +import java.io.ObjectOutputStream;
    +import java.io.Serializable;
    +import java.util.Iterator;
    +
    +/**
    + * The wrapper for a Hadoop Reducer (mapred API).
    + */
    +public class HadoopReduceFunction<KEYIN extends WritableComparable, 
VALUEIN extends Writable,
    +           KEYOUT extends WritableComparable, VALUEOUT extends Writable> 
extends GroupReduceFunction<Tuple2<KEYIN,VALUEIN>,
    +           Tuple2<KEYOUT,VALUEOUT>> implements Serializable, 
ResultTypeQueryable<Tuple2<KEYOUT,VALUEOUT>> {
    +
    +   private static final long serialVersionUID = 1L;
    +
    +   private Class<KEYOUT> keyoutClass;
    +   private Class<VALUEOUT> valueoutClass;
    +   private JobConf jobConf;
    +
    +   private Reducer<KEYIN,VALUEIN,KEYOUT,VALUEOUT> reducer;
    +   private Reducer<KEYIN,VALUEIN,KEYOUT,VALUEOUT> combiner;
    +   private HadoopOutputCollector outputCollector;
    +   private Reporter reporter;
    +   private ReducerTransformingIterator iterator;
    +
    +   @SuppressWarnings("unchecked")
    +   public HadoopReduceFunction(JobConf jobConf) {
    +           this.jobConf = jobConf;
    +
    +           this.reducer = 
InstantiationUtil.instantiate(jobConf.getReducerClass());
    +           final Class combinerClass = jobConf.getCombinerClass();
    +           if (combinerClass != null) {
    +                   this.combiner = (Reducer<KEYIN, VALUEIN, KEYOUT, 
VALUEOUT>) InstantiationUtil.instantiate(combinerClass);
    +           }
    +
    +           this.keyoutClass = (Class<KEYOUT>) jobConf.getOutputKeyClass();
    +           this.valueoutClass = (Class<VALUEOUT>) 
jobConf.getOutputValueClass();
    +           this.outputCollector = new HadoopOutputCollector(keyoutClass, 
valueoutClass);
    +           this.iterator = new ReducerTransformingIterator();
    +           this.reporter = new HadoopDummyReporter();
    +   }
    +
    +   /**
    +    * A wrapping iterator for an iterator of key-value tuples that can be 
used as an iterator of values.
    +    */
    +   private final class ReducerTransformingIterator extends 
TupleUnwrappingIterator<VALUEIN,KEYIN>
    +                   implements java.io.Serializable {
    +
    +           private static final long serialVersionUID = 1L;
    +           private Iterator<Tuple2<KEYIN,VALUEIN>> iterator;
    +           private KEYIN key;
    +           private Tuple2<KEYIN,VALUEIN> first;
    +
    +           @Override()
    +           public void set(Iterator<Tuple2<KEYIN,VALUEIN>> iterator) {
    +                   this.iterator = iterator;
    +                   if(this.hasNext()) {
    +                           this.first = iterator.next();
    +                           this.key = this.first.f0;
    +                   }
    +           }
    +
    +           @Override
    +           public boolean hasNext() {
    +                   if(this.first != null) {
    +                           return true;
    +                   }
    +                   return iterator.hasNext();
    +           }
    +
    +           @Override
    +           public VALUEIN next() {
    +                   if(this.first != null) {
    +                           final VALUEIN val = this.first.f1;
    +                           this.first = null;
    +                           return val;
    +                   }
    +                   final Tuple2<KEYIN,VALUEIN> tuple = iterator.next();
    +                   return tuple.f1;
    +           }
    +
    +           private KEYIN getKey() {
    +                   return WritableUtils.clone(this.key, jobConf);
    +           }
    +
    +           @Override
    +           public void remove() {
    +                   throw new UnsupportedOperationException();
    +           }
    +   }
    +
    +   @Override
    +   @SuppressWarnings("unchecked")
    +   public void reduce(Iterator<Tuple2<KEYIN,VALUEIN>> values, 
Collector<Tuple2<KEYOUT,VALUEOUT>> out)
    +                   throws Exception {
    +           outputCollector.set(out);
    +           iterator.set(values);
    +           reducer.reduce(iterator.getKey(), iterator, outputCollector, 
reporter);
    +   }
    +
    +   @Override
    +   @SuppressWarnings("unchecked")
    +   public void combine(Iterator<Tuple2<KEYIN,VALUEIN>> values, 
Collector<Tuple2<KEYIN,VALUEIN>> out) throws Exception {
    +           if (this.combiner == null) {
    --- End diff --
    
    The default value for ```JobConf.getCombinerClass()``` is null ( and this 
is not the case with Mappers and Reducers that have their respective identity 
functions as default. Even if the user wants the combiner to be the same as the 
reducer he has to explicitly say so. Otherwise, the job runs with no combine 
phase. Do you suggest that the combiner class should be the reducer class by 
default and that we should never skip reducing?
    
    Moreover, in the client there is:
    ```java
                final Class<? extends Reducer> combinerClass = 
hadoopJobConf.getCombinerClass();
                if (combinerClass != null) {
                        reduceOp.setCombinable(true);
                }
    ```
    
    so if there is no combiner the function is not combinable for Flink. Isn't 
that correct?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to