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



##########
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:
       For consistent behavior, I agree to continue to throw exception if 
required to down convert, instead of NOOP, as the upper layer may catch and 
handle exception.
   
   And I'd prefer to continue to throw the exception from `getConverter`, as 
per the error msg, it's about not able to find converter to do the down 
convert, instead of not allowing it.




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