gargvishesh commented on code in PR #15965:
URL: https://github.com/apache/druid/pull/15965#discussion_r1512156226
##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/exec/ControllerImpl.java:
##########
@@ -1715,12 +1725,95 @@ private void publishSegmentsIfNeeded(
{
if (queryKernel.isSuccess() &&
MSQControllerTask.isIngestion(task.getQuerySpec())) {
final StageId finalStageId =
queryKernel.getStageId(queryDef.getFinalStageDefinition().getStageNumber());
+ queryDef.getFinalStageDefinition().getClusterBy();
//noinspection unchecked
@SuppressWarnings("unchecked")
final Set<DataSegment> segments = (Set<DataSegment>)
queryKernel.getResultObjectForStage(finalStageId);
+ DataSchema dataSchema = ((SegmentGeneratorFrameProcessorFactory)
queryKernel.getStageDefinition(finalStageId)
+
.getProcessorFactory()).getDataSchema();
+
+ ShardSpec shardSpec = segments.isEmpty()
+ ? null
+ : segments.stream()
+ .findFirst()
+ .get()
+
.getShardSpec();
+ List<String> partitionDimensions = Collections.emptyList();
+
+ if (shardSpec != null && (Objects.equals(shardSpec.getType(),
ShardSpec.Type.SINGLE)
+ || Objects.equals(shardSpec.getType(),
ShardSpec.Type.RANGE))) {
+ partitionDimensions = ((DimensionRangeShardSpec)
shardSpec).getDimensions();
+ }
+
+ Function<Set<DataSegment>, Set<DataSegment>>
compactionStateAnnotateFunction = compactionStateAnnotateFunction(
+ task(),
+ context.jsonMapper(),
+ dataSchema,
+ partitionDimensions
+ );
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,
+ List<String> partitionDimensions
+ )
+ {
+ final boolean storeCompactionState = task.getContextValue(
Review Comment:
Moved this to query context
##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/exec/ControllerImpl.java:
##########
@@ -1715,12 +1725,95 @@ private void publishSegmentsIfNeeded(
{
if (queryKernel.isSuccess() &&
MSQControllerTask.isIngestion(task.getQuerySpec())) {
final StageId finalStageId =
queryKernel.getStageId(queryDef.getFinalStageDefinition().getStageNumber());
+ queryDef.getFinalStageDefinition().getClusterBy();
//noinspection unchecked
@SuppressWarnings("unchecked")
final Set<DataSegment> segments = (Set<DataSegment>)
queryKernel.getResultObjectForStage(finalStageId);
+ DataSchema dataSchema = ((SegmentGeneratorFrameProcessorFactory)
queryKernel.getStageDefinition(finalStageId)
+
.getProcessorFactory()).getDataSchema();
+
+ ShardSpec shardSpec = segments.isEmpty()
+ ? null
+ : segments.stream()
+ .findFirst()
+ .get()
+
.getShardSpec();
+ List<String> partitionDimensions = Collections.emptyList();
+
+ if (shardSpec != null && (Objects.equals(shardSpec.getType(),
ShardSpec.Type.SINGLE)
+ || Objects.equals(shardSpec.getType(),
ShardSpec.Type.RANGE))) {
+ partitionDimensions = ((DimensionRangeShardSpec)
shardSpec).getDimensions();
+ }
+
+ Function<Set<DataSegment>, Set<DataSegment>>
compactionStateAnnotateFunction = compactionStateAnnotateFunction(
+ task(),
+ context.jsonMapper(),
+ dataSchema,
+ partitionDimensions
+ );
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,
+ List<String> partitionDimensions
+ )
+ {
+ final boolean storeCompactionState = task.getContextValue(
+ Tasks.STORE_COMPACTION_STATE_KEY,
+ Tasks.DEFAULT_STORE_COMPACTION_STATE
+ );
+
+ if (storeCompactionState) {
Review Comment:
Done. Thanks!
--
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]