Copilot commented on code in PR #16953:
URL: https://github.com/apache/pinot/pull/16953#discussion_r2403691311


##########
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/loader/invertedindex/H3IndexHandler.java:
##########
@@ -95,6 +115,30 @@ public void updateIndices(SegmentDirectory.Writer 
segmentWriter)
         LOGGER.info("Removing existing H3 index from segment: {}, column: {}", 
segmentName, column);
         segmentWriter.removeIndex(column, StandardIndexes.h3());
         LOGGER.info("Removed existing H3 index from segment: {}, column: {}", 
segmentName, column);
+      } else {
+        // Index already exists, check for change in resolution config
+        short newResolution = 
_h3Configs.get(column).getResolution().serialize();
+        short oldResolution;
+
+        try (H3IndexReader indexReader = new ImmutableH3IndexReader(
+            segmentWriter.getIndexFor(column, StandardIndexes.h3()))) {
+          oldResolution = indexReader.getH3IndexResolution().serialize();
+        } catch (IOException e) {
+          LOGGER.warn("Failed to read existing H3 index for segment: {}, 
column: {}", segmentName, column, e);
+          segmentWriter.removeIndex(column, StandardIndexes.h3());
+          columnsToAddIdx.add(column);
+          continue;
+        }
+
+        if (newResolution != oldResolution) {
+          LOGGER.info(
+              "H3 index resolution changed for segment: {}, column: {}, old 
resolution: {}, new resolution: {}. "
+                  + "Deleting existing H3 index before rebuilding a new one.",
+              segmentName, column, oldResolution, newResolution);
+          segmentWriter.removeIndex(column, StandardIndexes.h3());
+          LOGGER.info("Removed existing H3 index from segment: {}, column: 
{}", segmentName, column);
+          columnsToAddIdx.add(column);
+        }

Review Comment:
   The resolution comparison and index rebuilding logic is duplicated between 
`needUpdateIndices()` and `updateIndices()` methods. Consider extracting this 
logic into a private helper method to reduce code duplication and improve 
maintainability.



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