Search in sources :

Example 96 with SelectorDimFilter

use of org.apache.druid.query.filter.SelectorDimFilter in project druid by druid-io.

the class FilteredAggregatorTest method testAggregateWithNotFilter.

@Test
public void testAggregateWithNotFilter() {
    final float[] values = { 0.15f, 0.27f };
    final TestFloatColumnSelector selector = new TestFloatColumnSelector(values);
    FilteredAggregatorFactory factory = new FilteredAggregatorFactory(new DoubleSumAggregatorFactory("billy", "value"), new NotDimFilter(new SelectorDimFilter("dim", "b", null)));
    validateFilteredAggs(factory, values, selector);
}
Also used : NotDimFilter(org.apache.druid.query.filter.NotDimFilter) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) Test(org.junit.Test)

Example 97 with SelectorDimFilter

use of org.apache.druid.query.filter.SelectorDimFilter in project druid by druid-io.

the class FilteredAggregatorTest method testAggregateWithAndFilter.

@Test
public void testAggregateWithAndFilter() {
    final float[] values = { 0.15f, 0.27f };
    final TestFloatColumnSelector selector = new TestFloatColumnSelector(values);
    FilteredAggregatorFactory factory = new FilteredAggregatorFactory(new DoubleSumAggregatorFactory("billy", "value"), new AndDimFilter(Lists.newArrayList(new NotDimFilter(new SelectorDimFilter("dim", "b", null)), new SelectorDimFilter("dim", "a", null))));
    validateFilteredAggs(factory, values, selector);
}
Also used : NotDimFilter(org.apache.druid.query.filter.NotDimFilter) AndDimFilter(org.apache.druid.query.filter.AndDimFilter) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) Test(org.junit.Test)

Example 98 with SelectorDimFilter

use of org.apache.druid.query.filter.SelectorDimFilter in project druid by druid-io.

the class ConvertBoundsToSelectors method process.

@Override
public DimFilter process(DimFilter filter) {
    if (filter instanceof BoundDimFilter) {
        final BoundDimFilter bound = (BoundDimFilter) filter;
        final StringComparator comparator = RowSignatures.getNaturalStringComparator(rowSignature, SimpleExtraction.of(bound.getDimension(), bound.getExtractionFn()));
        if (bound.hasUpperBound() && bound.hasLowerBound() && bound.getUpper().equals(bound.getLower()) && !bound.isUpperStrict() && !bound.isLowerStrict() && bound.getOrdering().equals(comparator)) {
            return new SelectorDimFilter(bound.getDimension(), bound.getUpper(), bound.getExtractionFn());
        } else {
            return filter;
        }
    } else {
        return filter;
    }
}
Also used : BoundDimFilter(org.apache.druid.query.filter.BoundDimFilter) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) StringComparator(org.apache.druid.query.ordering.StringComparator)

Example 99 with SelectorDimFilter

use of org.apache.druid.query.filter.SelectorDimFilter in project druid by druid-io.

the class DatasourceIngestionSpecTest method testMultiIntervalSerde.

@Test
public void testMultiIntervalSerde() throws Exception {
    // defaults
    String jsonStr = "{\n" + "  \"dataSource\": \"test\",\n" + "  \"intervals\": [\"2014/2015\", \"2016/2017\"]\n" + "}\n";
    DatasourceIngestionSpec actual = MAPPER.readValue(MAPPER.writeValueAsString(MAPPER.readValue(jsonStr, DatasourceIngestionSpec.class)), DatasourceIngestionSpec.class);
    List<Interval> intervals = ImmutableList.of(Intervals.of("2014/2015"), Intervals.of("2016/2017"));
    DatasourceIngestionSpec expected = new DatasourceIngestionSpec("test", null, intervals, null, null, null, null, false, null);
    Assert.assertEquals(expected, actual);
    // non-defaults
    jsonStr = "{\n" + "  \"dataSource\": \"test\",\n" + "  \"intervals\": [\"2014/2015\", \"2016/2017\"],\n" + "  \"segments\": [{\n" + "    \"dataSource\":\"test\",\n" + "    \"interval\":\"2014-01-01T00:00:00.000Z/2017-01-01T00:00:00.000Z\",\n" + "    \"version\":\"v0\",\n" + "    \"loadSpec\":null,\n" + "    \"dimensions\":\"\",\n" + "    \"metrics\":\"\",\n" + "    \"shardSpec\":{\"type\":\"none\"},\n" + "    \"binaryVersion\":9,\n" + "    \"size\":128,\n" + "    \"identifier\":\"test_2014-01-01T00:00:00.000Z_2017-01-01T00:00:00.000Z_v0\"\n" + "    }],\n" + "  \"filter\": { \"type\": \"selector\", \"dimension\": \"dim\", \"value\": \"value\"},\n" + "  \"granularity\": \"day\",\n" + "  \"dimensions\": [\"d1\", \"d2\"],\n" + "  \"metrics\": [\"m1\", \"m2\", \"m3\"],\n" + "  \"ignoreWhenNoSegments\": true\n" + "}\n";
    expected = new DatasourceIngestionSpec("test", null, intervals, ImmutableList.of(new DataSegment("test", Intervals.of("2014/2017"), "v0", null, null, null, null, 9, 128)), new SelectorDimFilter("dim", "value", null), Lists.newArrayList("d1", "d2"), Lists.newArrayList("m1", "m2", "m3"), true, null);
    actual = MAPPER.readValue(MAPPER.writeValueAsString(MAPPER.readValue(jsonStr, DatasourceIngestionSpec.class)), DatasourceIngestionSpec.class);
    Assert.assertEquals(expected, actual);
}
Also used : SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) DataSegment(org.apache.druid.timeline.DataSegment) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 100 with SelectorDimFilter

use of org.apache.druid.query.filter.SelectorDimFilter in project druid by druid-io.

the class DatasourceIngestionSpecTest method testSingleIntervalSerde.

@Test
public void testSingleIntervalSerde() throws Exception {
    Interval interval = Intervals.of("2014/2015");
    DatasourceIngestionSpec expected = new DatasourceIngestionSpec("test", interval, null, null, new SelectorDimFilter("dim", "value", null), Lists.newArrayList("d1", "d2"), Lists.newArrayList("m1", "m2", "m3"), false, null);
    DatasourceIngestionSpec actual = MAPPER.readValue(MAPPER.writeValueAsString(expected), DatasourceIngestionSpec.class);
    Assert.assertEquals(ImmutableList.of(interval), actual.getIntervals());
    Assert.assertEquals(expected, actual);
}
Also used : SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) Interval(org.joda.time.Interval) Test(org.junit.Test)

Aggregations

SelectorDimFilter (org.apache.druid.query.filter.SelectorDimFilter)206 Test (org.junit.Test)184 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)78 OrDimFilter (org.apache.druid.query.filter.OrDimFilter)54 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)41 AndDimFilter (org.apache.druid.query.filter.AndDimFilter)39 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)37 BoundDimFilter (org.apache.druid.query.filter.BoundDimFilter)34 ArrayList (java.util.ArrayList)29 Filter (org.apache.druid.query.filter.Filter)27 Result (org.apache.druid.query.Result)25 DimFilter (org.apache.druid.query.filter.DimFilter)24 InDimFilter (org.apache.druid.query.filter.InDimFilter)24 NotDimFilter (org.apache.druid.query.filter.NotDimFilter)24 ExpressionDimFilter (org.apache.druid.query.filter.ExpressionDimFilter)23 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)22 SelectorFilter (org.apache.druid.segment.filter.SelectorFilter)22 JoinFilterPreAnalysis (org.apache.druid.segment.join.filter.JoinFilterPreAnalysis)21 LookupExtractionFn (org.apache.druid.query.lookup.LookupExtractionFn)20 HashMap (java.util.HashMap)19