You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "abhishekrb19 (via GitHub)" <gi...@apache.org> on 2023/06/22 01:06:56 UTC

[GitHub] [druid] abhishekrb19 opened a new pull request, #14465: Add missing `isNull()` implementation to `FilteredAggregator`

abhishekrb19 opened a new pull request, #14465:
URL: https://github.com/apache/druid/pull/14465

   This PR adds an `isNull()` implementation to `FilteredAggregator`. Otherwise, the default implementation always returns
   false, which can be wrong, and will cause jobs to fail when invoking accessors like `getDouble()`, `getFloat()` on the delegate when the underlying data can contain null:
   
   
   ```
   java.lang.RuntimeException: java.lang.IllegalStateException: Cannot return float for Null Value
   	at org.apache.druid.indexing.seekablestream.SeekableStreamIndexTaskRunner.runInternal(SeekableStreamIndexTaskRunner.java:605) ~[druid-indexing-service]
   	at org.apache.druid.indexing.seekablestream.SeekableStreamIndexTaskRunner.run(SeekableStreamIndexTaskRunner.java:266) ~[druid-indexing-service]
   	at org.apache.druid.indexing.seekablestream.SeekableStreamIndexTask.runTask(SeekableStreamIndexTask.java:151) ~[druid-indexing-service]
   	at org.apache.druid.indexing.common.task.AbstractTask.run(AbstractTask.java:173) ~[druid-indexing-service]
   	at org.apache.druid.indexing.overlord.SingleTaskBackgroundRunner$SingleTaskBackgroundRunnerCallable.call(SingleTaskBackgroundRunner.java:477) ~[druid-indexing-service]
   	at org.apache.druid.indexing.overlord.SingleTaskBackgroundRunner$SingleTaskBackgroundRunnerCallable.call(SingleTaskBackgroundRunner.java:449) ~[druid-indexing-service]
   	at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
   	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[?:?]
   	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[?:?]
   	at java.lang.Thread.run(Thread.java:829) ~[?:?]
   Caused by: java.lang.IllegalStateException: Cannot return float for Null Value
   	at org.apache.druid.query.aggregation.NullableNumericAggregator.getFloat(NullableNumericAggregator.java:83) ~[druid-processing]
   	at org.apache.druid.query.aggregation.FilteredAggregator.getFloat(FilteredAggregator.java:52) ~[druid-processing]
   	at org.apache.druid.segment.incremental.OnheapIncrementalIndex.getMetricHelper(OnheapIncrementalIndex.java:578) ~[druid-processing]
   	at org.apache.druid.segment.incremental.OnheapIncrementalIndex.getMetricFloatValue(OnheapIncrementalIndex.java:461) ~[druid-processing]
   	at org.apache.druid.segment.incremental.IncrementalIndex$FloatMetricColumnSelector.getFloat(IncrementalIndex.java:1481) ~[druid-processing]
   ```
   <!--
   In each section, please describe design decisions made, including:
    - Choice of algorithms
    - Behavioral aspects. What configuration values are acceptable? How are corner cases and error conditions handled, such as when there are insufficient resources?
    - Class organization and design (how the logic is split between classes, inheritance, composition, design patterns)
    - Method organization and design (how the logic is split between methods, parameters and return types)
    - Naming (class, method, API, configuration, HTTP endpoint, names of emitted metrics)
   -->
   
   
   <!-- It's good to describe an alternative design (or mention an alternative name) for every design (or naming) decision point and compare the alternatives with the designs that you've implemented (or the names you've chosen) to highlight the advantages of the chosen designs and names. -->
   
   <!-- If there was a discussion of the design of the feature implemented in this PR elsewhere (e. g. a "Proposal" issue, any other issue, or a thread in the development mailing list), link to that discussion from this PR description and explain what have changed in your final design compared to your original proposal or the consensus version in the end of the discussion. If something hasn't changed since the original discussion, you can omit a detailed discussion of those aspects of the design here, perhaps apart from brief mentioning for the sake of readability of this PR description. -->
   
   <!-- Some of the aspects mentioned above may be omitted for simple and small changes. -->
   
   <!-- Give your best effort to summarize your changes in a couple of sentences aimed toward Druid users. 
   
   If your change doesn't have end user impact, you can skip this section.
   
   For tips about how to write a good release note, see [Release notes](https://github.com/apache/druid/blob/master/CONTRIBUTING.md#release-notes).
   
   -->
   
   
   <hr>
   
   ##### Key changed/added classes in this PR
    * `FilteredAggregator.java`
    * `FiilteredAggregatorTest.java`
    *  `TestFloatNullableColumnSelector.java`
   
   <hr>
   
   <!-- Check the items by putting "x" in the brackets for the done things. Not all of these items apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items from the checklist below are strictly necessary, but it would be very helpful if you at least self-review the PR. -->
   
   This PR has:
   
   - [x] been self-reviewed.
      - [ ] using the [concurrency checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md) (Remove this item if the PR doesn't have any relation to concurrency.)
   - [ ] added documentation for new or modified features or behaviors.
   - [ ] a release note entry in the PR description.
   - [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
   - [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
   - [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
   - [x] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
   - [ ] added integration tests.
   - [ ] been tested in a test Druid cluster.
   


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


[GitHub] [druid] abhishekrb19 commented on a diff in pull request #14465: Add missing `isNull()` implementation to `FilteredAggregator`

Posted by "abhishekrb19 (via GitHub)" <gi...@apache.org>.
abhishekrb19 commented on code in PR #14465:
URL: https://github.com/apache/druid/pull/14465#discussion_r1237922145


##########
processing/src/test/java/org/apache/druid/query/aggregation/TestFloatNullableColumnSelector.java:
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.aggregation;
+
+
+public class TestFloatNullableColumnSelector extends TestFloatColumnSelector

Review Comment:
   yeah, I agree this was a quick dirty hack. I remembered this test class I wrote a while back: https://github.com/apache/druid/blob/master/processing/src/test/java/org/apache/druid/segment/TestNullableFloatColumnSelector.java. I can cleanup this test to use `TestNullableFloatColumnSelector` which takes in `Float` and determines `isNull()` on the fly as opposed to returning a static value.



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


[GitHub] [druid] clintropolis commented on a diff in pull request #14465: Add missing `isNull()` implementation to `FilteredAggregator`

Posted by "clintropolis (via GitHub)" <gi...@apache.org>.
clintropolis commented on code in PR #14465:
URL: https://github.com/apache/druid/pull/14465#discussion_r1237913207


##########
processing/src/test/java/org/apache/druid/query/aggregation/TestFloatNullableColumnSelector.java:
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.aggregation;
+
+
+public class TestFloatNullableColumnSelector extends TestFloatColumnSelector

Review Comment:
   nit: is this really worth being in its own file instead of just like.. overriding something inline or a static class in the test file?



##########
processing/src/test/java/org/apache/druid/query/aggregation/FilteredAggregatorTest.java:
##########
@@ -84,6 +85,40 @@ public void testAggregate()
     assertValues(agg, selector, expectedFirst, expectedSecond, expectedThird);
   }
 
+  @Test
+  public void testAggregateWithNullableSelectorAndNullValues()
+  {
+    NullHandling.initializeForTestsWithValues(false, true);
+
+    final TestFloatNullableColumnSelector selector = new TestFloatNullableColumnSelector(null);
+
+    final FilteredAggregatorFactory factory = new FilteredAggregatorFactory(
+        new FloatMaxAggregatorFactory("loss", "value"),
+        new SelectorDimFilter("dim", "a", null)
+    );
+
+    final FilteredAggregator agg = (FilteredAggregator) factory.factorize(makeColumnSelector(selector));
+    aggregate(selector, agg);
+    assertValues(agg, selector);
+  }
+
+  @Test
+  public void testAggregateWithNullableSelectorAndNonNullValues()

Review Comment:
   nit: since isNull on the selector always returns true is this really testing null and non-null values?



##########
processing/src/test/java/org/apache/druid/query/aggregation/FilteredAggregatorTest.java:
##########
@@ -218,14 +253,22 @@ public ColumnCapabilities getColumnCapabilities(String columnName)
 
   private void assertValues(FilteredAggregator agg, TestFloatColumnSelector selector, double... expectedVals)
   {
-    Assert.assertEquals(NullHandling.defaultDoubleValue(), agg.get());
-    Assert.assertEquals(NullHandling.defaultDoubleValue(), agg.get());
-    Assert.assertEquals(NullHandling.defaultDoubleValue(), agg.get());
-    for (double expectedVal : expectedVals) {

Review Comment:
   maybe this should accept `Double...` instead of `double...` so that it confirms that it _actually_ tests the expected values, since in this case the selectory always returns null it seems like for the test cases using `TestFloatNullableColumnSelector` this `!agg.isNull` branch will never be hit...



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


[GitHub] [druid] abhishekrb19 commented on a diff in pull request #14465: Add missing `isNull()` implementation to `FilteredAggregator`

Posted by "abhishekrb19 (via GitHub)" <gi...@apache.org>.
abhishekrb19 commented on code in PR #14465:
URL: https://github.com/apache/druid/pull/14465#discussion_r1237922145


##########
processing/src/test/java/org/apache/druid/query/aggregation/TestFloatNullableColumnSelector.java:
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.aggregation;
+
+
+public class TestFloatNullableColumnSelector extends TestFloatColumnSelector

Review Comment:
   yeah, I agree this was a quick dirty hack. I remembered this test class a while back: https://github.com/apache/druid/blob/master/processing/src/test/java/org/apache/druid/segment/TestNullableFloatColumnSelector.java. I can cleanup this test to use `TestNullableFloatColumnSelector` which takes in `Float` and determines `isNull()` on the fly as opposed to returning a static value.



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


[GitHub] [druid] clintropolis merged pull request #14465: Add missing `isNull()` implementation to `FilteredAggregator`

Posted by "clintropolis (via GitHub)" <gi...@apache.org>.
clintropolis merged PR #14465:
URL: https://github.com/apache/druid/pull/14465


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


[GitHub] [druid] abhishekrb19 commented on a diff in pull request #14465: Add missing `isNull()` implementation to `FilteredAggregator`

Posted by "abhishekrb19 (via GitHub)" <gi...@apache.org>.
abhishekrb19 commented on code in PR #14465:
URL: https://github.com/apache/druid/pull/14465#discussion_r1237922145


##########
processing/src/test/java/org/apache/druid/query/aggregation/TestFloatNullableColumnSelector.java:
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.aggregation;
+
+
+public class TestFloatNullableColumnSelector extends TestFloatColumnSelector

Review Comment:
   yeah, I agree this was a quick dirty hack. I remembered this test class I wrote a while back: https://github.com/apache/druid/blob/master/processing/src/test/java/org/apache/druid/segment/TestNullableFloatColumnSelector.java. I can cleanup this test to use `TestNullableFloatColumnSelector` which takes in `Float` and determines `isNull()` on the fly as opposed to returning a constant value.



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