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


##########
processing/src/test/java/org/apache/druid/query/operator/ScanOperatorFactoryTest.java:
##########
@@ -0,0 +1,165 @@
+/*
+ * 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.operator;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.collect.ImmutableSet;
+import org.apache.druid.common.config.NullHandling;
+import org.apache.druid.jackson.DefaultObjectMapper;
+import org.apache.druid.java.util.common.Intervals;
+import org.apache.druid.query.filter.DimFilter;
+import org.apache.druid.query.filter.DimFilters;
+import org.apache.druid.query.filter.InDimFilter;
+import org.apache.druid.query.rowsandcols.RowsAndColumns;
+import org.apache.druid.query.rowsandcols.TestRowsAndColumns;
+import org.apache.druid.query.rowsandcols.semantic.RowsAndColumnsDecorator;
+import org.apache.druid.query.rowsandcols.semantic.TestRowsAndColumnsDecorator;
+import org.apache.druid.segment.VirtualColumns;
+import org.joda.time.Interval;
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.annotation.Nullable;
+import java.io.Closeable;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+@SuppressWarnings("unchecked")
+public class ScanOperatorFactoryTest
+{
+  static {
+    NullHandling.initializeForTests();
+  }
+
+  @Test
+  public void testSerialization() throws JsonProcessingException
+  {
+    ObjectMapper mapper = DefaultObjectMapper.INSTANCE;
+
+    ScanOperatorFactory factory = new ScanOperatorFactory(
+        Intervals.utc(0, 6),
+        DimFilters.dimEquals("abc", "d"),
+        20,
+        Arrays.asList("dim1", "dim2"),
+        VirtualColumns.EMPTY,
+        Arrays.asList(ColumnWithDirection.descending("dim2"), 
ColumnWithDirection.ascending("dim1"))
+    );
+
+    final String asString = mapper.writeValueAsString(factory);
+    final ScanOperatorFactory deserialized = mapper.readValue(asString, 
ScanOperatorFactory.class);
+
+    Assert.assertEquals(factory, deserialized);
+    Assert.assertEquals(factory.hashCode(), deserialized.hashCode());
+  }
+
+  @Test
+  public void testWrappedOperatorCarriesThroughValues()
+  {
+    Interval[] intervals = new Interval[]{Intervals.utc(0, 6), 
Intervals.utc(6, 13), Intervals.utc(4, 8)};
+    DimFilter[] filters = new DimFilter[]{
+        new InDimFilter("dim", ImmutableSet.of("a", "b", "c", "e", "g")),
+        DimFilters.and(
+            new InDimFilter("dim", ImmutableSet.of("a", "b", "g")),
+            DimFilters.dimEquals("val", "789")
+        ),
+        DimFilters.or(
+            DimFilters.dimEquals("dim", "b"),
+            DimFilters.dimEquals("val", "789")
+        ),
+        DimFilters.dimEquals("dim", "f")
+    };
+    int[] limits = new int[]{100, 1000};
+    List<ColumnWithDirection>[] orderings = new List[]{
+        Arrays.asList(ColumnWithDirection.descending("__time"), 
ColumnWithDirection.ascending("dim")),
+        Collections.singletonList(ColumnWithDirection.ascending("val"))
+    };
+
+    for (int i = 2; i <= intervals.length; ++i) {
+      Interval interval = (i == 0 ? null : intervals[i - 1]);

Review Comment:
   ## Useless comparison test
   
   Test is always false.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/5213)



##########
processing/src/main/java/org/apache/druid/query/rowsandcols/semantic/DefaultColumnSelectorFactoryMaker.java:
##########
@@ -219,5 +178,222 @@
       }
       return fn.apply(retVal);
     }
+
+    private class PassThroughColumnValueSelector implements ColumnValueSelector
+    {
+      private final Class myClazz;
+      private final ColumnAccessor columnAccessor;
+
+      public PassThroughColumnValueSelector(
+          ColumnAccessor columnAccessor
+      )
+      {
+        this.columnAccessor = columnAccessor;
+        switch (columnAccessor.getType().getType()) {
+          case LONG:
+            myClazz = long.class;
+            break;
+          case DOUBLE:
+            myClazz = double.class;
+            break;
+          case FLOAT:
+            myClazz = float.class;
+            break;
+          case ARRAY:
+            myClazz = List.class;
+          default:
+            throw DruidException.defensive("this class cannot handle type 
[%s]", columnAccessor.getType());
+        }
+      }
+
+      @Nullable
+      @Override
+      public Object getObject()
+      {
+        return columnAccessor.getObject(cellIdSupplier.get());
+      }
+
+      @SuppressWarnings("rawtypes")
+      @Override
+      public Class classOfObject()
+      {
+        return myClazz;
+      }
+
+      @Override
+      public boolean isNull()
+      {
+        return columnAccessor.isNull(cellIdSupplier.get());
+      }
+
+      @Override
+      public long getLong()
+      {
+        return columnAccessor.getLong(cellIdSupplier.get());
+      }
+
+      @Override
+      public float getFloat()
+      {
+        return columnAccessor.getFloat(cellIdSupplier.get());
+      }
+
+      @Override
+      public double getDouble()
+      {
+        return columnAccessor.getDouble(cellIdSupplier.get());
+      }
+
+      @Override
+      public void inspectRuntimeShape(RuntimeShapeInspector inspector)
+      {
+
+      }
+    }
+
+    private class StringColumnValueSelector implements ColumnValueSelector
+    {
+      private final ColumnAccessor columnAccessor;
+
+      public StringColumnValueSelector(
+          ColumnAccessor columnAccessor
+      )
+      {
+        this.columnAccessor = columnAccessor;
+      }
+
+      @Nullable
+      @Override
+      public Object getObject()
+      {
+        // We want our String columns to be ByteBuffers, but users of this 
ColumnValueSelector interface
+        // would generally expect String objects instead of UTF8 ByteBuffers, 
so we have to convert here
+        // if we get a ByteBuffer.
+
+        final Object retVal = columnAccessor.getObject(cellIdSupplier.get());
+        if (retVal instanceof ByteBuffer) {
+          return StringUtils.fromUtf8(((ByteBuffer) 
retVal).asReadOnlyBuffer());
+        }
+        return retVal;
+      }
+
+      @SuppressWarnings("rawtypes")
+      @Override
+      public Class classOfObject()
+      {
+        return String.class;
+      }
+
+      @Override
+      public boolean isNull()
+      {
+        return columnAccessor.isNull(cellIdSupplier.get());
+      }
+
+      @Override
+      public long getLong()
+      {
+        return columnAccessor.getLong(cellIdSupplier.get());
+      }
+
+      @Override
+      public float getFloat()
+      {
+        return columnAccessor.getFloat(cellIdSupplier.get());
+      }
+
+      @Override
+      public double getDouble()
+      {
+        return columnAccessor.getDouble(cellIdSupplier.get());
+      }
+
+      @Override
+      public void inspectRuntimeShape(RuntimeShapeInspector inspector)
+      {
+
+      }
+    }
+
+    private class ComplexColumnValueSelector implements ColumnValueSelector
+    {
+      private final AtomicReference<Class> myClazz;
+      private final ColumnAccessor columnAccessor;
+
+      public ComplexColumnValueSelector(ColumnAccessor columnAccessor)
+      {
+        this.columnAccessor = columnAccessor;
+        myClazz = new AtomicReference<>(null);
+      }
+
+      @Nullable
+      @Override
+      public Object getObject()
+      {
+        return columnAccessor.getObject(cellIdSupplier.get());
+      }
+
+      @SuppressWarnings("rawtypes")
+      @Override
+      public Class classOfObject()
+      {
+        Class retVal = myClazz.get();
+        if (retVal == null) {
+          retVal = findClazz();
+          myClazz.set(retVal);
+        }
+        return retVal;
+      }
+
+      private Class findClazz()
+      {
+        final ColumnType type = columnAccessor.getType();
+        if (type.getType() == ValueType.COMPLEX) {
+          final ComplexMetricSerde serdeForType = 
ComplexMetrics.getSerdeForType(type.getComplexTypeName());
+          if (serdeForType != null && serdeForType.getObjectStrategy() != 
null) {
+            return serdeForType.getObjectStrategy().getClazz();

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



##########
processing/src/test/java/org/apache/druid/query/rowsandcols/semantic/RowsAndColumnsDecoratorTest.java:
##########
@@ -0,0 +1,243 @@
+/*
+ * 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.rowsandcols.semantic;
+
+import com.google.common.collect.ImmutableSet;
+import org.apache.druid.java.util.common.ISE;
+import org.apache.druid.java.util.common.Intervals;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.UOE;
+import org.apache.druid.java.util.common.granularity.Granularities;
+import org.apache.druid.java.util.common.guava.Sequence;
+import org.apache.druid.query.filter.Filter;
+import org.apache.druid.query.filter.InDimFilter;
+import org.apache.druid.query.operator.ColumnWithDirection;
+import org.apache.druid.query.rowsandcols.MapOfColumnsRowsAndColumns;
+import org.apache.druid.query.rowsandcols.RowsAndColumns;
+import org.apache.druid.query.rowsandcols.column.ColumnAccessor;
+import org.apache.druid.segment.ArrayListSegment;
+import org.apache.druid.segment.ColumnValueSelector;
+import org.apache.druid.segment.Cursor;
+import org.apache.druid.segment.VirtualColumns;
+import org.apache.druid.segment.column.ColumnType;
+import org.apache.druid.segment.column.RowSignature;
+import org.apache.druid.segment.column.TypeStrategy;
+import org.apache.druid.segment.filter.AndFilter;
+import org.apache.druid.segment.filter.OrFilter;
+import org.apache.druid.segment.filter.SelectorFilter;
+import org.apache.druid.timeline.SegmentId;
+import org.joda.time.Interval;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.function.Function;
+
+@SuppressWarnings({"unchecked", "rawtypes", "ConstantConditions", 
"SingleStatementInBlock", "VariableNotUsedInsideIf"})
+public class RowsAndColumnsDecoratorTest extends SemanticTestBase
+{
+  public RowsAndColumnsDecoratorTest(
+      String name,
+      Function<MapOfColumnsRowsAndColumns, RowsAndColumns> fn
+  )
+  {
+    super(name, fn);
+  }
+
+  @Test
+  public void testDecoration()
+  {
+    Object[][] vals = new Object[][]{
+        {1L, "a", 123L, 0L},
+        {2L, "a", 456L, 1L},
+        {3L, "b", 789L, 2L},
+        {4L, "b", 123L, 3L},
+        {5L, "c", 456L, 4L},
+        {6L, "c", 789L, 5L},
+        {7L, "c", 123L, 6L},
+        {8L, "d", 456L, 7L},
+        {9L, "e", 789L, 8L},
+        {10L, "f", 123L, 9L},
+        {11L, "f", 456L, 10L},
+        {12L, "g", 789L, 11L},
+        };
+
+    RowSignature siggy = RowSignature.builder()
+                                     .add("__time", ColumnType.LONG)
+                                     .add("dim", ColumnType.STRING)
+                                     .add("val", ColumnType.LONG)
+                                     .add("arrayIndex", ColumnType.LONG)
+                                     .build();
+
+    final RowsAndColumns base = 
make(MapOfColumnsRowsAndColumns.fromRowObjects(vals, siggy));
+
+    Interval[] intervals = new Interval[]{Intervals.utc(0, 6), 
Intervals.utc(6, 13), Intervals.utc(4, 8)};
+    Filter[] filters = new Filter[]{
+        new InDimFilter("dim", ImmutableSet.of("a", "b", "c", "e", "g")),
+        new AndFilter(Arrays.asList(
+            new InDimFilter("dim", ImmutableSet.of("a", "b", "g")),
+            new SelectorFilter("val", "789")
+        )),
+        new OrFilter(Arrays.asList(
+            new SelectorFilter("dim", "b"),
+            new SelectorFilter("val", "789")
+        )),
+        new SelectorFilter("dim", "f")
+    };
+    int[] limits = new int[]{3, 6, 100};
+    List<ColumnWithDirection>[] orderings = new List[]{
+        Arrays.asList(ColumnWithDirection.descending("__time"), 
ColumnWithDirection.ascending("dim")),
+        Collections.singletonList(ColumnWithDirection.ascending("val"))
+    };
+
+    // call the same method multiple times
+
+    for (int i = 2; i <= intervals.length; ++i) {
+      Interval interval = (i == 0 ? null : intervals[i - 1]);

Review Comment:
   ## Useless comparison test
   
   Test is always false.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/5214)



##########
processing/src/main/java/org/apache/druid/query/rowsandcols/semantic/DefaultColumnSelectorFactoryMaker.java:
##########
@@ -219,5 +178,222 @@
       }
       return fn.apply(retVal);
     }
+
+    private class PassThroughColumnValueSelector implements ColumnValueSelector
+    {
+      private final Class myClazz;
+      private final ColumnAccessor columnAccessor;
+
+      public PassThroughColumnValueSelector(
+          ColumnAccessor columnAccessor
+      )
+      {
+        this.columnAccessor = columnAccessor;
+        switch (columnAccessor.getType().getType()) {
+          case LONG:
+            myClazz = long.class;
+            break;
+          case DOUBLE:
+            myClazz = double.class;
+            break;
+          case FLOAT:
+            myClazz = float.class;
+            break;
+          case ARRAY:
+            myClazz = List.class;
+          default:
+            throw DruidException.defensive("this class cannot handle type 
[%s]", columnAccessor.getType());
+        }
+      }
+
+      @Nullable
+      @Override
+      public Object getObject()
+      {
+        return columnAccessor.getObject(cellIdSupplier.get());
+      }
+
+      @SuppressWarnings("rawtypes")
+      @Override
+      public Class classOfObject()
+      {
+        return myClazz;
+      }
+
+      @Override
+      public boolean isNull()
+      {
+        return columnAccessor.isNull(cellIdSupplier.get());
+      }
+
+      @Override
+      public long getLong()
+      {
+        return columnAccessor.getLong(cellIdSupplier.get());
+      }
+
+      @Override
+      public float getFloat()
+      {
+        return columnAccessor.getFloat(cellIdSupplier.get());
+      }
+
+      @Override
+      public double getDouble()
+      {
+        return columnAccessor.getDouble(cellIdSupplier.get());
+      }
+
+      @Override
+      public void inspectRuntimeShape(RuntimeShapeInspector inspector)
+      {
+
+      }
+    }
+
+    private class StringColumnValueSelector implements ColumnValueSelector
+    {
+      private final ColumnAccessor columnAccessor;
+
+      public StringColumnValueSelector(
+          ColumnAccessor columnAccessor
+      )
+      {
+        this.columnAccessor = columnAccessor;
+      }
+
+      @Nullable
+      @Override
+      public Object getObject()
+      {
+        // We want our String columns to be ByteBuffers, but users of this 
ColumnValueSelector interface
+        // would generally expect String objects instead of UTF8 ByteBuffers, 
so we have to convert here
+        // if we get a ByteBuffer.
+
+        final Object retVal = columnAccessor.getObject(cellIdSupplier.get());
+        if (retVal instanceof ByteBuffer) {
+          return StringUtils.fromUtf8(((ByteBuffer) 
retVal).asReadOnlyBuffer());
+        }
+        return retVal;
+      }
+
+      @SuppressWarnings("rawtypes")
+      @Override
+      public Class classOfObject()
+      {
+        return String.class;
+      }
+
+      @Override
+      public boolean isNull()
+      {
+        return columnAccessor.isNull(cellIdSupplier.get());
+      }
+
+      @Override
+      public long getLong()
+      {
+        return columnAccessor.getLong(cellIdSupplier.get());
+      }
+
+      @Override
+      public float getFloat()
+      {
+        return columnAccessor.getFloat(cellIdSupplier.get());
+      }
+
+      @Override
+      public double getDouble()
+      {
+        return columnAccessor.getDouble(cellIdSupplier.get());
+      }
+
+      @Override
+      public void inspectRuntimeShape(RuntimeShapeInspector inspector)
+      {
+
+      }
+    }
+
+    private class ComplexColumnValueSelector implements ColumnValueSelector
+    {
+      private final AtomicReference<Class> myClazz;
+      private final ColumnAccessor columnAccessor;
+
+      public ComplexColumnValueSelector(ColumnAccessor columnAccessor)
+      {
+        this.columnAccessor = columnAccessor;
+        myClazz = new AtomicReference<>(null);
+      }
+
+      @Nullable
+      @Override
+      public Object getObject()
+      {
+        return columnAccessor.getObject(cellIdSupplier.get());
+      }
+
+      @SuppressWarnings("rawtypes")
+      @Override
+      public Class classOfObject()
+      {
+        Class retVal = myClazz.get();
+        if (retVal == null) {
+          retVal = findClazz();
+          myClazz.set(retVal);
+        }
+        return retVal;
+      }
+
+      private Class findClazz()
+      {
+        final ColumnType type = columnAccessor.getType();
+        if (type.getType() == ValueType.COMPLEX) {
+          final ComplexMetricSerde serdeForType = 
ComplexMetrics.getSerdeForType(type.getComplexTypeName());
+          if (serdeForType != null && serdeForType.getObjectStrategy() != 
null) {

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



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