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

    https://github.com/apache/incubator-flink/pull/37#discussion_r15390287
  
    --- Diff: 
flink-addons/flink-hadoop-compatibility/src/main/java/org/apache/flink/hadoopcompatibility/mapred/FlinkHadoopJobClient.java
 ---
    @@ -0,0 +1,318 @@
    +/**
    + * 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.DataSet;
    +import org.apache.flink.api.java.ExecutionEnvironment;
    +import org.apache.flink.api.java.operators.FlatMapOperator;
    +import org.apache.flink.api.java.operators.ReduceGroupOperator;
    +import org.apache.flink.api.java.operators.UnsortedGrouping;
    +import org.apache.flink.api.java.typeutils.TypeExtractor;
    +import 
org.apache.flink.hadoopcompatibility.mapred.utils.HadoopIdentityReduce;
    +import 
org.apache.flink.hadoopcompatibility.mapred.wrapper.HadoopGroupingKeySelector;
    +import 
org.apache.flink.hadoopcompatibility.mapred.wrapper.HadoopPartitioner;
    +import org.apache.flink.types.TypeInformation;
    +import org.apache.flink.util.InstantiationUtil;
    +import org.apache.hadoop.conf.Configuration;
    +import org.apache.hadoop.io.RawComparator;
    +import org.apache.hadoop.mapred.Counters;
    +import org.apache.hadoop.mapred.InputFormat;
    +import org.apache.hadoop.mapred.JobClient;
    +import org.apache.hadoop.mapred.JobConf;
    +import org.apache.hadoop.mapred.JobID;
    +import org.apache.hadoop.mapred.JobStatus;
    +import org.apache.hadoop.mapred.Mapper;
    +import org.apache.hadoop.mapred.Partitioner;
    +import org.apache.hadoop.mapred.Reducer;
    +import org.apache.hadoop.mapred.RunningJob;
    +import org.apache.hadoop.mapred.TaskAttemptID;
    +import org.apache.hadoop.mapred.TaskCompletionEvent;
    +
    +import java.io.IOException;
    +
    +/**
    + * The user's view of a Hadoop Job executed on a Flink cluster.
    + */
    +public class FlinkHadoopJobClient extends JobClient {
    +
    +   private final ExecutionEnvironment environment;
    +   private Configuration hadoopConf;
    +
    +   public FlinkHadoopJobClient() throws IOException {
    +           this(new Configuration());
    +   }
    +
    +   public FlinkHadoopJobClient(JobConf jobConf) throws IOException {
    +           this(new Configuration(jobConf));
    +   }
    +
    +   public FlinkHadoopJobClient(Configuration hadoopConf) throws 
IOException{
    +           this(hadoopConf, 
(ExecutionEnvironment.getExecutionEnvironment()));
    +   }
    +
    +   public FlinkHadoopJobClient(Configuration hadoopConf, 
ExecutionEnvironment environment) throws IOException {
    +           super(new JobConf(hadoopConf));
    +           this.hadoopConf = hadoopConf;
    +           this.environment = environment;
    +   }
    +
    +   /**
    +    * Submits a Hadoop job to Flink (as described by the JobConf) and 
returns after the job has been completed.
    +    */
    +   public static RunningJob runJob(JobConf hadoopJobConf) throws 
IOException{
    +           final FlinkHadoopJobClient jobClient = new 
FlinkHadoopJobClient(hadoopJobConf);
    +           final RunningJob job = jobClient.submitJob(hadoopJobConf);
    +           job.waitForCompletion();
    +           return job;
    +   }
    +
    +   /**
    +    * Submits a job to Flink and returns a RunningJob instance which can 
be scheduled and monitored
    +    * without blocking by default. Use waitForCompletion() to block until 
the job is finished.
    +    */
    +   @Override
    +   @SuppressWarnings("unchecked")
    +   public RunningJob submitJob(JobConf hadoopJobConf) throws IOException{
    +
    +           //setting up the inputFormat for the job
    +           final DataSet input = 
environment.createInput(getFlinkInputFormat(hadoopJobConf));
    +
    +           final Mapper mapper = 
InstantiationUtil.instantiate(hadoopJobConf.getMapperClass());
    +           final Class mapOutputKeyClass = 
hadoopJobConf.getMapOutputKeyClass();
    +           final Class mapOutputValueClass = 
hadoopJobConf.getMapOutputValueClass();
    +           final FlatMapOperator mapped = input.flatMap(new 
HadoopMapFunction(mapper, mapOutputKeyClass,
    +                           mapOutputValueClass));
    +           mapped.setParallelism(getMapParallelism(hadoopJobConf));
    +
    +           //Partitioning
    --- End diff --
    
    The issue is that Flink uses the same key for partitioning and grouping, 
i.e., it would also partition on `keyOfGroup` and group on `partition`. Of 
course, partitioning and grouping are separate operations in the execution 
layer, but the API gives the same key for both to the optimizer.
    
    If neither the partitioner or sorter are custom, MapReduce will also use 
the same key for both operations, i.e., behave the same way as Flink.
    
    For this PR, I'd simply throw an exception if you encounter a user-defined 
partitioner or comparator and support only the default case. We need to think 
carefully how we can add support for custom partitioners and comparators and 
might need to extend the API or add a hook somewhere to enable that.


---
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