use of org.apache.druid.query.filter.BoundDimFilter in project druid by druid-io.
the class FilteredAggregatorTest method testAggregateWithExtractionFns.
@Test
public void testAggregateWithExtractionFns() {
final float[] values = { 0.15f, 0.27f };
TestFloatColumnSelector selector;
FilteredAggregatorFactory factory;
String extractionJsFn = "function(str) { return str + 'AARDVARK'; }";
ExtractionFn extractionFn = new JavaScriptExtractionFn(extractionJsFn, false, JavaScriptConfig.getEnabledInstance());
factory = new FilteredAggregatorFactory(new DoubleSumAggregatorFactory("billy", "value"), new SelectorDimFilter("dim", "aAARDVARK", extractionFn));
selector = new TestFloatColumnSelector(values);
validateFilteredAggs(factory, values, selector);
factory = new FilteredAggregatorFactory(new DoubleSumAggregatorFactory("billy", "value"), new InDimFilter("dim", Arrays.asList("NOT-aAARDVARK", "FOOBAR", "aAARDVARK"), extractionFn));
selector = new TestFloatColumnSelector(values);
validateFilteredAggs(factory, values, selector);
factory = new FilteredAggregatorFactory(new DoubleSumAggregatorFactory("billy", "value"), new BoundDimFilter("dim", "aAARDVARK", "aAARDVARK", false, false, true, extractionFn, StringComparators.ALPHANUMERIC));
selector = new TestFloatColumnSelector(values);
validateFilteredAggs(factory, values, selector);
factory = new FilteredAggregatorFactory(new DoubleSumAggregatorFactory("billy", "value"), new RegexDimFilter("dim", "aAARDVARK", extractionFn));
selector = new TestFloatColumnSelector(values);
validateFilteredAggs(factory, values, selector);
factory = new FilteredAggregatorFactory(new DoubleSumAggregatorFactory("billy", "value"), new SearchQueryDimFilter("dim", new ContainsSearchQuerySpec("aAARDVARK", true), extractionFn));
selector = new TestFloatColumnSelector(values);
validateFilteredAggs(factory, values, selector);
String jsFn = "function(x) { return(x === 'aAARDVARK') }";
factory = new FilteredAggregatorFactory(new DoubleSumAggregatorFactory("billy", "value"), new JavaScriptDimFilter("dim", jsFn, extractionFn, JavaScriptConfig.getEnabledInstance()));
selector = new TestFloatColumnSelector(values);
validateFilteredAggs(factory, values, selector);
}
use of org.apache.druid.query.filter.BoundDimFilter in project druid by druid-io.
the class IncrementalIndexTest method testFilteredAggregators.
@Test
public void testFilteredAggregators() throws Exception {
long timestamp = System.currentTimeMillis();
IncrementalIndex index = indexCreator.createIndex((Object) new AggregatorFactory[] { new CountAggregatorFactory("count"), new FilteredAggregatorFactory(new CountAggregatorFactory("count_selector_filtered"), new SelectorDimFilter("dim2", "2", null)), new FilteredAggregatorFactory(new CountAggregatorFactory("count_bound_filtered"), new BoundDimFilter("dim2", "2", "3", false, true, null, null, StringComparators.NUMERIC)), new FilteredAggregatorFactory(new CountAggregatorFactory("count_multivaldim_filtered"), new SelectorDimFilter("dim3", "b", null)), new FilteredAggregatorFactory(new CountAggregatorFactory("count_numeric_filtered"), new SelectorDimFilter("met1", "11", null)) });
index.add(new MapBasedInputRow(timestamp, Arrays.asList("dim1", "dim2", "dim3"), ImmutableMap.of("dim1", "1", "dim2", "2", "dim3", Lists.newArrayList("b", "a"), "met1", 10)));
index.add(new MapBasedInputRow(timestamp, Arrays.asList("dim1", "dim2", "dim3"), ImmutableMap.of("dim1", "3", "dim2", "4", "dim3", Lists.newArrayList("c", "d"), "met1", 11)));
Assert.assertEquals(Arrays.asList("dim1", "dim2", "dim3"), index.getDimensionNames());
Assert.assertEquals(Arrays.asList("count", "count_selector_filtered", "count_bound_filtered", "count_multivaldim_filtered", "count_numeric_filtered"), index.getMetricNames());
Assert.assertEquals(2, index.size());
final Iterator<Row> rows = index.iterator();
Row row = rows.next();
Assert.assertEquals(timestamp, row.getTimestampFromEpoch());
Assert.assertEquals(Collections.singletonList("1"), row.getDimension("dim1"));
Assert.assertEquals(Collections.singletonList("2"), row.getDimension("dim2"));
Assert.assertEquals(Arrays.asList("a", "b"), row.getDimension("dim3"));
Assert.assertEquals(1L, row.getMetric("count"));
Assert.assertEquals(1L, row.getMetric("count_selector_filtered"));
Assert.assertEquals(1L, row.getMetric("count_bound_filtered"));
Assert.assertEquals(1L, row.getMetric("count_multivaldim_filtered"));
Assert.assertEquals(0L, row.getMetric("count_numeric_filtered"));
row = rows.next();
Assert.assertEquals(timestamp, row.getTimestampFromEpoch());
Assert.assertEquals(Collections.singletonList("3"), row.getDimension("dim1"));
Assert.assertEquals(Collections.singletonList("4"), row.getDimension("dim2"));
Assert.assertEquals(Arrays.asList("c", "d"), row.getDimension("dim3"));
Assert.assertEquals(1L, row.getMetric("count"));
Assert.assertEquals(0L, row.getMetric("count_selector_filtered"));
Assert.assertEquals(0L, row.getMetric("count_bound_filtered"));
Assert.assertEquals(0L, row.getMetric("count_multivaldim_filtered"));
Assert.assertEquals(1L, row.getMetric("count_numeric_filtered"));
}
use of org.apache.druid.query.filter.BoundDimFilter in project druid by druid-io.
the class BoundFilterTest method testNumericMatchExactlySingleValue.
@Test
public void testNumericMatchExactlySingleValue() {
assertFilterMatches(new BoundDimFilter("dim1", "2", "2", false, false, false, null, StringComparators.NUMERIC), ImmutableList.of("2"));
assertFilterMatches(new BoundDimFilter("dim1", "-10.012", "-10.012", false, false, false, null, StringComparators.NUMERIC), ImmutableList.of("7"));
}
use of org.apache.druid.query.filter.BoundDimFilter in project druid by druid-io.
the class BoundFilterTest method testLexicographicMatchTooStrict.
@Test
public void testLexicographicMatchTooStrict() {
assertFilterMatches(new BoundDimFilter("dim1", "abc", "abc", true, false, false, null, StringComparators.LEXICOGRAPHIC), ImmutableList.of());
assertFilterMatches(new BoundDimFilter("dim1", "abc", "abc", true, true, false, null, StringComparators.LEXICOGRAPHIC), ImmutableList.of());
assertFilterMatches(new BoundDimFilter("dim1", "abc", "abc", false, true, false, null, StringComparators.LEXICOGRAPHIC), ImmutableList.of());
}
use of org.apache.druid.query.filter.BoundDimFilter in project druid by druid-io.
the class BoundFilterTest method testNumericMatchSurroundingSingleValue.
@Test
public void testNumericMatchSurroundingSingleValue() {
assertFilterMatches(new BoundDimFilter("dim1", "1", "3", true, true, false, null, StringComparators.NUMERIC), ImmutableList.of("2"));
assertFilterMatches(new BoundDimFilter("dim1", "-11", "-10", false, false, false, null, StringComparators.NUMERIC), ImmutableList.of("7"));
}
Aggregations