LakshSingla commented on code in PR #16291: URL: https://github.com/apache/druid/pull/16291#discussion_r1618197497
########## indexing-service/src/main/java/org/apache/druid/indexing/common/task/CompactionRunner.java: ########## @@ -0,0 +1,62 @@ +/* + * 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.indexing.common.task; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import org.apache.druid.indexer.TaskStatus; +import org.apache.druid.indexing.common.TaskToolbox; +import org.apache.druid.java.util.common.NonnullPair; +import org.apache.druid.java.util.common.Pair; +import org.apache.druid.segment.indexing.DataSchema; +import org.apache.druid.server.coordinator.ClientCompactionRunnerInfo; +import org.joda.time.Interval; + +import java.util.List; + +/** + * Strategy to be used for executing a compaction task. + * Should be synchronized with {@link ClientCompactionRunnerInfo} + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = CompactionRunner.TYPE_PROPERTY) +@JsonSubTypes(value = { + @JsonSubTypes.Type(name = "NATIVE", value = NativeCompactionRunner.class) Review Comment: stylistic comment: This field is mostly in camelcase, instead of all caps. ```suggestion @JsonSubTypes.Type(name = "native", value = NativeCompactionRunner.class) ``` ########## extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/exec/ControllerImpl.java: ########## @@ -1513,7 +1516,7 @@ private void handleQueryResults( if (!destination.isReplaceTimeChunks()) { // Store compaction state only for replace queries. log.warn( - "storeCompactionState flag set for a non-REPLACE query [%s]. Ignoring the flag for now.", + "storeCompactionState flag set for a non-REPLACE query[%s]. Ignoring the flag for now.", Review Comment: ```suggestion "Ignoring storeCompactionState flag since it is set for a non-REPLACE query[%s].", ``` ########## extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/indexing/MSQCompactionRunner.java: ########## @@ -0,0 +1,508 @@ +/* + * 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; + +import com.fasterxml.jackson.annotation.JacksonInject; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.ImmutableList; +import com.google.inject.Injector; +import org.apache.druid.data.input.impl.DimensionSchema; +import org.apache.druid.error.InvalidInput; +import org.apache.druid.indexer.TaskStatus; +import org.apache.druid.indexer.partitions.DimensionRangePartitionsSpec; +import org.apache.druid.indexer.partitions.DynamicPartitionsSpec; +import org.apache.druid.indexer.partitions.PartitionsSpec; +import org.apache.druid.indexer.partitions.SecondaryPartitionType; +import org.apache.druid.indexing.common.TaskToolbox; +import org.apache.druid.indexing.common.task.CompactionRunner; +import org.apache.druid.indexing.common.task.CompactionTask; +import org.apache.druid.indexing.common.task.CurrentSubTaskHolder; +import org.apache.druid.java.util.common.NonnullPair; +import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.java.util.common.granularity.AllGranularity; +import org.apache.druid.java.util.common.granularity.Granularities; +import org.apache.druid.java.util.common.granularity.Granularity; +import org.apache.druid.java.util.common.granularity.PeriodGranularity; +import org.apache.druid.java.util.common.logger.Logger; +import org.apache.druid.math.expr.ExprMacroTable; +import org.apache.druid.msq.indexing.destination.DataSourceMSQDestination; +import org.apache.druid.msq.kernel.WorkerAssignmentStrategy; +import org.apache.druid.msq.util.MultiStageQueryContext; +import org.apache.druid.query.Druids; +import org.apache.druid.query.Query; +import org.apache.druid.query.QueryContext; +import org.apache.druid.query.TableDataSource; +import org.apache.druid.query.dimension.DefaultDimensionSpec; +import org.apache.druid.query.dimension.DimensionSpec; +import org.apache.druid.query.expression.TimestampFloorExprMacro; +import org.apache.druid.query.filter.DimFilter; +import org.apache.druid.query.groupby.GroupByQuery; +import org.apache.druid.query.groupby.orderby.OrderByColumnSpec; +import org.apache.druid.query.spec.MultipleIntervalSegmentSpec; +import org.apache.druid.segment.VirtualColumn; +import org.apache.druid.segment.VirtualColumns; +import org.apache.druid.segment.column.ColumnHolder; +import org.apache.druid.segment.column.ColumnType; +import org.apache.druid.segment.column.RowSignature; +import org.apache.druid.segment.indexing.DataSchema; +import org.apache.druid.segment.virtual.ExpressionVirtualColumn; +import org.apache.druid.sql.calcite.parser.DruidSqlInsert; +import org.apache.druid.sql.calcite.planner.ColumnMapping; +import org.apache.druid.sql.calcite.planner.ColumnMappings; +import org.joda.time.Interval; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +public class MSQCompactionRunner implements CompactionRunner +{ + private static final Logger log = new Logger(MSQCompactionRunner.class); + private static final Granularity DEFAULT_SEGMENT_GRANULARITY = Granularities.ALL; + + private final ObjectMapper jsonMapper; + private final Injector injector; + + public static final String TIME_VIRTUAL_COLUMN = "__vTime"; + public static final String TIME_COLUMN = ColumnHolder.TIME_COLUMN_NAME; + + @JsonIgnore + private final CurrentSubTaskHolder currentSubTaskHolder = new CurrentSubTaskHolder( + (taskObject, config) -> { + final MSQControllerTask msqControllerTask = (MSQControllerTask) taskObject; + msqControllerTask.stopGracefully(config); + }); + + + public MSQCompactionRunner(@JacksonInject ObjectMapper jsonMapper, @JacksonInject Injector injector) + { + this.jsonMapper = jsonMapper; + this.injector = injector; + } + + @Override + public NonnullPair<Boolean, String> supportsCompactionSpec( + CompactionTask compactionTask + ) + { + if (compactionTask.getTuningConfig() != null) { + PartitionsSpec partitionsSpec = compactionTask.getTuningConfig().getPartitionsSpec(); + if (!(partitionsSpec instanceof DynamicPartitionsSpec + || partitionsSpec instanceof DimensionRangePartitionsSpec)) { + return new NonnullPair<>(false, StringUtils.format( + "Invalid partition spec type[%s] for MSQ compaction engine." + + " Type must be either DynamicPartitionsSpec or DynamicRangePartitionsSpec.", + partitionsSpec.getClass() + )); + } + if (partitionsSpec instanceof DynamicPartitionsSpec + && ((DynamicPartitionsSpec) partitionsSpec).getMaxTotalRows() != null) { + return new NonnullPair<>(false, StringUtils.format( + "maxTotalRows[%d] in DynamicPartitionsSpec not supported for MSQ compaction engine.", + ((DynamicPartitionsSpec) partitionsSpec).getMaxTotalRows() + )); + } + } + if (compactionTask.getMetricsSpec() != null + && compactionTask.getGranularitySpec() != null + && !compactionTask.getGranularitySpec() + .isRollup()) { + return new NonnullPair<>( + false, + "rollup in granularitySpec must be set to True if metricsSpec is specifed " + + "for MSQ compaction engine." + ); Review Comment: ```suggestion return new NonnullPair<>( false, "rollup in granularitySpec must be set to true if metricsSpec is specifed " + "for MSQ compaction engine." ); ``` I thought that finalizeAggregations = true, corresponds to rollup = false. Is that not the case? ########## processing/src/main/java/org/apache/druid/indexer/CompactionEngine.java: ########## @@ -0,0 +1,39 @@ +/* + * 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.indexer; + +import com.fasterxml.jackson.annotation.JsonCreator; +import org.apache.druid.java.util.common.StringUtils; + +/** + * Encapsulates the Engine to be used for a compaction task. + * Should be kept in sync with the subtypes for {@link org.apache.druid.indexing.common.task.CompactionRunner}. + */ +public enum CompactionEngine +{ + NATIVE, + MSQ; + + @JsonCreator + public static CompactionEngine fromString(String name) Review Comment: Please annotate with `@Nullable` ```suggestion @Nullable @JsonCreator public static CompactionEngine fromString(@Nullable String name) ``` ########## extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/indexing/processor/SegmentGeneratorFrameProcessorFactory.java: ########## @@ -113,6 +119,12 @@ public MSQTuningConfig getTuningConfig() return tuningConfig; } + @JsonProperty + public Map<String, AggregatorFactory> getDimensionToAggregatorFactoryMap() + { + return dimensionToAggregatorFactoryMap; + } Review Comment: Is this a backward-compatible change? What happens if the controller is on an older version while the workers are on a newer version? -- 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]
