From 7b9e6c29cd9dd2fa6d670b651406a06487e5c595 Mon Sep 17 00:00:00 2001 From: Gian Merlino Date: Mon, 6 Mar 2017 10:01:30 -0800 Subject: [PATCH] Fix float, long dimension indexer object selectors. (#4012) Their "convertUnsortedEncodedKeyComponentToActualArrayOrList" methods didn't respect the contract, which says they should return single values (not array/list) if there is only a single value to return. This affects the behavior of ObjectColumnSelectors on realtime segments. --- .../druid/segment/FloatDimensionIndexer.java | 3 +-- .../druid/segment/LongDimensionIndexer.java | 3 +-- .../query/groupby/GroupByQueryRunnerTest.java | 26 ++++++++++++++++--- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/processing/src/main/java/io/druid/segment/FloatDimensionIndexer.java b/processing/src/main/java/io/druid/segment/FloatDimensionIndexer.java index c0cd2a9b07d..65faa810ec1 100644 --- a/processing/src/main/java/io/druid/segment/FloatDimensionIndexer.java +++ b/processing/src/main/java/io/druid/segment/FloatDimensionIndexer.java @@ -19,7 +19,6 @@ package io.druid.segment; -import com.google.common.collect.ImmutableList; import io.druid.collections.bitmap.BitmapFactory; import io.druid.collections.bitmap.MutableBitmap; import io.druid.query.dimension.DimensionSpec; @@ -199,7 +198,7 @@ public class FloatDimensionIndexer implements DimensionIndexer @Override public Object convertUnsortedEncodedKeyComponentToActualArrayOrList(Long key, boolean asList) { - return ImmutableList.of(key); + return key; } @Override diff --git a/processing/src/test/java/io/druid/query/groupby/GroupByQueryRunnerTest.java b/processing/src/test/java/io/druid/query/groupby/GroupByQueryRunnerTest.java index 98268bcc349..cc4ad83fadd 100644 --- a/processing/src/test/java/io/druid/query/groupby/GroupByQueryRunnerTest.java +++ b/processing/src/test/java/io/druid/query/groupby/GroupByQueryRunnerTest.java @@ -7975,8 +7975,24 @@ public class GroupByQueryRunnerTest QueryRunnerTestHelper.rowsCount, new LongSumAggregatorFactory("qlLong", "qualityLong"), new DoubleSumAggregatorFactory("qlFloat", "qualityLong"), + new JavaScriptAggregatorFactory( + "qlJs", + ImmutableList.of("qualityLong"), + "function(a,b) { return a + b; }", + "function() { return 0; }", + "function(a,b) { return a + b }", + JavaScriptConfig.getEnabledInstance() + ), new DoubleSumAggregatorFactory("qfFloat", "qualityFloat"), - new LongSumAggregatorFactory("qfLong", "qualityFloat") + new LongSumAggregatorFactory("qfLong", "qualityFloat"), + new JavaScriptAggregatorFactory( + "qfJs", + ImmutableList.of("qualityFloat"), + "function(a,b) { return a + b; }", + "function() { return 0; }", + "function(a,b) { return a + b }", + JavaScriptConfig.getEnabledInstance() + ) ) ) .setGranularity(QueryRunnerTestHelper.dayGran) @@ -7989,8 +8005,10 @@ public class GroupByQueryRunnerTest "rows", 1L, "qlLong", 1700L, "qlFloat", 1700.0, + "qlJs", 1700.0, "qfFloat", 17000.0, - "qfLong", 17000L + "qfLong", 17000L, + "qfJs", 17000.0 ), GroupByQueryRunnerTestHelper.createExpectedRow( "2011-04-02", @@ -7998,8 +8016,10 @@ public class GroupByQueryRunnerTest "rows", 1L, "qlLong", 1700L, "qlFloat", 1700.0, + "qlJs", 1700.0, "qfFloat", 17000.0, - "qfLong", 17000L + "qfLong", 17000L, + "qfJs", 17000.0 ) );