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

    https://github.com/apache/carbondata/pull/2601#discussion_r207430989
  
    --- Diff: 
core/src/main/java/org/apache/carbondata/core/util/CarbonUtil.java ---
    @@ -3212,28 +3213,27 @@ public static ColumnarFormatVersion 
getFormatVersion(CarbonTable carbonTable)
           }
           storePath = 
carbonTable.getSegmentPath(validSegments.get(0).getSegmentNo());
         }
    -
    -    CarbonFile[] carbonFiles = FileFactory
    -        .getCarbonFile(storePath)
    -        .listFiles(new CarbonFileFilter() {
    -          @Override
    -          public boolean accept(CarbonFile file) {
    -            if (file == null) {
    -              return false;
    -            }
    -            return file.getName().endsWith("carbondata");
    -          }
    -        });
    -    if (carbonFiles == null || carbonFiles.length < 1) {
    -      return CarbonProperties.getInstance().getFormatVersion();
    +    // get the carbon index file header
    +    FileFactory.FileType fileType = FileFactory.getFileType(storePath);
    +    ColumnarFormatVersion version = null;
    +    if (FileFactory.isFileExist(storePath, fileType)) {
    +      SegmentIndexFileStore fileStore = new SegmentIndexFileStore();
    +      fileStore.readAllIIndexOfSegment(storePath);
    +      Map<String, byte[]> carbonIndexMap = fileStore.getCarbonIndexMap();
    +      if (carbonIndexMap.size() == 0) {
    +        version = CarbonProperties.getInstance().getFormatVersion();
    +      }
    +      CarbonIndexFileReader indexReader = new CarbonIndexFileReader();
    +      for (byte[] fileData : carbonIndexMap.values()) {
    +        indexReader.openThriftReader(fileData);
    +        IndexHeader indexHeader = indexReader.readIndexHeader();
    +        version = 
ColumnarFormatVersion.valueOf((short)indexHeader.getVersion());
    +        break;
    --- End diff --
    
     modified according to review comments


---

Reply via email to