You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "github-code-scanning[bot] (via GitHub)" <gi...@apache.org> on 2023/03/17 07:10:13 UTC

[GitHub] [druid] github-code-scanning[bot] commented on a diff in pull request #12139: Limit the subquery results by memory usage (estimated)

github-code-scanning[bot] commented on code in PR #12139:
URL: https://github.com/apache/druid/pull/12139#discussion_r1139853746


##########
server/src/main/java/org/apache/druid/server/InlineResultsCursor.java:
##########
@@ -0,0 +1,374 @@
+/*
+ * 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;
+
+import com.google.common.base.Preconditions;
+import com.google.common.base.Predicate;
+import org.apache.druid.frame.write.UnsupportedColumnTypeException;
+import org.apache.druid.java.util.common.DateTimes;
+import org.apache.druid.java.util.common.ISE;
+import org.apache.druid.query.BaseQuery;
+import org.apache.druid.query.dimension.DimensionSpec;
+import org.apache.druid.query.filter.ValueMatcher;
+import org.apache.druid.query.monomorphicprocessing.RuntimeShapeInspector;
+import org.apache.druid.segment.ColumnSelectorFactory;
+import org.apache.druid.segment.ColumnValueSelector;
+import org.apache.druid.segment.Cursor;
+import org.apache.druid.segment.DimensionSelector;
+import org.apache.druid.segment.DoubleColumnSelector;
+import org.apache.druid.segment.FloatColumnSelector;
+import org.apache.druid.segment.IdLookup;
+import org.apache.druid.segment.LongColumnSelector;
+import org.apache.druid.segment.ObjectColumnSelector;
+import org.apache.druid.segment.SimpleAscendingOffset;
+import org.apache.druid.segment.SimpleSettableOffset;
+import org.apache.druid.segment.column.ColumnCapabilities;
+import org.apache.druid.segment.column.ColumnType;
+import org.apache.druid.segment.column.RowSignature;
+import org.apache.druid.segment.data.IndexedInts;
+import org.apache.druid.segment.serde.ComplexMetrics;
+import org.joda.time.DateTime;
+
+import javax.annotation.Nullable;
+import java.util.List;
+import java.util.Optional;
+
+public class InlineResultsCursor implements Cursor
+{
+
+  private final SimpleSettableOffset offset;
+  private final RowSignature rowSignature;
+  private final List<Object[]> results;
+
+
+  public InlineResultsCursor(List<Object[]> results, RowSignature rowSignature)
+  {
+    this.results = Preconditions.checkNotNull(results, "'results' cannot be null");
+    this.rowSignature = rowSignature;
+    this.offset = new SimpleAscendingOffset(results.size());
+  }
+
+  @Override
+  public ColumnSelectorFactory getColumnSelectorFactory()
+  {
+    return new ColumnSelectorFactory()
+    {
+      @Override
+      public DimensionSelector makeDimensionSelector(DimensionSpec dimensionSpec)
+      {
+        return null;
+      }
+
+      @Override
+      public ColumnValueSelector makeColumnValueSelector(String columnName)
+      {
+        return makeColumnValueSelectorFor(columnName);
+      }
+
+      @Nullable
+      @Override
+      public ColumnCapabilities getColumnCapabilities(String column)
+      {
+        return rowSignature.getColumnCapabilities(column);
+      }
+    };
+  }
+
+  @Override
+  public DateTime getTime()
+  {
+    return DateTimes.MIN;
+  }
+
+  @Override
+  public void advance()
+  {
+    offset.increment();
+    BaseQuery.checkInterrupted();
+  }
+
+  @Override
+  public void advanceUninterruptibly()
+  {
+    offset.increment();
+  }
+
+  @Override
+  public boolean isDone()
+  {
+    return offset.withinBounds();
+  }
+
+  @Override
+  public boolean isDoneOrInterrupted()
+  {
+    return offset.withinBounds() || Thread.currentThread().isInterrupted();
+  }
+
+  @Override
+  public void reset()
+  {
+    offset.reset();
+  }
+
+  private DimensionSelector makeDimensionSelectorFor(DimensionSpec dimensionSpec)
+  {
+    return dimensionSpec.decorate(makeUndecoratedDimensionSelectorFor(dimensionSpec.getDimension()));
+  }
+
+  private DimensionSelector makeUndecoratedDimensionSelectorFor(String dimensionSpec)
+  {
+    Object stringValueObject = results.get(offset.getOffset())[rowSignature.indexOf(dimensionSpec)];

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



##########
server/src/main/java/org/apache/druid/server/ClientQuerySegmentWalker.java:
##########
@@ -565,10 +615,13 @@
       final Sequence<T> results,
       final QueryToolChest<T, QueryType> toolChest,
       final AtomicInteger limitAccumulator,
-      final int limit
+      final AtomicLong memoryLimitAccumulator,
+      final int limit,
+      final long memoryLimit
   )
   {
     final int limitToUse = limit < 0 ? Integer.MAX_VALUE : limit;
+    final long memoryLimitToUse = memoryLimit < 0 ? Long.MAX_VALUE : memoryLimit;

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



##########
server/src/main/java/org/apache/druid/server/ClientQuerySegmentWalker.java:
##########
@@ -565,10 +615,13 @@
       final Sequence<T> results,
       final QueryToolChest<T, QueryType> toolChest,
       final AtomicInteger limitAccumulator,
-      final int limit
+      final AtomicLong memoryLimitAccumulator,

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



-- 
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org