carbondata-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ravipesala <...@git.apache.org>
Subject [GitHub] incubator-carbondata pull request #604: [CARBONDATA-691] After Compaction re...
Date Tue, 21 Feb 2017 14:52:04 GMT
Github user ravipesala commented on a diff in the pull request:

    https://github.com/apache/incubator-carbondata/pull/604#discussion_r102224557
  
    --- Diff: hadoop/src/main/java/org/apache/carbondata/hadoop/util/CarbonInputSplitTaskInfo.java
---
    @@ -0,0 +1,129 @@
    +/*
    + * 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.carbondata.hadoop.util;
    +
    +import java.io.IOException;
    +import java.util.ArrayList;
    +import java.util.Arrays;
    +import java.util.HashSet;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.Objects;
    +import java.util.Set;
    +import java.util.TreeMap;
    +
    +import org.apache.carbondata.core.datastore.block.Distributable;
    +import org.apache.carbondata.hadoop.CarbonInputSplit;
    +
    +public class CarbonInputSplitTaskInfo implements Distributable {
    +
    +  private final List<CarbonInputSplit> carbonBlockInfoList;
    +
    +  private final String taskId;
    +
    +  public String getTaskId() {
    +    return taskId;
    +  }
    +
    +  public List<CarbonInputSplit> getCarbonInputSplitList() {
    +    return carbonBlockInfoList;
    +  }
    +
    +  public CarbonInputSplitTaskInfo(String taskId, List<CarbonInputSplit> carbonSplitListInfo)
{
    +    this.taskId = taskId;
    +    this.carbonBlockInfoList = carbonSplitListInfo;
    +  }
    +
    +  @Override public String[] getLocations() {
    +    Set<String> locations = new HashSet<String>();
    +    for (CarbonInputSplit splitInfo : carbonBlockInfoList) {
    +      try {
    +        locations.addAll(Arrays.asList(splitInfo.getLocations()));
    +      } catch (IOException e) {
    +        e.printStackTrace();
    +      }
    +    }
    +    locations.toArray(new String[locations.size()]);
    +    List<String> nodes = CarbonInputSplitTaskInfo.maxNoNodes(carbonBlockInfoList);
    +    return nodes.toArray(new String[nodes.size()]);
    +  }
    +
    +  @Override public int compareTo(Distributable o) {
    +    return taskId.compareTo(((CarbonInputSplitTaskInfo) o).getTaskId());
    +  }
    +
    +  /**
    +   * Finding which node has the maximum number of blocks for it.
    +   *
    +   * @param blockList
    +   * @return
    +   */
    +  public static List<String> maxNoNodes(List<CarbonInputSplit> splitList)
{
    +    boolean useIndex = true;
    +    Integer maxOccurence = 0;
    +    String maxNode = null;
    +    Map<String, Integer> nodeAndOccurenceMapping = new TreeMap<>();
    +
    +    // populate the map of node and number of occurences of that node.
    +    for (CarbonInputSplit split : splitList) {
    +      try {
    +        for (String node : split.getLocations()) {
    +          Integer nodeOccurence = nodeAndOccurenceMapping.get(node);
    +          if (null == nodeOccurence) {
    +            nodeAndOccurenceMapping.put(node, 1);
    +          } else {
    +            nodeOccurence++;
    +          }
    +        }
    +      } catch (IOException e) {
    +        e.printStackTrace();
    --- End diff --
    
    Add logger or throw the exception


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

Mime
View raw message