You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "clintropolis (via GitHub)" <gi...@apache.org> on 2025/01/30 04:28:52 UTC
Re: [PR] Enable querying policy-enabled table in MSQ, and use RestrictedDataSource as a base in DataSourceAnalysis. (druid)
clintropolis commented on code in PR #17666:
URL: https://github.com/apache/druid/pull/17666#discussion_r1934709207
##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/exec/RunWorkOrder.java:
##########
@@ -399,29 +398,29 @@ private void makeShuffleOutputChannelFactory()
* Use {@link FrameProcessorFactory#makeProcessors} to create {@link ProcessorsAndChannels}. Executes the
* processors using {@link #exec} and sets the output channels in {@link #workResultAndOutputChannels}.
*
- * @param <FactoryType> type of {@link StageDefinition#getProcessorFactory()}
- * @param <ProcessorReturnType> return type of {@link FrameProcessor} created by the manager
- * @param <ManagerReturnType> result type of {@link ProcessorManager#result()}
- * @param <ExtraInfoType> type of {@link WorkOrder#getExtraInfo()}
+ * @param <FactoryT> type of {@link StageDefinition#getProcessorFactory()}
+ * @param <ProcessorReturnT> return type of {@link FrameProcessor} created by the manager
+ * @param <ManagerReturnT> result type of {@link ProcessorManager#result()}
+ * @param <ExtraInfoT> type of {@link WorkOrder#getExtraInfo()}
*/
- private <FactoryType extends FrameProcessorFactory<ProcessorReturnType, ManagerReturnType, ExtraInfoType>, ProcessorReturnType, ManagerReturnType, ExtraInfoType> void makeAndRunWorkProcessors()
- throws IOException
+ private <FactoryT extends FrameProcessorFactory<ProcessorReturnT, ManagerReturnT, ExtraInfoT>, ProcessorReturnT, ManagerReturnT, ExtraInfoT>
Review Comment:
nit: why change these names? just seems to add extra noise to the PR
##########
sql/src/main/java/org/apache/druid/sql/calcite/rel/DruidQuery.java:
##########
@@ -981,10 +1001,18 @@ public Query<?> getQuery()
}
/**
- * Return this query as some kind of Druid query. The returned query will either be {@link TopNQuery},
- * {@link TimeseriesQuery}, {@link GroupByQuery}, {@link ScanQuery}
+ * Computes a native druid query, must be called from the constructor. The returned query will be one of following:
+ * <ul>
+ * <li> {@link GroupByQuery}
+ * <li> {@link WindowOperatorQuery}
+ * <li> {@link TimeBoundaryQuery}
+ * <li> {@link TimeseriesQuery}
+ * <li> {@link TopNQuery}
+ * <li> {@link ScanQuery}
+ * </ul>
Review Comment:
nit: afaik we do not publish javadocs, so these could just be a plain list
##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/exec/RunWorkOrder.java:
##########
@@ -430,27 +429,19 @@ private <FactoryType extends FrameProcessorFactory<ProcessorReturnType, ManagerR
removeNullBytes
);
- final ProcessorManager<ProcessorReturnType, ManagerReturnType> processorManager = processors.getProcessorManager();
-
- final int maxOutstandingProcessors;
-
- if (processors.getOutputChannels().getAllChannels().isEmpty()) {
- // No output channels: run up to "parallelism" processors at once.
- maxOutstandingProcessors = Math.max(1, parallelism);
- } else {
- // If there are output channels, that acts as a ceiling on the number of processors that can run at once.
- maxOutstandingProcessors =
- Math.max(1, Math.min(parallelism, processors.getOutputChannels().getAllChannels().size()));
- }
+ final ProcessorManager<ProcessorReturnT, ManagerReturnT> processorManager = processors.getProcessorManager();
+ final OutputChannels outputChannels = processors.getOutputChannels();
- final ListenableFuture<ManagerReturnType> workResultFuture = exec.runAllFully(
+ final int channelSize = outputChannels.getAllChannels().size();
+ final int parallelismBoundedByChannelSize = channelSize == 0 ? parallelism : Math.min(parallelism, channelSize);
+ final int maxOutstandingProcessors = Math.max(1, parallelismBoundedByChannelSize);
Review Comment:
nit: the old code seemed clearer and had comments that were nice
##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/exec/RunWorkOrder.java:
##########
@@ -1187,6 +1149,11 @@ public OutputChannels getOutputChannels()
{
return outputChannels;
}
+
+ public ListenableFuture<OutputChannels> waitResultReadyAndGetSanityCheckedChannels()
Review Comment:
i think this could just be called `waitResultReady`
##########
sql/src/main/java/org/apache/druid/sql/calcite/rel/DruidQuery.java:
##########
@@ -185,20 +187,40 @@ private DruidQuery(
this.grouping = grouping;
this.sorting = sorting;
this.windowing = windowing;
- this.sourceRowSignature = sourceRowSignature;
- this.outputRowSignature = computeOutputRowSignature(
- sourceRowSignature,
+ this.sourceRowSignature = Preconditions.checkNotNull(sourceRowSignature, "sourceRowSignature");
+ this.outputRowSignature = Preconditions.checkNotNull(outputRowSignature, "outputRowSignature");
+ this.outputRowType = Preconditions.checkNotNull(outputRowType, "outputRowType");
+ this.virtualColumnRegistry = Preconditions.checkNotNull(virtualColumnRegistry, "virtualColumnRegistry");
+ this.query = query == null ? computeQuery() : query;
+ }
+
+ /**
+ * Returns an updated {@link DruidQuery} based on the policy restrictions on tables.
+ */
+ public DruidQuery withPolicies(Map<String, Optional<Policy>> policyMap)
Review Comment:
this method seems off to me, like why isn't `dataSource` updated as well? I think calling this makes a `DruidQuery` that is in a bit of a strange state, and I think it basically only chill with the way that `MSQTaskQueryMaker` is working since it only really modifies the `query` part of the `DruidQuery`.
I'm not sure what is better to do here, since it is maybe odd that MSQ is using `DruidQuery` directly for stuff while this is filled with planner stuff, need to think about it a bit.
##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/querykit/RestrictedInputNumberDataSource.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.querykit;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+import com.google.common.base.Preconditions;
+import org.apache.druid.java.util.common.IAE;
+import org.apache.druid.query.DataSource;
+import org.apache.druid.query.Query;
+import org.apache.druid.query.planning.DataSourceAnalysis;
+import org.apache.druid.query.policy.Policy;
+import org.apache.druid.segment.RestrictedSegment;
+import org.apache.druid.segment.SegmentReference;
+import org.apache.druid.utils.JvmUtils;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.Function;
+
+/**
+ * Represents an input number, i.e., a positional index into
+ * {@link org.apache.druid.msq.kernel.StageDefinition#getInputSpecs()}, with policy restriction.
+ * <p>
+ * Used by
+ * <ul>
+ * <li>{@link DataSourcePlan}, to note which inputs correspond to which datasources in the query being planned.
+ * <li>{@link BroadcastJoinSegmentMapFnProcessor} to associate broadcast inputs with the correct datasources in a
+ * join tree.
+ */
+@JsonTypeName("restrictedInputNumber")
+public class RestrictedInputNumberDataSource implements DataSource
Review Comment:
should this be `InputNumberRestrictedDataSource` instead?
##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/indexing/MSQWorkerTaskLauncher.java:
##########
@@ -459,13 +459,7 @@ private void runNewTasks()
);
taskTrackers.put(task.getId(), new TaskTracker(i, task));
- workerToTaskIds.compute(i, (workerId, taskIds) -> {
- if (taskIds == null) {
- taskIds = new ArrayList<>();
- }
- taskIds.add(task.getId());
- return taskIds;
- });
+ workerToTaskIds.computeIfAbsent(i, (unused) -> (new ArrayList<>())).add(task.getId());
Review Comment:
this isn't equivalent, previously it would always add the taskId to the worker, now it only adds if the worker isn't there, is that ok?
##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/querykit/BroadcastJoinSegmentMapFnProcessor.java:
##########
@@ -198,6 +198,7 @@ private Function<SegmentReference, SegmentReference> createSegmentMapFunction()
DataSource inlineChannelData(final DataSource originalDataSource)
{
+ // TODO: need to handle RestrictedInputNumberDataSource here
Review Comment:
we typically don't leave TODO comments in the code, either do the thing or leave a bigger comment explaining the problem that needs addressed in the future
##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/querykit/BaseLeafFrameProcessorFactory.java:
##########
@@ -340,14 +333,7 @@ private FrameProcessor<Function<SegmentReference, SegmentReference>> makeSegment
);
if (broadcastInputs.isEmpty()) {
- if (query.getDataSource().getAnalysis().isJoin()) {
- // Joins may require significant computation to compute the segmentMapFn. Offload it to a processor.
- return new SimpleSegmentMapFnProcessor(query);
- } else {
- // Non-joins are expected to have cheap-to-compute segmentMapFn. Do the computation in the factory thread,
- // without offloading to a processor.
- return null;
- }
Review Comment:
why this change? I guess the result is that above we always need a `ChainedProcessorManager`, is that necessary?
##########
processing/src/main/java/org/apache/druid/frame/processor/OutputChannels.java:
##########
@@ -74,6 +75,26 @@ public static OutputChannels wrapReadOnly(final List<OutputChannel> outputChanne
return new OutputChannels(outputChannels.stream().map(OutputChannel::readOnly).collect(Collectors.toList()));
}
+ /**
+ * Verifies there is exactly one channel per partition.
+ */
+ public OutputChannels sanityCheck()
Review Comment:
maybe we should call this `verify()` or `verifySingleChannel()`?
--
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-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org