siddharthteotia commented on a change in pull request #7898:
URL: https://github.com/apache/pinot/pull/7898#discussion_r769209971



##########
File path: 
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/indexsegment/immutable/ImmutableSegmentLoader.java
##########
@@ -173,6 +174,34 @@ public static ImmutableSegment load(File indexDir, 
IndexLoadingConfig indexLoadi
     return segment;
   }
 
+  /**
+   * Check segment directory against the table config and schema to see if any 
preprocessing is needed,
+   * like changing segment format, adding new indices or updating default 
columns.
+   */
+  public static boolean needPreprocess(SegmentDirectory segmentDirectory, 
IndexLoadingConfig indexLoadingConfig,
+      @Nullable Schema schema)
+      throws Exception {
+    if (needConvertSegmentFormat(indexLoadingConfig, 
segmentDirectory.getSegmentMetadata())) {
+      return true;
+    }
+    SegmentPreProcessor preProcessor = new 
SegmentPreProcessor(segmentDirectory, indexLoadingConfig, schema);
+    return preProcessor.needProcess();
+  }
+
+  @VisibleForTesting
+  static boolean needConvertSegmentFormat(IndexLoadingConfig 
indexLoadingConfig,
+      SegmentMetadataImpl segmentMetadata) {
+    SegmentVersion segmentVersionToLoad = 
indexLoadingConfig.getSegmentVersion();
+    if (segmentVersionToLoad == null) {
+      return false;
+    }
+    File indexDir = segmentMetadata.getIndexDir();
+    if (indexDir != null && 
SegmentDirectoryPaths.segmentDirectoryFor(indexDir, 
segmentVersionToLoad).isDirectory()) {
+      return false;
+    }
+    return segmentVersionToLoad != segmentMetadata.getVersion();

Review comment:
       Today during segment preprocessor when the converter is created, we 
throw exception for down convert from v3 to v1 / v2.
   
    ```
   public static SegmentFormatConverter getConverter(SegmentVersion from, 
SegmentVersion to) {
   
       if ((from.equals(SegmentVersion.v1) || from.equals(SegmentVersion.v2)) 
&& to.equals(SegmentVersion.v3)) {
         return new SegmentV1V2ToV3FormatConverter();
       }
   
       throw new UnsupportedOperationException("Unable to find a converter to 
convert segment from:" + from + " to:" + to);
     }
   ```
   
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to