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


##########
processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryMetricsTest.java:
##########
@@ -0,0 +1,567 @@
+/*
+ * 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.groupby;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+import org.apache.druid.common.config.NullHandling;
+import org.apache.druid.data.input.Rows;
+import org.apache.druid.java.util.common.HumanReadableBytes;
+import org.apache.druid.java.util.common.ISE;
+import org.apache.druid.java.util.common.Intervals;
+import org.apache.druid.java.util.common.Pair;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.concurrent.Execs;
+import org.apache.druid.java.util.common.granularity.Granularities;
+import org.apache.druid.java.util.common.guava.MergeSequence;
+import org.apache.druid.java.util.common.guava.Sequence;
+import org.apache.druid.java.util.common.guava.Sequences;
+import org.apache.druid.query.DruidProcessingConfig;
+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.TestQueryRunner;
+import org.apache.druid.query.aggregation.DoubleMaxAggregatorFactory;
+import org.apache.druid.query.aggregation.LongSumAggregatorFactory;
+import 
org.apache.druid.query.aggregation.firstlast.first.LongFirstAggregatorFactory;
+import 
org.apache.druid.query.aggregation.firstlast.last.LongLastAggregatorFactory;
+import org.apache.druid.query.aggregation.post.ArithmeticPostAggregator;
+import org.apache.druid.query.aggregation.post.ConstantPostAggregator;
+import org.apache.druid.query.aggregation.post.FieldAccessPostAggregator;
+import org.apache.druid.query.context.ResponseContext;
+import org.apache.druid.query.dimension.DefaultDimensionSpec;
+import org.apache.druid.query.expression.TestExprMacroTable;
+import org.apache.druid.query.filter.OrDimFilter;
+import org.apache.druid.query.filter.SelectorDimFilter;
+import org.apache.druid.query.groupby.having.HavingSpec;
+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.segment.TestHelper;
+import org.apache.druid.segment.column.ColumnType;
+import org.apache.druid.segment.virtual.ExpressionVirtualColumn;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+@RunWith(Parameterized.class)
+public class GroupByQueryMetricsTest
+{
+  public static final ObjectMapper DEFAULT_MAPPER = 
TestHelper.makeSmileMapper();
+
+  private static TestGroupByBuffers BUFFER_POOLS = null;
+
+  private final QueryRunner<ResultRow> runner;
+  private final TestQueryRunner<ResultRow> originalRunner;
+  private final GroupByQueryRunnerFactory factory;
+  private final GroupByQueryConfig config;
+  private final GroupByStatsProvider groupByStatsProvider;
+  private final boolean vectorize;
+
+  public static GroupByQueryConfig testConfig()
+  {
+    return new GroupByQueryConfig()
+    {
+      @Override
+      public int getBufferGrouperMaxSize()
+      {
+        return 2;
+      }
+
+      @Override
+      public HumanReadableBytes getMaxOnDiskStorage()
+      {
+        return HumanReadableBytes.valueOf(10L * 1024 * 1024);
+      }
+
+      @Override
+      public String toString()
+      {
+        return "v2SmallBuffer";
+      }
+    };
+  }
+
+  public static GroupByQueryRunnerFactory makeQueryRunnerFactory(
+      final ObjectMapper mapper,
+      final GroupByQueryConfig config,
+      final TestGroupByBuffers bufferPools,
+      final DruidProcessingConfig processingConfig,
+      final GroupByStatsProvider statsProvider
+  )
+  {
+    if (bufferPools.getBufferSize() != 
processingConfig.intermediateComputeSizeBytes()) {
+      throw new ISE(
+          "Provided buffer size [%,d] does not match configured size [%,d]",
+          bufferPools.getBufferSize(),
+          processingConfig.intermediateComputeSizeBytes()
+      );
+    }
+    if (bufferPools.getNumMergeBuffers() != 
processingConfig.getNumMergeBuffers()) {
+      throw new ISE(
+          "Provided merge buffer count [%,d] does not match configured count 
[%,d]",
+          bufferPools.getNumMergeBuffers(),
+          processingConfig.getNumMergeBuffers()
+      );
+    }
+    final Supplier<GroupByQueryConfig> configSupplier = 
Suppliers.ofInstance(config);
+    final GroupByResourcesReservationPool groupByResourcesReservationPool =
+        new GroupByResourcesReservationPool(bufferPools.getMergePool(), 
config, statsProvider);
+    final GroupingEngine groupingEngine = new GroupingEngine(
+        processingConfig,
+        configSupplier,
+        groupByResourcesReservationPool,
+        mapper,
+        mapper,
+        QueryRunnerTestHelper.NOOP_QUERYWATCHER,
+        statsProvider
+    );
+    final GroupByQueryQueryToolChest toolChest = new 
GroupByQueryQueryToolChest(
+        groupingEngine,
+        () -> config,
+        DefaultGroupByQueryMetricsFactory.instance(),
+        groupByResourcesReservationPool,
+        statsProvider
+    );
+    return new GroupByQueryRunnerFactory(groupingEngine, toolChest, 
bufferPools.getProcessingPool());
+  }
+
+  @Parameterized.Parameters(name = "{0}")
+  public static Collection<Object[]> constructorFeeder()
+  {
+    NullHandling.initializeForTests();
+    setUpClass();
+
+    final List<Object[]> constructors = new ArrayList<>();
+    GroupByQueryConfig config = testConfig();
+    GroupByStatsProvider statsProvider = new GroupByStatsProvider();
+    final GroupByQueryRunnerFactory factory = makeQueryRunnerFactory(
+        DEFAULT_MAPPER,
+        config,
+        BUFFER_POOLS,
+        GroupByQueryRunnerTest.DEFAULT_PROCESSING_CONFIG,
+        statsProvider
+    );
+    for (QueryRunner<ResultRow> runner : 
QueryRunnerTestHelper.makeQueryRunners(factory, true)) {
+      for (boolean vectorize : ImmutableList.of(false, true)) {
+        final String testName = StringUtils.format("config=%s, runner=%s, 
vectorize=%s", config, runner, vectorize);
+
+        // Add vectorization tests for any indexes that support it.
+        if (!vectorize || 
(QueryRunnerTestHelper.isTestRunnerVectorizable(runner))) {
+          constructors.add(new Object[]{testName, config, factory, runner, 
statsProvider, vectorize});
+        }
+      }
+    }
+
+    return constructors;
+  }
+
+  @BeforeClass
+  public static void setUpClass()
+  {
+    if (BUFFER_POOLS == null) {
+      BUFFER_POOLS = TestGroupByBuffers.createDefault();
+    }
+  }
+
+  @AfterClass
+  public static void tearDownClass()
+  {
+    BUFFER_POOLS.close();
+    BUFFER_POOLS = null;
+  }
+
+  @SuppressWarnings("unused")
+  public GroupByQueryMetricsTest(
+      String testName,

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



##########
processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryMetricsTest.java:
##########
@@ -0,0 +1,567 @@
+/*
+ * 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.groupby;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+import org.apache.druid.common.config.NullHandling;
+import org.apache.druid.data.input.Rows;
+import org.apache.druid.java.util.common.HumanReadableBytes;
+import org.apache.druid.java.util.common.ISE;
+import org.apache.druid.java.util.common.Intervals;
+import org.apache.druid.java.util.common.Pair;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.concurrent.Execs;
+import org.apache.druid.java.util.common.granularity.Granularities;
+import org.apache.druid.java.util.common.guava.MergeSequence;
+import org.apache.druid.java.util.common.guava.Sequence;
+import org.apache.druid.java.util.common.guava.Sequences;
+import org.apache.druid.query.DruidProcessingConfig;
+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.TestQueryRunner;
+import org.apache.druid.query.aggregation.DoubleMaxAggregatorFactory;
+import org.apache.druid.query.aggregation.LongSumAggregatorFactory;
+import 
org.apache.druid.query.aggregation.firstlast.first.LongFirstAggregatorFactory;
+import 
org.apache.druid.query.aggregation.firstlast.last.LongLastAggregatorFactory;
+import org.apache.druid.query.aggregation.post.ArithmeticPostAggregator;
+import org.apache.druid.query.aggregation.post.ConstantPostAggregator;
+import org.apache.druid.query.aggregation.post.FieldAccessPostAggregator;
+import org.apache.druid.query.context.ResponseContext;
+import org.apache.druid.query.dimension.DefaultDimensionSpec;
+import org.apache.druid.query.expression.TestExprMacroTable;
+import org.apache.druid.query.filter.OrDimFilter;
+import org.apache.druid.query.filter.SelectorDimFilter;
+import org.apache.druid.query.groupby.having.HavingSpec;
+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.segment.TestHelper;
+import org.apache.druid.segment.column.ColumnType;
+import org.apache.druid.segment.virtual.ExpressionVirtualColumn;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+@RunWith(Parameterized.class)
+public class GroupByQueryMetricsTest
+{
+  public static final ObjectMapper DEFAULT_MAPPER = 
TestHelper.makeSmileMapper();
+
+  private static TestGroupByBuffers BUFFER_POOLS = null;
+
+  private final QueryRunner<ResultRow> runner;
+  private final TestQueryRunner<ResultRow> originalRunner;
+  private final GroupByQueryRunnerFactory factory;
+  private final GroupByQueryConfig config;
+  private final GroupByStatsProvider groupByStatsProvider;
+  private final boolean vectorize;
+
+  public static GroupByQueryConfig testConfig()
+  {
+    return new GroupByQueryConfig()
+    {
+      @Override
+      public int getBufferGrouperMaxSize()
+      {
+        return 2;
+      }
+
+      @Override
+      public HumanReadableBytes getMaxOnDiskStorage()
+      {
+        return HumanReadableBytes.valueOf(10L * 1024 * 1024);
+      }
+
+      @Override
+      public String toString()
+      {
+        return "v2SmallBuffer";
+      }
+    };
+  }
+
+  public static GroupByQueryRunnerFactory makeQueryRunnerFactory(
+      final ObjectMapper mapper,
+      final GroupByQueryConfig config,
+      final TestGroupByBuffers bufferPools,
+      final DruidProcessingConfig processingConfig,
+      final GroupByStatsProvider statsProvider
+  )
+  {
+    if (bufferPools.getBufferSize() != 
processingConfig.intermediateComputeSizeBytes()) {
+      throw new ISE(
+          "Provided buffer size [%,d] does not match configured size [%,d]",
+          bufferPools.getBufferSize(),
+          processingConfig.intermediateComputeSizeBytes()
+      );
+    }
+    if (bufferPools.getNumMergeBuffers() != 
processingConfig.getNumMergeBuffers()) {
+      throw new ISE(
+          "Provided merge buffer count [%,d] does not match configured count 
[%,d]",
+          bufferPools.getNumMergeBuffers(),
+          processingConfig.getNumMergeBuffers()
+      );
+    }
+    final Supplier<GroupByQueryConfig> configSupplier = 
Suppliers.ofInstance(config);
+    final GroupByResourcesReservationPool groupByResourcesReservationPool =
+        new GroupByResourcesReservationPool(bufferPools.getMergePool(), 
config, statsProvider);
+    final GroupingEngine groupingEngine = new GroupingEngine(
+        processingConfig,
+        configSupplier,
+        groupByResourcesReservationPool,
+        mapper,
+        mapper,
+        QueryRunnerTestHelper.NOOP_QUERYWATCHER,
+        statsProvider
+    );
+    final GroupByQueryQueryToolChest toolChest = new 
GroupByQueryQueryToolChest(
+        groupingEngine,
+        () -> config,
+        DefaultGroupByQueryMetricsFactory.instance(),
+        groupByResourcesReservationPool,
+        statsProvider
+    );
+    return new GroupByQueryRunnerFactory(groupingEngine, toolChest, 
bufferPools.getProcessingPool());
+  }
+
+  @Parameterized.Parameters(name = "{0}")
+  public static Collection<Object[]> constructorFeeder()
+  {
+    NullHandling.initializeForTests();
+    setUpClass();
+
+    final List<Object[]> constructors = new ArrayList<>();
+    GroupByQueryConfig config = testConfig();
+    GroupByStatsProvider statsProvider = new GroupByStatsProvider();
+    final GroupByQueryRunnerFactory factory = makeQueryRunnerFactory(
+        DEFAULT_MAPPER,
+        config,
+        BUFFER_POOLS,
+        GroupByQueryRunnerTest.DEFAULT_PROCESSING_CONFIG,
+        statsProvider
+    );
+    for (QueryRunner<ResultRow> runner : 
QueryRunnerTestHelper.makeQueryRunners(factory, true)) {
+      for (boolean vectorize : ImmutableList.of(false, true)) {
+        final String testName = StringUtils.format("config=%s, runner=%s, 
vectorize=%s", config, runner, vectorize);
+
+        // Add vectorization tests for any indexes that support it.
+        if (!vectorize || 
(QueryRunnerTestHelper.isTestRunnerVectorizable(runner))) {
+          constructors.add(new Object[]{testName, config, factory, runner, 
statsProvider, vectorize});
+        }
+      }
+    }
+
+    return constructors;
+  }
+
+  @BeforeClass
+  public static void setUpClass()
+  {
+    if (BUFFER_POOLS == null) {
+      BUFFER_POOLS = TestGroupByBuffers.createDefault();
+    }
+  }
+
+  @AfterClass
+  public static void tearDownClass()
+  {
+    BUFFER_POOLS.close();
+    BUFFER_POOLS = null;
+  }
+
+  @SuppressWarnings("unused")
+  public GroupByQueryMetricsTest(
+      String testName,
+      GroupByQueryConfig config,
+      GroupByQueryRunnerFactory factory,
+      TestQueryRunner runner,
+      GroupByStatsProvider groupByStatsProvider,
+      boolean vectorize
+  )
+  {
+    this.config = config;
+    this.factory = factory;
+    this.runner = factory.mergeRunners(Execs.directExecutor(), 
ImmutableList.of(runner));

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



##########
server/src/test/java/org/apache/druid/server/metrics/GroupByStatsMonitorTest.java:
##########
@@ -0,0 +1,149 @@
+/*
+ * 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.metrics;
+
+import org.apache.druid.collections.BlockingPool;
+import org.apache.druid.collections.DefaultBlockingPool;
+import org.apache.druid.java.util.common.Pair;
+import org.apache.druid.java.util.metrics.StubServiceEmitter;
+import org.apache.druid.query.groupby.GroupByStatsProvider;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.nio.ByteBuffer;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.stream.Collectors;
+
+public class GroupByStatsMonitorTest
+{
+  private GroupByStatsProvider groupByStatsProvider;
+  private BlockingPool<ByteBuffer> mergeBufferPool;
+  private ExecutorService executorService;
+
+  @Before
+  public void setUp()
+  {
+    groupByStatsProvider = new GroupByStatsProvider()
+    {
+      @Override
+      public synchronized Pair<Long, Long> 
getAndResetMergeBufferAcquisitionStats()
+      {
+        return Pair.of(1L, 1L);
+      }
+
+      @Override
+      public Pair<Long, Long> getAndResetSpilledBytes()

Review Comment:
   ## Non-synchronized override of synchronized method
   
   Method 'getAndResetSpilledBytes' overrides a synchronized method in 
[org.apache.druid.query.groupby.GroupByStatsProvider](1) but is not 
synchronized.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/8427)



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