github-advanced-security[bot] commented on code in PR #17895:
URL: https://github.com/apache/druid/pull/17895#discussion_r2069317317


##########
extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/indexing/MSQSpecCompatTest.java:
##########
@@ -0,0 +1,211 @@
+/*
+ * 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.databind.ObjectMapper;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import org.apache.druid.java.util.common.Intervals;
+import org.apache.druid.java.util.common.granularity.Granularities;
+import org.apache.druid.java.util.common.granularity.Granularity;
+import org.apache.druid.msq.indexing.destination.DataSourceMSQDestination;
+import org.apache.druid.msq.indexing.destination.DurableStorageMSQDestination;
+import org.apache.druid.msq.indexing.destination.TaskReportMSQDestination;
+import org.apache.druid.msq.kernel.WorkerAssignmentStrategy;
+import org.apache.druid.query.Druids;
+import org.apache.druid.query.InlineDataSource;
+import org.apache.druid.query.aggregation.CountAggregatorFactory;
+import org.apache.druid.query.dimension.DefaultDimensionSpec;
+import org.apache.druid.query.filter.NotDimFilter;
+import org.apache.druid.query.filter.NullFilter;
+import org.apache.druid.query.groupby.GroupByQuery;
+import org.apache.druid.query.groupby.orderby.DefaultLimitSpec;
+import org.apache.druid.query.groupby.orderby.OrderByColumnSpec;
+import org.apache.druid.query.spec.MultipleIntervalSegmentSpec;
+import org.apache.druid.query.spec.QuerySegmentSpec;
+import org.apache.druid.quidem.ProjectPathUtils;
+import org.apache.druid.segment.column.ColumnType;
+import org.apache.druid.segment.column.RowSignature;
+import org.apache.druid.sql.calcite.planner.ColumnMapping;
+import org.apache.druid.sql.calcite.planner.ColumnMappings;
+import org.apache.druid.sql.calcite.util.CalciteTests;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class MSQSpecCompatTest
+{
+  private static final ObjectMapper JSON_MAPPER = CalciteTests.getJsonMapper();
+  private static final boolean OVERWRITE = false;
+
+  @Test
+  public void testBuilder1(TestInfo info) throws Exception
+  {
+    RowSignature resultSignature = RowSignature.builder()
+        .add("EXPR$0", ColumnType.LONG)
+        .build();
+
+    Map<String, Object> context = ImmutableMap.<String, Object>builder()
+        .put("someThing", 111)
+        .put("sqlInsertSegmentGranularity", "\"DAY\"")
+        .build();
+    MSQSpec msqSpec = LegacyMSQSpec.builder()
+        .query(
+            Druids.newScanQueryBuilder()
+                .dataSource(
+                    InlineDataSource.fromIterable(
+                        ImmutableList.of(new Object[] {2}),
+                        resultSignature
+                    )
+                )
+                .intervals(QuerySegmentSpec.ETERNITY)
+                .columns("EXPR$0")
+                .columnTypes(ColumnType.LONG)
+                .context(context)
+                .build()
+        )

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [Builder.query](1) should be avoided because it has been deprecated.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/9154)



##########
extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/indexing/MSQSpecCompatTest.java:
##########
@@ -0,0 +1,211 @@
+/*
+ * 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.databind.ObjectMapper;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import org.apache.druid.java.util.common.Intervals;
+import org.apache.druid.java.util.common.granularity.Granularities;
+import org.apache.druid.java.util.common.granularity.Granularity;
+import org.apache.druid.msq.indexing.destination.DataSourceMSQDestination;
+import org.apache.druid.msq.indexing.destination.DurableStorageMSQDestination;
+import org.apache.druid.msq.indexing.destination.TaskReportMSQDestination;
+import org.apache.druid.msq.kernel.WorkerAssignmentStrategy;
+import org.apache.druid.query.Druids;
+import org.apache.druid.query.InlineDataSource;
+import org.apache.druid.query.aggregation.CountAggregatorFactory;
+import org.apache.druid.query.dimension.DefaultDimensionSpec;
+import org.apache.druid.query.filter.NotDimFilter;
+import org.apache.druid.query.filter.NullFilter;
+import org.apache.druid.query.groupby.GroupByQuery;
+import org.apache.druid.query.groupby.orderby.DefaultLimitSpec;
+import org.apache.druid.query.groupby.orderby.OrderByColumnSpec;
+import org.apache.druid.query.spec.MultipleIntervalSegmentSpec;
+import org.apache.druid.query.spec.QuerySegmentSpec;
+import org.apache.druid.quidem.ProjectPathUtils;
+import org.apache.druid.segment.column.ColumnType;
+import org.apache.druid.segment.column.RowSignature;
+import org.apache.druid.sql.calcite.planner.ColumnMapping;
+import org.apache.druid.sql.calcite.planner.ColumnMappings;
+import org.apache.druid.sql.calcite.util.CalciteTests;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class MSQSpecCompatTest
+{
+  private static final ObjectMapper JSON_MAPPER = CalciteTests.getJsonMapper();
+  private static final boolean OVERWRITE = false;
+
+  @Test
+  public void testBuilder1(TestInfo info) throws Exception
+  {
+    RowSignature resultSignature = RowSignature.builder()
+        .add("EXPR$0", ColumnType.LONG)
+        .build();
+
+    Map<String, Object> context = ImmutableMap.<String, Object>builder()
+        .put("someThing", 111)
+        .put("sqlInsertSegmentGranularity", "\"DAY\"")
+        .build();
+    MSQSpec msqSpec = LegacyMSQSpec.builder()
+        .query(
+            Druids.newScanQueryBuilder()
+                .dataSource(
+                    InlineDataSource.fromIterable(
+                        ImmutableList.of(new Object[] {2}),
+                        resultSignature
+                    )
+                )
+                .intervals(QuerySegmentSpec.ETERNITY)
+                .columns("EXPR$0")
+                .columnTypes(ColumnType.LONG)
+                .context(context)
+                .build()
+        )
+        .assignmentStrategy(WorkerAssignmentStrategy.AUTO)
+        .columnMappings(ColumnMappings.identity(resultSignature))
+        .tuningConfig(new MSQTuningConfig(1, 2, 3, 4, null))
+        .destination(TaskReportMSQDestination.INSTANCE)
+        .build();
+    validateMSQSpecCompat(info, msqSpec, LegacyMSQSpec.class);
+  }
+
+  @Test
+  public void testBuilder2(TestInfo info) throws Exception
+  {
+    RowSignature resultSignature = RowSignature.builder()
+        .add("EXPR$0", ColumnType.LONG)
+        .build();
+    Map<String, Object> context = ImmutableMap.<String, Object>builder()
+        .put("someThing", 222)
+        .put("sqlInsertSegmentGranularity", "\"DAY\"")
+        .build();
+    MSQSpec msqSpec = LegacyMSQSpec.builder()
+        .query(
+            Druids.newScanQueryBuilder()
+                .dataSource(
+                    InlineDataSource.fromIterable(
+                        ImmutableList.of(new Object[] {2}),
+                        resultSignature
+                    )
+                )
+                .intervals(QuerySegmentSpec.ETERNITY)
+                .columns("EXPR$0")
+                .columnTypes(ColumnType.LONG)
+                .context(context)
+                .build()
+        )

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [Builder.query](1) should be avoided because it has been deprecated.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/9155)



##########
extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/sql/resources/SqlStatementResourceTest.java:
##########
@@ -141,8 +142,8 @@
~
 
   private static final MSQControllerTask MSQ_CONTROLLER_SELECT_PAYLOAD = new 
MSQControllerTask(
       ACCEPTED_SELECT_MSQ_QUERY,
-      MSQSpec.builder()
+      LegacyMSQSpec.builder()

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [Builder.query](1) should be avoided because it has been deprecated.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/8903)



##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/sql/MSQTaskQueryMaker.java:
##########
@@ -236,17 +244,22 @@
 
     // This flag is to ensure backward compatibility, as brokers are upgraded 
after indexers/middlemanagers.
     
nativeQueryContextOverrides.put(MultiStageQueryContext.WINDOW_FUNCTION_OPERATOR_TRANSFORMATION,
 true);
+    boolean isReindex = 
MSQControllerTask.isReplaceInputDataSourceTask(druidQuery.getQuery(), 
destination);
+    if (isReindex) {
+      nativeQueryContextOverrides.put(MultiStageQueryContext.CTX_IS_REINDEX, 
isReindex);
+    }
 
-    final MSQSpec querySpec =
-        MSQSpec.builder()
-               
.query(druidQuery.getQuery().withOverriddenContext(nativeQueryContextOverrides))
+    final LegacyMSQSpec querySpec =
+        LegacyMSQSpec.builder()
+               .query(druidQuery.getQuery())

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [Builder.query](1) should be avoided because it has been deprecated.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/9153)



##########
extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/sql/resources/SqlStatementResourceTest.java:
##########
@@ -181,8 +182,8 @@
~  );
 
   private static final MSQControllerTask MSQ_CONTROLLER_INSERT_PAYLOAD = new 
MSQControllerTask(
       ACCEPTED_SELECT_MSQ_QUERY,
-      MSQSpec.builder()
+      LegacyMSQSpec.builder()

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [Builder.query](1) should be avoided because it has been deprecated.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/8904)



##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/indexing/QueryDefMSQSpec.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.druid.msq.indexing.destination.MSQDestination;
+import org.apache.druid.msq.indexing.destination.TaskReportMSQDestination;
+import org.apache.druid.msq.kernel.QueryDefinition;
+import org.apache.druid.msq.kernel.WorkerAssignmentStrategy;
+import org.apache.druid.query.BaseQuery;
+import org.apache.druid.query.QueryContext;
+import org.apache.druid.sql.calcite.planner.ColumnMappings;
+
+import java.util.Map;
+import java.util.Objects;
+
+public class QueryDefMSQSpec extends MSQSpec
+{
+
+  protected final QueryDefinition queryDef;
+
+  // jackson defaults
+  public QueryDefMSQSpec()
+  {
+    super();
+    queryDef = null;
+  }
+
+  @JsonCreator
+  public QueryDefMSQSpec(
+      @JsonProperty("queryDef") QueryDefinition queryDef,
+      @JsonProperty("columnMappings") ColumnMappings columnMappings,
+      @JsonProperty("destination") MSQDestination destination,
+      @JsonProperty("assignmentStrategy") WorkerAssignmentStrategy 
assignmentStrategy,
+      @JsonProperty("tuningConfig") MSQTuningConfig tuningConfig)
+  {
+    super(columnMappings, destination, assignmentStrategy, tuningConfig);
+    this.queryDef = queryDef;
+  }
+
+  @JsonProperty("queryDef")
+  @JsonInclude(value = Include.NON_NULL)
+  public QueryDefinition getQueryDef()
+  {
+    return queryDef;
+  }
+
+  @Override
+  public String getId()
+  {
+    return getContext().getString(BaseQuery.QUERY_ID);
+  }
+
+  private boolean isLegacyMode()
+  {
+    return queryDef == null;
+  }
+
+  public QueryDefMSQSpec withOverriddenContext(Map<String, Object> 
contextOverride)
+  {
+    throw new UnsupportedOperationException("Not implemented");
+  }
+
+  @Override
+  public boolean equals(Object o)
+  {
+    if (!super.equals(o)) {
+      return false;
+    }
+    QueryDefMSQSpec that = (QueryDefMSQSpec) o;

Review Comment:
   ## Unread local variable
   
   Variable 'QueryDefMSQSpec that' is never read.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/9156)



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