itschrispeck commented on code in PR #15760:
URL: https://github.com/apache/pinot/pull/15760#discussion_r2082613399


##########
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:
   nit: the query level logs seem more like debug logs? Do you want to add a 
metric here? 



##########
pinot-common/src/main/java/org/apache/pinot/common/utils/config/QueryOptionsUtils.java:
##########
@@ -379,6 +380,10 @@ public static Boolean 
isUseMSEToFillEmptySchema(Map<String, String> queryOptions
     return useMSEToFillEmptySchema != null ? 
Boolean.parseBoolean(useMSEToFillEmptySchema) : defaultValue;
   }
 
+  public static boolean isInferInvalidSegmentPartition(Map<String, String> 
queryOptions) {
+    return 
BooleanUtils.toBoolean(queryOptions.getOrDefault(QueryOptionKey.INFER_INVALID_SEGMENT_PARTITION,
 "false"));

Review Comment:
   Any reason we don't stick w/ `Boolean.parseBoolean` like the other query 
options? For handling `1`? 



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