AmatyaAvadhanula commented on code in PR #15965:
URL: https://github.com/apache/druid/pull/15965#discussion_r1535072710


##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/exec/ControllerImpl.java:
##########
@@ -1719,9 +1731,129 @@ private void publishSegmentsIfNeeded(
       //noinspection unchecked
       @SuppressWarnings("unchecked")
       final Set<DataSegment> segments = (Set<DataSegment>) 
queryKernel.getResultObjectForStage(finalStageId);
+
+      Function<Set<DataSegment>, Set<DataSegment>> 
compactionStateAnnotateFunction = Function.identity();
+
+      Boolean storeCompactionState = (Boolean) task.getQuerySpec()
+                                                   .getQuery()
+                                                   .getContext()
+                                                   
.get(Tasks.STORE_COMPACTION_STATE_KEY);
+
+      if (storeCompactionState == null) {
+        storeCompactionState = Tasks.DEFAULT_STORE_COMPACTION_STATE;
+
+      }
+
+      if (!segments.isEmpty() && storeCompactionState) {
+        DataSchema dataSchema = ((SegmentGeneratorFrameProcessorFactory) 
queryKernel.getStageDefinition(finalStageId)
+                                                                               
     .getProcessorFactory()).getDataSchema();
+
+
+        ShardSpec shardSpec = 
segments.stream().findFirst().get().getShardSpec();
+
+        compactionStateAnnotateFunction = compactionStateAnnotateFunction(
+            task(),
+            context.jsonMapper(),
+            dataSchema,
+            shardSpec,
+            queryDef.getQueryId()
+        );
+
+      }
+
       log.info("Query [%s] publishing %d segments.", queryDef.getQueryId(), 
segments.size());
-      publishAllSegments(segments);
+      publishAllSegments(compactionStateAnnotateFunction.apply(segments));
+    }
+  }
+
+  public static Function<Set<DataSegment>, Set<DataSegment>> 
compactionStateAnnotateFunction(
+      MSQControllerTask task, ObjectMapper jsonMapper, DataSchema dataSchema, 
ShardSpec shardSpec, String queryId
+  )
+  {
+    DataSourceMSQDestination destination = (DataSourceMSQDestination) 
task.getQuerySpec().getDestination();
+    if (!destination.isReplaceTimeChunks()) {
+      // Only do this for replace queries, whether originating directly or via 
compaction
+      log.error("Query [%s] skipping storing compaction state in segments as 
query not of type REPLACE.", queryId);

Review Comment:
   This method is presently being called irrespective of the query being INSERT 
/ REPLACE.
   I think the defensive check can be done in the calling method itself.



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