-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Add configurable final stages to MSQ ingestion queries #16699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
d8bdc2a
Add a segmentMorphFactory to MSQ.
adarshsanjeev a11d9c3
Add test
adarshsanjeev 51a619b
Make argument nullable
adarshsanjeev c2af5b8
Fix Guice issues
adarshsanjeev 16f7f94
Merge remote-tracking branch 'origin/master' into msq-segment-morpher
adarshsanjeev 0df3bc6
Merge with master
adarshsanjeev afb88e0
Remove extra information
adarshsanjeev 6591107
Fix tests
adarshsanjeev 021a527
Create a utils class
adarshsanjeev 75be018
Refactor segment generation
adarshsanjeev f6d185c
Fix javadoc
adarshsanjeev 5fb16d5
Refactor
adarshsanjeev 12e2205
Merge remote-tracking branch 'origin/master' into msq-segment-morpher
adarshsanjeev b588fa6
Refactor
adarshsanjeev f79535b
Merge remote-tracking branch 'origin/master' into msq-segment-morpher
adarshsanjeev 29406f4
Fix injection
adarshsanjeev a3de226
Merge remote-tracking branch 'origin/master' into msq-segment-morpher
adarshsanjeev 5890c41
Merge remote-tracking branch 'origin/master' into msq-segment-morpher
adarshsanjeev 67cdcac
Merge remote-tracking branch 'origin/master' into msq-segment-morpher
adarshsanjeev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
391 changes: 22 additions & 369 deletions
391
...nsions-core/multi-stage-query/src/main/java/org/apache/druid/msq/exec/ControllerImpl.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...lti-stage-query/src/main/java/org/apache/druid/msq/guice/MSQTerminalStageSpecFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.druid.msq.guice; | ||
|
|
||
| import org.apache.druid.msq.indexing.destination.SegmentGenerationStageSpec; | ||
| import org.apache.druid.msq.indexing.destination.TerminalStageSpec; | ||
| import org.apache.druid.sql.calcite.planner.PlannerContext; | ||
| import org.apache.druid.sql.calcite.rel.DruidQuery; | ||
|
|
||
| public class MSQTerminalStageSpecFactory | ||
| { | ||
| /** | ||
| * Creates a {@link TerminalStageSpec} which determines the final of a query. Currently, always returns a segment | ||
| * generation spec, but this can be used to configure a wide range of behaviours. | ||
| */ | ||
| public TerminalStageSpec createTerminalStageSpec(DruidQuery druidQuery, PlannerContext plannerContext) | ||
Check noticeCode scanning / CodeQL Useless parameter
The parameter 'plannerContext' is never used.
|
||
| { | ||
| return SegmentGenerationStageSpec.instance(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
...y/src/main/java/org/apache/druid/msq/indexing/destination/SegmentGenerationStageSpec.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.druid.msq.indexing.destination; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.google.common.collect.Iterables; | ||
| import it.unimi.dsi.fastutil.ints.Int2ObjectAVLTreeMap; | ||
| import it.unimi.dsi.fastutil.ints.Int2ObjectMap; | ||
| import org.apache.druid.frame.key.ClusterBy; | ||
| import org.apache.druid.msq.indexing.MSQSpec; | ||
| import org.apache.druid.msq.indexing.MSQTuningConfig; | ||
| import org.apache.druid.msq.indexing.processor.SegmentGeneratorFrameProcessorFactory; | ||
| import org.apache.druid.msq.input.stage.ReadablePartition; | ||
| import org.apache.druid.msq.input.stage.StageInputSlice; | ||
| import org.apache.druid.msq.input.stage.StageInputSpec; | ||
| import org.apache.druid.msq.kernel.QueryDefinition; | ||
| import org.apache.druid.msq.kernel.StageDefinition; | ||
| import org.apache.druid.msq.kernel.StageDefinitionBuilder; | ||
| import org.apache.druid.msq.kernel.controller.WorkerInputs; | ||
| import org.apache.druid.segment.column.RowSignature; | ||
| import org.apache.druid.segment.indexing.DataSchema; | ||
| import org.apache.druid.segment.realtime.appenderator.SegmentIdWithShardSpec; | ||
| import org.apache.druid.sql.calcite.planner.ColumnMappings; | ||
|
|
||
| import javax.annotation.Nullable; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class SegmentGenerationStageSpec implements TerminalStageSpec | ||
| { | ||
| public static final String TYPE = "segmentGeneration"; | ||
|
|
||
| private static final SegmentGenerationStageSpec INSTANCE = new SegmentGenerationStageSpec(); | ||
|
|
||
| private SegmentGenerationStageSpec() | ||
| { | ||
| } | ||
|
|
||
| @JsonCreator | ||
| public static SegmentGenerationStageSpec instance() | ||
| { | ||
| return INSTANCE; | ||
| } | ||
|
|
||
| @Override | ||
| public StageDefinitionBuilder constructFinalStage(QueryDefinition queryDef, MSQSpec querySpec, ObjectMapper jsonMapper) | ||
| { | ||
| final MSQTuningConfig tuningConfig = querySpec.getTuningConfig(); | ||
| final ColumnMappings columnMappings = querySpec.getColumnMappings(); | ||
| final RowSignature querySignature = queryDef.getFinalStageDefinition().getSignature(); | ||
| final ClusterBy queryClusterBy = queryDef.getFinalStageDefinition().getClusterBy(); | ||
|
|
||
| // Add a segment-generation stage. | ||
| final DataSchema dataSchema = | ||
| SegmentGenerationUtils.makeDataSchemaForIngestion(querySpec, querySignature, queryClusterBy, columnMappings, jsonMapper); | ||
|
|
||
| return StageDefinition.builder(queryDef.getNextStageNumber()) | ||
| .inputs(new StageInputSpec(queryDef.getFinalStageDefinition().getStageNumber())) | ||
| .maxWorkerCount(tuningConfig.getMaxNumWorkers()) | ||
| .processorFactory( | ||
| new SegmentGeneratorFrameProcessorFactory( | ||
| dataSchema, | ||
| columnMappings, | ||
| tuningConfig | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| public Int2ObjectMap<List<SegmentIdWithShardSpec>> getWorkerInfo( | ||
| final WorkerInputs workerInputs, | ||
| @Nullable final List<SegmentIdWithShardSpec> segmentsToGenerate | ||
| ) | ||
| { | ||
| final Int2ObjectMap<List<SegmentIdWithShardSpec>> retVal = new Int2ObjectAVLTreeMap<>(); | ||
|
|
||
| // Empty segments validation already happens when the stages are started -- so we cannot have both | ||
| // isFailOnEmptyInsertEnabled and segmentsToGenerate.isEmpty() be true here. | ||
| if (segmentsToGenerate == null || segmentsToGenerate.isEmpty()) { | ||
| return retVal; | ||
| } | ||
|
|
||
| for (final int workerNumber : workerInputs.workers()) { | ||
| // SegmentGenerator stage has a single input from another stage. | ||
| final StageInputSlice stageInputSlice = | ||
| (StageInputSlice) Iterables.getOnlyElement(workerInputs.inputsForWorker(workerNumber)); | ||
|
|
||
| final List<SegmentIdWithShardSpec> workerSegments = new ArrayList<>(); | ||
| retVal.put(workerNumber, workerSegments); | ||
|
|
||
| for (final ReadablePartition partition : stageInputSlice.getPartitions()) { | ||
| workerSegments.add(segmentsToGenerate.get(partition.getPartitionNumber())); | ||
| } | ||
| } | ||
|
|
||
| return retVal; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Useless parameter