cryptoe commented on code in PR #16291:
URL: https://github.com/apache/druid/pull/16291#discussion_r1606285611


##########
server/src/main/java/org/apache/druid/server/coordinator/UserCompactionStrategy.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.server.coordinator;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.druid.indexer.CompactionEngine;
+
+import java.util.Objects;
+
+
+public class UserCompactionStrategy

Review Comment:
   This class is creating confusion. From the name it seems like it should 
implement compactionStrategy but it seems its a placeholder for serde stuff. 
Javadocs and name changes would be helpful. 



##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/exec/ControllerImpl.java:
##########
@@ -1853,25 +1864,42 @@ private static Function<Set<DataSegment>, 
Set<DataSegment>> addCompactionStateTo
 
     GranularitySpec granularitySpec = new UniformGranularitySpec(
         segmentGranularity,
-        dataSchema.getGranularitySpec().getQueryGranularity(),
+        
QueryContext.of(task.getContext()).getGranularity(DruidSqlInsert.SQL_INSERT_QUERY_GRANULARITY,
 jsonMapper),
         dataSchema.getGranularitySpec().isRollup(),
-        dataSchema.getGranularitySpec().inputIntervals()
+        ((DataSourceMSQDestination) 
task.getQuerySpec().getDestination()).getReplaceTimeChunks()
     );
 
-    DimensionsSpec dimensionsSpec = dataSchema.getDimensionsSpec();
     Map<String, Object> transformSpec = 
TransformSpec.NONE.equals(dataSchema.getTransformSpec())
                                         ? null
                                         : new 
ClientCompactionTaskTransformSpec(
                                             
dataSchema.getTransformSpec().getFilter()
                                         ).asMap(jsonMapper);
-    List<Object> metricsSpec = dataSchema.getAggregators() == null
-                               ? null
-                               : jsonMapper.convertValue(
-                                   dataSchema.getAggregators(), new 
TypeReference<List<Object>>()
-                                   {
-                                   });
 
 
+    DimensionsSpec dimensionsSpec;
+    List<Object> metricsSpec;
+
+    if (task.getQuerySpec().getQuery() instanceof GroupByQuery) {

Review Comment:
   
   If finalize is true we should create all dimension no ?



##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/exec/ControllerImpl.java:
##########
@@ -1768,6 +1769,16 @@ private void handleQueryResults(
                                                  );
 
       if (!segments.isEmpty() && storeCompactionState) {
+        if (!(task.getQuerySpec().getDestination() instanceof 
DataSourceMSQDestination)) {

Review Comment:
   This validation should be done in makeQueryDefinition and should be a 
warning imho. 



##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/exec/ControllerImpl.java:
##########
@@ -1853,25 +1864,42 @@ private static Function<Set<DataSegment>, 
Set<DataSegment>> addCompactionStateTo
 
     GranularitySpec granularitySpec = new UniformGranularitySpec(
         segmentGranularity,
-        dataSchema.getGranularitySpec().getQueryGranularity(),
+        
QueryContext.of(task.getContext()).getGranularity(DruidSqlInsert.SQL_INSERT_QUERY_GRANULARITY,
 jsonMapper),
         dataSchema.getGranularitySpec().isRollup(),
-        dataSchema.getGranularitySpec().inputIntervals()
+        ((DataSourceMSQDestination) 
task.getQuerySpec().getDestination()).getReplaceTimeChunks()
     );
 
-    DimensionsSpec dimensionsSpec = dataSchema.getDimensionsSpec();
     Map<String, Object> transformSpec = 
TransformSpec.NONE.equals(dataSchema.getTransformSpec())
                                         ? null
                                         : new 
ClientCompactionTaskTransformSpec(
                                             
dataSchema.getTransformSpec().getFilter()
                                         ).asMap(jsonMapper);
-    List<Object> metricsSpec = dataSchema.getAggregators() == null
-                               ? null
-                               : jsonMapper.convertValue(
-                                   dataSchema.getAggregators(), new 
TypeReference<List<Object>>()
-                                   {
-                                   });
 
 
+    DimensionsSpec dimensionsSpec;
+    List<Object> metricsSpec;
+
+    if (task.getQuerySpec().getQuery() instanceof GroupByQuery) {

Review Comment:
   I feel the dataSchema should own this logic and I feel the current logic is 
current. IF we want to make changes to how the compaction state comparison 
works, that can be a follow up pr and we can document it in known issues. 



##########
indexing-service/src/main/java/org/apache/druid/indexing/common/task/CompactionStrategy.java:
##########
@@ -0,0 +1,58 @@
+/*
+ * 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 com.fasterxml.jackson.core.JsonProcessingException;
+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.segment.indexing.DataSchema;
+import org.joda.time.Interval;
+
+import java.util.List;
+
+/**
+ * Strategy to be used for executing a compaction task.
+ * Should be synchronized with {@link 
org.apache.druid.server.coordinator.UserCompactionStrategy}
+ */
+@JsonTypeInfo(
+    use = JsonTypeInfo.Id.NAME,
+    include = JsonTypeInfo.As.EXISTING_PROPERTY,
+    property = CompactionStrategy.TYPE_PROPERTY,
+    visible = true)
+@JsonSubTypes(value = {
+    @JsonSubTypes.Type(name = NativeCompactionStrategy.TYPE, value = 
NativeCompactionStrategy.class)
+})
+public interface CompactionStrategy
+{
+  String TYPE_PROPERTY = "TYPE";
+
+  TaskStatus runCompactionTasks(
+      CompactionTask compactionTask,
+      TaskToolbox taskToolbox,
+      List<NonnullPair<Interval, DataSchema>> dataSchemas
+  ) throws JsonProcessingException;
+
+  CurrentSubTaskHolder getCurrentSubTaskHolder();

Review Comment:
   This interface should also have a supportsCompactionSpec() method which will 
tell the run task method can it run the compaction spec using this strategy or 
not. 
   This will be helpful once we fallback to native in case msq is set to 
default as a cluster level engine. 
   If we donot have it, MSQ engine would have to support 100% feature coverage 
of native compaction spec, else users jobs will fail. 



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