ankitsultana commented on code in PR #15760: URL: https://github.com/apache/pinot/pull/15760#discussion_r2082639020
########## pinot-query-planner/src/main/java/org/apache/pinot/query/planner/physical/v2/opt/rules/LeafStageWorkerAssignmentRule.java: ########## @@ -326,6 +340,56 @@ static TableScanWorkerAssignmentResult attemptPartitionedDistribution(String tab return new TableScanWorkerAssignmentResult(dataDistribution, workerIdToSegmentsMap); } + /** + * Infers partition from invalid segments if the passed flag is set to true. + */ + @VisibleForTesting + static Map<Integer, List<String>> getInvalidSegmentsByInferredPartition(@Nullable List<String> invalidSegments, + boolean inferPartitionsForInvalidSegments, String tableNameWithType) { + if (CollectionUtils.isEmpty(invalidSegments)) { + return Map.of(); + } else if (!Objects.equals(TableNameBuilder.getTableTypeFromTableName(tableNameWithType), TableType.REALTIME) + || !inferPartitionsForInvalidSegments) { + throw new IllegalStateException(String.format("Table %s has %s segments with invalid partition info. Will " + + "assume un-partitioned distribution. Sampled: %s", tableNameWithType, invalidSegments.size(), + sampleSegmentsForLogging(invalidSegments))); + } + Map<Integer, List<String>> invalidSegmentsByInferredPartition = new HashMap<>(); + for (String invalidPartitionSegment : invalidSegments) { + int partitionId = -1; + if (LLCSegmentName.isLLCSegment(invalidPartitionSegment)) { + LLCSegmentName llcSegmentName = LLCSegmentName.of(invalidPartitionSegment); + if (llcSegmentName != null) { + partitionId = llcSegmentName.getPartitionGroupId(); + } + } else if (UploadedRealtimeSegmentName.isUploadedRealtimeSegmentName(invalidPartitionSegment)) { + UploadedRealtimeSegmentName uploadedRealtimeSegmentName = UploadedRealtimeSegmentName.of( + invalidPartitionSegment); + if (uploadedRealtimeSegmentName != null) { + partitionId = uploadedRealtimeSegmentName.getPartitionId(); + } + } + if (partitionId == -1) { + throw new IllegalStateException(String.format("Could not infer partition for segment: %s. Falling back to " + + "un-partitioned distribution", invalidPartitionSegment)); + } + invalidSegmentsByInferredPartition.computeIfAbsent(partitionId, (x) -> new ArrayList<>()).add( + invalidPartitionSegment); + } + LOGGER.info("Realtime Table {} has {} segments with invalid partition info. Assuming partitionId from stream " + + "partition ID. Sampled segments: {}", tableNameWithType, invalidSegments, + sampleSegmentsForLogging(invalidSegments)); Review Comment: good catch. addressed -- 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: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org