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


##########
processing/src/main/java/org/apache/druid/query/topn/TopNQuery.java:
##########
@@ -97,9 +99,18 @@
             : postAggregatorSpecs
     );
 
+
+    final long expectedAllocBytes = 
aggregatorSpecs.stream().mapToLong(AggregatorFactory::getMaxIntermediateSizeWithNulls).sum();

Review Comment:
   ## Dereferenced variable may be null
   
   Variable [aggregatorSpecs](1) may be null at this access as suggested by 
[this](2) null guard.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/8446)



##########
processing/src/test/java/org/apache/druid/query/topn/TopNQueryRunnerFailureTest.java:
##########
@@ -0,0 +1,264 @@
+/*
+ * 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.query.topn;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import org.apache.druid.collections.CloseableStupidPool;
+import org.apache.druid.java.util.common.DateTimes;
+import org.apache.druid.java.util.common.guava.Sequence;
+import org.apache.druid.java.util.common.io.Closer;
+import org.apache.druid.query.QueryContexts;
+import org.apache.druid.query.QueryPlus;
+import org.apache.druid.query.QueryRunner;
+import org.apache.druid.query.QueryRunnerTestHelper;
+import org.apache.druid.query.ResourceLimitExceededException;
+import org.apache.druid.query.Result;
+import org.apache.druid.query.TestQueryRunners;
+import org.apache.druid.query.aggregation.AggregatorFactory;
+import org.apache.druid.query.aggregation.DoubleMaxAggregatorFactory;
+import org.apache.druid.query.aggregation.DoubleMinAggregatorFactory;
+import org.apache.druid.query.aggregation.FloatMaxAggregatorFactory;
+import org.apache.druid.query.aggregation.FloatMinAggregatorFactory;
+import 
org.apache.druid.query.aggregation.firstlast.first.DoubleFirstAggregatorFactory;
+import org.apache.druid.query.context.ResponseContext;
+import org.apache.druid.segment.TestHelper;
+import org.apache.druid.testing.InitializedNullHandlingTest;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ */
+@RunWith(Parameterized.class)
+public class TopNQueryRunnerFailureTest extends InitializedNullHandlingTest
+{
+  private static final Closer RESOURCE_CLOSER = Closer.create();
+
+  @AfterClass
+  public static void teardown() throws IOException
+  {
+    RESOURCE_CLOSER.close();
+  }
+
+  @Parameterized.Parameters(name = "{7}")
+  public static Iterable<Object[]> constructorFeeder()
+  {
+    List<QueryRunner<Result<TopNResultValue>>> retVal = queryRunners();
+    List<Object[]> parameters = new ArrayList<>();
+    final int nParam = 7;
+    for (int i = 0; i < 32; i++) {
+      for (QueryRunner<Result<TopNResultValue>> firstParameter : retVal) {
+        Object[] params = new Object[nParam];
+        params[0] = firstParameter;
+        params[1] = (i & 1) != 0;
+        params[2] = (i & 2) != 0;
+        params[3] = (i & 4) != 0;
+        params[4] = (i & 8) != 0;
+        params[5] = QueryRunnerTestHelper.COMMON_DOUBLE_AGGREGATORS;
+        params[6] = firstParameter + " double aggs";
+        Object[] params2 = Arrays.copyOf(params, nParam);
+        params2[5] = QueryRunnerTestHelper.COMMON_FLOAT_AGGREGATORS;
+        params2[6] = firstParameter + " float aggs";
+        parameters.add(params);
+        parameters.add(params2);
+      }
+    }
+    return parameters;
+  }
+
+  public static List<QueryRunner<Result<TopNResultValue>>> queryRunners()
+  {
+    final CloseableStupidPool<ByteBuffer> defaultPool = 
TestQueryRunners.createDefaultNonBlockingPool();
+    final CloseableStupidPool<ByteBuffer> customPool = new 
CloseableStupidPool<>(
+        "TopNQueryRunnerFactory-bufferPool",
+        () -> ByteBuffer.allocate(20000)
+    );
+
+    List<QueryRunner<Result<TopNResultValue>>> retVal = new ArrayList<>();
+    retVal.addAll(
+        QueryRunnerTestHelper.makeQueryRunnersToMerge(
+            new TopNQueryRunnerFactory(
+                defaultPool,
+                new TopNQueryQueryToolChest(new TopNQueryConfig()),
+                QueryRunnerTestHelper.NOOP_QUERYWATCHER
+            ),
+            false
+        )
+    );
+    retVal.addAll(
+        QueryRunnerTestHelper.makeQueryRunnersToMerge(
+            new TopNQueryRunnerFactory(
+                customPool,
+                new TopNQueryQueryToolChest(new TopNQueryConfig()),
+                QueryRunnerTestHelper.NOOP_QUERYWATCHER
+            ),
+            false
+        )
+    );
+
+    RESOURCE_CLOSER.register(() -> {
+      // Verify that all objects have been returned to the pool.
+      Assert.assertEquals("defaultPool objects created", 
defaultPool.poolSize(), defaultPool.objectsCreatedCount());
+      Assert.assertEquals("customPool objects created", customPool.poolSize(), 
customPool.objectsCreatedCount());
+      defaultPool.close();
+      customPool.close();
+    });
+
+    return retVal;
+  }
+
+  private final QueryRunner<Result<TopNResultValue>> runner;
+  private final List<AggregatorFactory> commonAggregators;
+
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();

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



##########
processing/src/test/java/org/apache/druid/query/topn/TopNQueryRunnerFailureTest.java:
##########
@@ -0,0 +1,264 @@
+/*
+ * 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.query.topn;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import org.apache.druid.collections.CloseableStupidPool;
+import org.apache.druid.java.util.common.DateTimes;
+import org.apache.druid.java.util.common.guava.Sequence;
+import org.apache.druid.java.util.common.io.Closer;
+import org.apache.druid.query.QueryContexts;
+import org.apache.druid.query.QueryPlus;
+import org.apache.druid.query.QueryRunner;
+import org.apache.druid.query.QueryRunnerTestHelper;
+import org.apache.druid.query.ResourceLimitExceededException;
+import org.apache.druid.query.Result;
+import org.apache.druid.query.TestQueryRunners;
+import org.apache.druid.query.aggregation.AggregatorFactory;
+import org.apache.druid.query.aggregation.DoubleMaxAggregatorFactory;
+import org.apache.druid.query.aggregation.DoubleMinAggregatorFactory;
+import org.apache.druid.query.aggregation.FloatMaxAggregatorFactory;
+import org.apache.druid.query.aggregation.FloatMinAggregatorFactory;
+import 
org.apache.druid.query.aggregation.firstlast.first.DoubleFirstAggregatorFactory;
+import org.apache.druid.query.context.ResponseContext;
+import org.apache.druid.segment.TestHelper;
+import org.apache.druid.testing.InitializedNullHandlingTest;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ */
+@RunWith(Parameterized.class)
+public class TopNQueryRunnerFailureTest extends InitializedNullHandlingTest
+{
+  private static final Closer RESOURCE_CLOSER = Closer.create();
+
+  @AfterClass
+  public static void teardown() throws IOException
+  {
+    RESOURCE_CLOSER.close();
+  }
+
+  @Parameterized.Parameters(name = "{7}")
+  public static Iterable<Object[]> constructorFeeder()
+  {
+    List<QueryRunner<Result<TopNResultValue>>> retVal = queryRunners();
+    List<Object[]> parameters = new ArrayList<>();
+    final int nParam = 7;
+    for (int i = 0; i < 32; i++) {
+      for (QueryRunner<Result<TopNResultValue>> firstParameter : retVal) {
+        Object[] params = new Object[nParam];
+        params[0] = firstParameter;
+        params[1] = (i & 1) != 0;
+        params[2] = (i & 2) != 0;
+        params[3] = (i & 4) != 0;
+        params[4] = (i & 8) != 0;
+        params[5] = QueryRunnerTestHelper.COMMON_DOUBLE_AGGREGATORS;
+        params[6] = firstParameter + " double aggs";
+        Object[] params2 = Arrays.copyOf(params, nParam);
+        params2[5] = QueryRunnerTestHelper.COMMON_FLOAT_AGGREGATORS;
+        params2[6] = firstParameter + " float aggs";
+        parameters.add(params);
+        parameters.add(params2);
+      }
+    }
+    return parameters;
+  }
+
+  public static List<QueryRunner<Result<TopNResultValue>>> queryRunners()
+  {
+    final CloseableStupidPool<ByteBuffer> defaultPool = 
TestQueryRunners.createDefaultNonBlockingPool();
+    final CloseableStupidPool<ByteBuffer> customPool = new 
CloseableStupidPool<>(
+        "TopNQueryRunnerFactory-bufferPool",
+        () -> ByteBuffer.allocate(20000)
+    );
+
+    List<QueryRunner<Result<TopNResultValue>>> retVal = new ArrayList<>();
+    retVal.addAll(
+        QueryRunnerTestHelper.makeQueryRunnersToMerge(
+            new TopNQueryRunnerFactory(
+                defaultPool,
+                new TopNQueryQueryToolChest(new TopNQueryConfig()),
+                QueryRunnerTestHelper.NOOP_QUERYWATCHER
+            ),
+            false
+        )
+    );
+    retVal.addAll(
+        QueryRunnerTestHelper.makeQueryRunnersToMerge(
+            new TopNQueryRunnerFactory(
+                customPool,
+                new TopNQueryQueryToolChest(new TopNQueryConfig()),
+                QueryRunnerTestHelper.NOOP_QUERYWATCHER
+            ),
+            false
+        )
+    );
+
+    RESOURCE_CLOSER.register(() -> {
+      // Verify that all objects have been returned to the pool.
+      Assert.assertEquals("defaultPool objects created", 
defaultPool.poolSize(), defaultPool.objectsCreatedCount());
+      Assert.assertEquals("customPool objects created", customPool.poolSize(), 
customPool.objectsCreatedCount());
+      defaultPool.close();
+      customPool.close();
+    });
+
+    return retVal;
+  }
+
+  private final QueryRunner<Result<TopNResultValue>> runner;
+  private final List<AggregatorFactory> commonAggregators;
+
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  @SuppressWarnings("unused")
+  public TopNQueryRunnerFailureTest(
+      QueryRunner<Result<TopNResultValue>> runner,
+      boolean specializeGeneric1AggPooledTopN,
+      boolean specializeGeneric2AggPooledTopN,
+      boolean specializeHistorical1SimpleDoubleAggPooledTopN,
+      boolean 
specializeHistoricalSingleValueDimSelector1SimpleDoubleAggPooledTopN,
+      List<AggregatorFactory> commonAggregators,
+      String testName

Review Comment:
   ## Useless parameter
   
   The parameter 'testName' is never used.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/8448)



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