spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chenghao-intel <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-8813][SQL][WIP]Combine splits by size
Date Fri, 16 Oct 2015 01:33:28 GMT
Github user chenghao-intel commented on a diff in the pull request:

    https://github.com/apache/spark/pull/9097#discussion_r42201403
  
    --- Diff: sql/hive/src/main/java/org/apache/spark/sql/hive/mapred/CombineSplitInputFormat.java
---
    @@ -0,0 +1,109 @@
    +/*
    + * 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.spark.sql.hive.mapred;
    +
    +import java.io.IOException;
    +import java.util.*;
    +
    +import com.clearspring.analytics.util.Lists;
    +import com.google.common.collect.Maps;
    +import com.google.common.collect.Sets;
    +import org.apache.hadoop.mapred.*;
    +
    +public class CombineSplitInputFormat<K, V> implements InputFormat<K, V> {
    +
    +  private InputFormat<K, V> inputformat;
    +  private long splitSize = 0;
    +
    +  public CombineSplitInputFormat(InputFormat<K, V> inputformat, long splitSize)
{
    +    this.inputformat = inputformat;
    +    this.splitSize = splitSize;
    +  }
    +
    +  /**
    +   * Create a single split from the list of blocks specified in validBlocks
    +   * Add this new split into splitList.
    +   */
    +  private void addCreatedSplit(List<CombineSplit> splitList,
    +                               long totalLen,
    +                               Collection<String> locations,
    +                               List<InputSplit> validSplits) {
    +    CombineSplit combineSparkSplit =
    +      new CombineSplit(validSplits.toArray(new InputSplit[0]),
    +        totalLen, locations.toArray(new String[0]));
    +    splitList.add(combineSparkSplit);
    +  }
    +
    +  @Override
    +  public InputSplit[] getSplits(JobConf job, int numSplits) throws IOException {
    +    InputSplit[] splits = inputformat.getSplits(job, numSplits);
    +    // populate nodeToSplits and splitsSet
    +    Map<String, List<InputSplit>> nodeToSplits = Maps.newHashMap();
    +    Set<InputSplit> splitsSet = Sets.newHashSet();
    +    for (InputSplit split: splits) {
    +      for (String node: split.getLocations()) {
    +        if (!nodeToSplits.containsKey(node)) {
    +          nodeToSplits.put(node, new ArrayList<InputSplit>());
    +        }
    +        nodeToSplits.get(node).add(split);
    +      }
    +      splitsSet.add(split);
    +    }
    +    // Iterate the nodes to combine in order to evenly distributing the splits
    +    List<CombineSplit> combineSparkSplits = Lists.newArrayList();
    +    List<InputSplit> oneCombinedSplits = Lists.newArrayList();
    +    long currentSplitSize = 0L;
    +    for (Map.Entry<String, List<InputSplit>> entry: nodeToSplits.entrySet())
{
    +      String node = entry.getKey();
    +      List<InputSplit> splitsPerNode = entry.getValue();
    +      for (InputSplit split: splitsPerNode) {
    +        if (splitSize != 0 && currentSplitSize > splitSize) {
    +          addCreatedSplit(combineSparkSplits,
    +            currentSplitSize, Collections.singleton(node), oneCombinedSplits);
    +          currentSplitSize = 0;
    +          oneCombinedSplits.clear();
    +        }
    +        // this split has been combined
    +        if (!splitsSet.contains(split)) {
    --- End diff --
    
    Put the checking a little bit ahead?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message