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

    https://github.com/apache/carbondata/pull/2091#discussion_r176903993
  
    --- Diff: 
core/src/main/java/org/apache/carbondata/core/statusmanager/SegmentStatusManager.java
 ---
    @@ -913,4 +950,91 @@ public static void deleteLoadsAndUpdateMetadata(
         CarbonLockUtil.deleteExpiredSegmentLockFiles(carbonTable);
       }
     
    +  /**
    +   * Get the number of invisible segment info from segment info list.
    +   */
    +  public static int countInvisibleSegments(LoadMetadataDetails[] 
segmentList) {
    +    int invisibleSegmentCnt = 0;
    +    if (segmentList.length != 0) {
    +      for (LoadMetadataDetails eachSeg : segmentList) {
    +        // can not remove segment 0, there are some info will be used later
    +        // for example: updateStatusFileName
    +        if (!eachSeg.getLoadName().equalsIgnoreCase("0")
    +            && eachSeg.getVisibility().equalsIgnoreCase("false")) {
    +          invisibleSegmentCnt += 1;
    +        }
    +      }
    +    }
    +    return invisibleSegmentCnt;
    +  }
    +
    +  private static class TableStatusReturnTuple {
    +    LoadMetadataDetails[] arrayOfLoadDetails;
    +    LoadMetadataDetails[] arrayOfLoadHistoryDetails;
    +    TableStatusReturnTuple(LoadMetadataDetails[] arrayOfLoadDetails,
    +        LoadMetadataDetails[] arrayOfLoadHistoryDetails) {
    +      this.arrayOfLoadDetails = arrayOfLoadDetails;
    +      this.arrayOfLoadHistoryDetails = arrayOfLoadHistoryDetails;
    +    }
    +  }
    +
    +  /**
    +   * Separate visible and invisible segments into two array.
    +   */
    +  public static TableStatusReturnTuple separateVisibleAndInvisibleSegments(
    +      LoadMetadataDetails[] oldList,
    +      LoadMetadataDetails[] newList,
    +      int invisibleSegmentCnt) {
    +    int newSegmentsLength = newList.length;
    +    int visibleSegmentCnt = newSegmentsLength - invisibleSegmentCnt;
    +    LoadMetadataDetails[] arrayOfVisibleSegments = new 
LoadMetadataDetails[visibleSegmentCnt];
    +    LoadMetadataDetails[] arrayOfInvisibleSegments = new 
LoadMetadataDetails[invisibleSegmentCnt];
    +    int oldSegmentsLength = oldList.length;
    +    int visibleIdx = 0;
    +    int invisibleIdx = 0;
    +    for (int i = 0; i < newSegmentsLength; i++) {
    +      LoadMetadataDetails newSegment = newList[i];
    +      if (i < oldSegmentsLength) {
    +        LoadMetadataDetails oldSegment = oldList[i];
    +        if (newSegment.getLoadName().equalsIgnoreCase("0")) {
    +          newSegment.setVisibility(oldSegment.getVisibility());
    +          arrayOfVisibleSegments[visibleIdx] = newSegment;
    +          visibleIdx++;
    +        } else if ("false".equalsIgnoreCase(oldSegment.getVisibility())) {
    +          newSegment.setVisibility("false");
    +          arrayOfInvisibleSegments[invisibleIdx] = newSegment;
    +          invisibleIdx++;
    +        } else {
    +          arrayOfVisibleSegments[visibleIdx] = newSegment;
    +          visibleIdx++;
    +        }
    +      } else {
    +        arrayOfVisibleSegments[visibleIdx] = newSegment;
    +        visibleIdx++;
    +      }
    +    }
    +    return new TableStatusReturnTuple(arrayOfVisibleSegments, 
arrayOfInvisibleSegments);
    +  }
    +
    +  /**
    +   * Append new invisible segment info to old list.
    --- End diff --
    
    change to `Pick all invisible segment entries in appendList and add them 
into historyList`


---

Reply via email to