@Override public List<AggregatorFactory> getRequiredColumns() { return fields.stream() .map( field -> new CardinalityAggregatorFactory( field.getOutputName(), null, Collections.singletonList(field), byRow, round ) ) .collect(Collectors.toList()); }
@Test public void testBufferAggregateRows() { CardinalityBufferAggregator agg = new CardinalityBufferAggregator( dimInfoList.toArray(new ColumnSelectorPlus[0]), true ); int maxSize = rowAggregatorFactory.getMaxIntermediateSizeWithNulls(); ByteBuffer buf = ByteBuffer.allocate(maxSize + 64); int pos = 10; buf.limit(pos + maxSize); agg.init(buf, pos); for (int i = 0; i < values1.size(); ++i) { bufferAggregate(selectorList, agg, buf, pos); } Assert.assertEquals(9.0, (Double) rowAggregatorFactory.finalizeComputation(agg.get(buf, pos)), 0.05); Assert.assertEquals(9L, rowAggregatorFactoryRounded.finalizeComputation(agg.get(buf, pos))); }
@JsonCreator public CardinalityAggregatorFactory( @JsonProperty("name") String name, @Deprecated @JsonProperty("fieldNames") final List<String> fieldNames, @JsonProperty("fields") final List<DimensionSpec> fields, @JsonProperty("byRow") final boolean byRow, @JsonProperty("round") final boolean round ) { this.name = name; // 'fieldNames' is deprecated, since CardinalityAggregatorFactory now accepts DimensionSpecs instead of Strings. // The old 'fieldNames' is still supported for backwards compatibility, but the user is not allowed to specify both // 'fields' and 'fieldNames'. if (fields == null) { Preconditions.checkArgument(fieldNames != null, "Must provide 'fieldNames' if 'fields' is null."); this.fields = makeFieldsFromFieldNames(fieldNames); } else { Preconditions.checkArgument(fieldNames == null, "Cannot specify both 'fieldNames' and 'fields."); this.fields = fields; } this.byRow = byRow; this.round = round; }
CardinalityAggregatorFactory factory = new CardinalityAggregatorFactory( "billy", Collections.singletonList(new DefaultDimensionSpec("dim1", "dim1")), ); int maxSize = factory.getMaxIntermediateSizeWithNulls(); buf = ByteBuffer.allocate(maxSize + 64); pos = 10;
Assert.assertEquals(4.0, (Double) rowAggregatorFactory.finalizeComputation(agg1.get()), 0.05); Assert.assertEquals(8.0, (Double) rowAggregatorFactory.finalizeComputation(agg2.get()), 0.05); (Double) rowAggregatorFactory.finalizeComputation( rowAggregatorFactory.combine( agg1.get(), agg2.get()
@Test public void testAggregateRows() { CardinalityAggregator agg = new CardinalityAggregator( dimInfoList, true ); for (int i = 0; i < values1.size(); ++i) { aggregate(selectorList, agg); } Assert.assertEquals(9.0, (Double) rowAggregatorFactory.finalizeComputation(agg.get()), 0.05); Assert.assertEquals(9L, rowAggregatorFactoryRounded.finalizeComputation(agg.get())); }
@Override public List<String> requiredFields() { return makeRequiredFieldNamesFromFields(fields); }
Assert.assertEquals(NullHandling.replaceWithDefault() ? 4.0 : 3.0, (Double) valueAggregatorFactory.finalizeComputation(agg1.get()), 0.05); Assert.assertEquals(NullHandling.replaceWithDefault() ? 7.0 : 6.0, (Double) valueAggregatorFactory.finalizeComputation(agg2.get()), 0.05); (Double) rowAggregatorFactory.finalizeComputation( rowAggregatorFactory.combine( agg1.get(), agg2.get()
@Test public void testAggregateValues() { CardinalityAggregator agg = new CardinalityAggregator( dimInfoList, false ); for (int i = 0; i < values1.size(); ++i) { aggregate(selectorList, agg); } Assert.assertEquals(NullHandling.replaceWithDefault() ? 7.0 : 6.0, (Double) valueAggregatorFactory.finalizeComputation(agg.get()), 0.05); Assert.assertEquals(NullHandling.replaceWithDefault() ? 7L : 6L, rowAggregatorFactoryRounded.finalizeComputation(agg.get())); }
@Override public List<String> requiredFields() { return makeRequiredFieldNamesFromFields(fields); }
ImmutableMap.of( "uniques", new CardinalityAggregatorFactory( "uniques", null,
@Test public void testBufferAggregateValues() { CardinalityBufferAggregator agg = new CardinalityBufferAggregator( dimInfoList.toArray(new ColumnSelectorPlus[0]), false ); int maxSize = valueAggregatorFactory.getMaxIntermediateSizeWithNulls(); ByteBuffer buf = ByteBuffer.allocate(maxSize + 64); int pos = 10; buf.limit(pos + maxSize); agg.init(buf, pos); for (int i = 0; i < values1.size(); ++i) { bufferAggregate(selectorList, agg, buf, pos); } Assert.assertEquals(NullHandling.replaceWithDefault() ? 7.0 : 6.0, (Double) valueAggregatorFactory.finalizeComputation(agg.get(buf, pos)), 0.05); Assert.assertEquals(NullHandling.replaceWithDefault() ? 7L : 6L, rowAggregatorFactoryRounded.finalizeComputation(agg.get(buf, pos))); }
@Test public void testAggregateValuesWithExtraction() { CardinalityAggregator agg = new CardinalityAggregator( dimInfoListWithExtraction, false ); for (int i = 0; i < values1.size(); ++i) { aggregate(selectorListWithExtraction, agg); } Assert.assertEquals(7.0, (Double) valueAggregatorFactory.finalizeComputation(agg.get()), 0.05); CardinalityAggregator agg2 = new CardinalityAggregator( dimInfoListConstantVal, false ); for (int i = 0; i < values1.size(); ++i) { aggregate(selectorListConstantVal, agg2); } Assert.assertEquals(1.0, (Double) valueAggregatorFactory.finalizeComputation(agg2.get()), 0.05); }
@JsonCreator public CardinalityAggregatorFactory( @JsonProperty("name") String name, @Deprecated @JsonProperty("fieldNames") final List<String> fieldNames, @JsonProperty("fields") final List<DimensionSpec> fields, @JsonProperty("byRow") final boolean byRow, @JsonProperty("round") final boolean round ) { this.name = name; // 'fieldNames' is deprecated, since CardinalityAggregatorFactory now accepts DimensionSpecs instead of Strings. // The old 'fieldNames' is still supported for backwards compatibility, but the user is not allowed to specify both // 'fields' and 'fieldNames'. if (fields == null) { Preconditions.checkArgument(fieldNames != null, "Must provide 'fieldNames' if 'fields' is null."); this.fields = makeFieldsFromFieldNames(fieldNames); } else { Preconditions.checkArgument(fieldNames == null, "Cannot specify both 'fieldNames' and 'fields."); this.fields = fields; } this.byRow = byRow; this.round = round; }
aggregatorFactory = new CardinalityAggregatorFactory( aggregatorName, null,
@Test public void testAggregateRowsWithExtraction() { CardinalityAggregator agg = new CardinalityAggregator( dimInfoListWithExtraction, true ); for (int i = 0; i < values1.size(); ++i) { aggregate(selectorListWithExtraction, agg); } Assert.assertEquals(9.0, (Double) rowAggregatorFactory.finalizeComputation(agg.get()), 0.05); CardinalityAggregator agg2 = new CardinalityAggregator( dimInfoListConstantVal, true ); for (int i = 0; i < values1.size(); ++i) { aggregate(selectorListConstantVal, agg2); } Assert.assertEquals(3.0, (Double) rowAggregatorFactory.finalizeComputation(agg2.get()), 0.05); }
.intervals(QueryRunnerTestHelper.firstToThird) .aggregators(duplicateAggregators( new CardinalityAggregatorFactory("numVals", aggregatorDimensionSpecs, false), new CardinalityAggregatorFactory("numVals1", aggregatorDimensionSpecs, false) )) .build();
@Test public void testSerde() throws Exception CardinalityAggregatorFactory factory = new CardinalityAggregatorFactory( "billy", null, ); CardinalityAggregatorFactory factory2 = new CardinalityAggregatorFactory( "billy", ImmutableList.of(
AGGS( new FilteredAggregatorFactory( new CardinalityAggregatorFactory( "a0", null, ), new FilteredAggregatorFactory( new CardinalityAggregatorFactory( "a1", null,
AGGS( new LongSumAggregatorFactory("a0", "cnt"), new CardinalityAggregatorFactory( "a1", null, ), new FilteredAggregatorFactory( new CardinalityAggregatorFactory( "a2", null, NOT(SELECTOR("dim2", "", null)) ), new CardinalityAggregatorFactory( "a3", null, true ), new CardinalityAggregatorFactory( "a4", null,