Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,13 @@ public class HyperUniquesAggregatorFactory extends AggregatorFactory
{
public static Object estimateCardinality(@Nullable Object object, boolean round)
{
if (object == null) {
return 0;
}

final HyperLogLogCollector collector = (HyperLogLogCollector) object;

// Avoid ternary, it causes estimateCardinalityRound to be cast to double.
// Avoid ternary for round check as it causes estimateCardinalityRound to be cast to double.
if (round) {
return collector.estimateCardinalityRound();
return collector == null ? 0L : collector.estimateCardinalityRound();
} else {
return collector.estimateCardinality();
return collector == null ? 0d : collector.estimateCardinality();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public void testHyperUniqueEvolutionTimeseries(boolean doVectorize)

// index1 has no "uniques" column
Assert.assertEquals(
timeseriesResult(ImmutableMap.of("uniques", 0)),
timeseriesResult(ImmutableMap.of("uniques", 0d)),
runQuery(query, factory, ImmutableList.of(index1))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.junit.Assert;
import org.junit.Test;

import java.nio.ByteBuffer;
import java.util.Comparator;
import java.util.Random;

Expand Down Expand Up @@ -173,6 +174,30 @@ public void testCompareToShouldBehaveConsistentlyWithEstimatedCardinalitiesEvenI
}
}

@Test
public void testEstimateCardinalityForZeroCardinality()
{
HyperLogLogCollector emptyHyperLogLogCollector = HyperUniquesBufferAggregator.doGet(
ByteBuffer.allocate(HyperLogLogCollector.getLatestNumBytesForDenseStorage()),
0
);

Assert.assertEquals(0L, HyperUniquesAggregatorFactory.estimateCardinality(null, true));
Assert.assertEquals(0d, HyperUniquesAggregatorFactory.estimateCardinality(null, false));

Assert.assertEquals(0L, HyperUniquesAggregatorFactory.estimateCardinality(emptyHyperLogLogCollector, true));
Assert.assertEquals(0d, HyperUniquesAggregatorFactory.estimateCardinality(emptyHyperLogLogCollector, false));

Assert.assertEquals(
HyperUniquesAggregatorFactory.estimateCardinality(emptyHyperLogLogCollector, true).getClass(),
HyperUniquesAggregatorFactory.estimateCardinality(null, true).getClass()
);
Assert.assertEquals(
HyperUniquesAggregatorFactory.estimateCardinality(emptyHyperLogLogCollector, false).getClass(),
HyperUniquesAggregatorFactory.estimateCardinality(null, false).getClass()
);
}

@Test
public void testSerde() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2568,7 +2568,7 @@ public void testTimeseriesWithTimestampResultFieldContextForArrayResponse()
);
Assert.assertEquals(
0.0D,
NullHandling.sqlCompatible() ? (Double) result[4] : (Integer) result[4],
(Double) result[4],
0.02
);
Assert.assertEquals(
Expand All @@ -2581,7 +2581,7 @@ public void testTimeseriesWithTimestampResultFieldContextForArrayResponse()
result[3]
);
Assert.assertEquals(
(Integer) result[4],
(Double) result[4],
0.0,
0.02
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,15 +647,15 @@ public void testTopNOverMissingUniques()
Arrays.<Map<String, Object>>asList(
ImmutableMap.<String, Object>builder()
.put("market", "spot")
.put("uniques", 0)
.put("uniques", 0d)
.build(),
ImmutableMap.<String, Object>builder()
.put("market", "total_market")
.put("uniques", 0)
.put("uniques", 0d)
.build(),
ImmutableMap.<String, Object>builder()
.put("market", "upfront")
.put("uniques", 0)
.put("uniques", 0d)
.build()
)
)
Expand Down