Search in sources :

Example 21 with RegexDimExtractionFn

use of io.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.

the class DimensionSelectorHavingSpecTest method testDimensionFilterSpec.

@Test
public void testDimensionFilterSpec() {
    DimensionSelectorHavingSpec spec = new DimensionSelectorHavingSpec("dimension", "v", null);
    assertTrue(spec.eval(getTestRow("v")));
    assertTrue(spec.eval(getTestRow(ImmutableList.of("v", "v1"))));
    assertFalse(spec.eval(getTestRow(ImmutableList.of())));
    assertFalse(spec.eval(getTestRow("v1")));
    spec = new DimensionSelectorHavingSpec("dimension", null, null);
    assertTrue(spec.eval(getTestRow(ImmutableList.of())));
    assertTrue(spec.eval(getTestRow(ImmutableList.of(""))));
    assertFalse(spec.eval(getTestRow(ImmutableList.of("v"))));
    assertFalse(spec.eval(getTestRow(ImmutableList.of("v", "v1"))));
    spec = new DimensionSelectorHavingSpec("dimension", "", null);
    assertTrue(spec.eval(getTestRow(ImmutableList.of())));
    assertTrue(spec.eval(getTestRow(ImmutableList.of(""))));
    assertTrue(spec.eval(getTestRow(ImmutableList.of("v", "v1", ""))));
    assertFalse(spec.eval(getTestRow(ImmutableList.of("v"))));
    assertFalse(spec.eval(getTestRow(ImmutableList.of("v", "v1"))));
    ExtractionFn extractionFn = new RegexDimExtractionFn("^([^,]*),", true, "default");
    spec = new DimensionSelectorHavingSpec("dimension", "v", extractionFn);
    assertTrue(spec.eval(getTestRow(ImmutableList.of("v,v1", "v2,v3"))));
    assertFalse(spec.eval(getTestRow(ImmutableList.of("v1,v4"))));
    assertFalse(spec.eval(getTestRow(ImmutableList.of("v"))));
    assertFalse(spec.eval(getTestRow(ImmutableList.of("v1", "default"))));
    assertTrue(spec.eval(getTestRow(ImmutableList.of("v,default", "none"))));
    spec = new DimensionSelectorHavingSpec("dimension", "default", extractionFn);
    assertTrue(spec.eval(getTestRow(ImmutableList.of("v1,v2", "none"))));
}
Also used : ExtractionFn(io.druid.query.extraction.ExtractionFn) RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) IdentityExtractionFn(io.druid.query.extraction.IdentityExtractionFn) RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) Test(org.junit.Test)

Example 22 with RegexDimExtractionFn

use of io.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.

the class GroupByQueryRunnerTest method testGroupByWithEmptyStringProducingDimExtractionFn.

@Test
@Ignore
public /**
   * This test exists only to show what the current behavior is and not necessarily to define that this is
   * correct behavior.  In fact, the behavior when returning the empty string from a DimExtractionFn is, by
   * contract, undefined, so this can do anything.
   */
void testGroupByWithEmptyStringProducingDimExtractionFn() {
    final ExtractionFn emptyStringExtractionFn = new RegexDimExtractionFn("(\\w{1})", false, null) {

        @Override
        public byte[] getCacheKey() {
            return new byte[] { (byte) 0xFF };
        }

        @Override
        public String apply(String dimValue) {
            return dimValue.equals("mezzanine") ? "" : super.apply(dimValue);
        }
    };
    GroupByQuery query = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.dataSource).setQuerySegmentSpec(QueryRunnerTestHelper.firstToThird).setAggregatorSpecs(Arrays.asList(QueryRunnerTestHelper.rowsCount, new LongSumAggregatorFactory("idx", "index"))).setGranularity(QueryRunnerTestHelper.dayGran).setDimensions(Lists.<DimensionSpec>newArrayList(new ExtractionDimensionSpec("quality", "alias", emptyStringExtractionFn))).build();
    List<Row> expectedResults = Arrays.asList(GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "", "rows", 3L, "idx", 2870L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "a", "rows", 1L, "idx", 135L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "b", "rows", 1L, "idx", 118L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "e", "rows", 1L, "idx", 158L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "h", "rows", 1L, "idx", 120L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "n", "rows", 1L, "idx", 121L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "p", "rows", 3L, "idx", 2900L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "t", "rows", 2L, "idx", 197L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "", "rows", 3L, "idx", 2447L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "a", "rows", 1L, "idx", 147L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "b", "rows", 1L, "idx", 112L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "e", "rows", 1L, "idx", 166L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "h", "rows", 1L, "idx", 113L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "n", "rows", 1L, "idx", 114L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "p", "rows", 3L, "idx", 2505L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "t", "rows", 2L, "idx", 223L));
    TestHelper.assertExpectedObjects(expectedResults, GroupByQueryRunnerTestHelper.runQuery(factory, runner, query), "");
}
Also used : LookupExtractionFn(io.druid.query.lookup.LookupExtractionFn) StrlenExtractionFn(io.druid.query.extraction.StrlenExtractionFn) JavaScriptExtractionFn(io.druid.query.extraction.JavaScriptExtractionFn) CascadeExtractionFn(io.druid.query.extraction.CascadeExtractionFn) TimeFormatExtractionFn(io.druid.query.extraction.TimeFormatExtractionFn) ExtractionFn(io.druid.query.extraction.ExtractionFn) RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) DimExtractionFn(io.druid.query.extraction.DimExtractionFn) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) RegexFilteredDimensionSpec(io.druid.query.dimension.RegexFilteredDimensionSpec) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) ListFilteredDimensionSpec(io.druid.query.dimension.ListFilteredDimensionSpec) DimensionSpec(io.druid.query.dimension.DimensionSpec) LongSumAggregatorFactory(io.druid.query.aggregation.LongSumAggregatorFactory) Row(io.druid.data.input.Row) RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 23 with RegexDimExtractionFn

use of io.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.

the class RegexDimFilterTest method testHashcode.

@Test
public void testHashcode() {
    RegexDimFilter regexDimFilter = new RegexDimFilter("dim", "reg", null);
    RegexDimFilter regexDimFilter2 = new RegexDimFilter("di", "mreg", null);
    RegexDimFilter regexDimFilter3 = new RegexDimFilter("di", "mreg", null);
    Assert.assertNotEquals(regexDimFilter.hashCode(), regexDimFilter2.hashCode());
    Assert.assertEquals(regexDimFilter2.hashCode(), regexDimFilter3.hashCode());
    RegexDimExtractionFn regexFn = new RegexDimExtractionFn(".*", false, null);
    RegexDimFilter regexDimFilter4 = new RegexDimFilter("dim", "reg", regexFn);
    RegexDimFilter regexDimFilter5 = new RegexDimFilter("dim", "reg", regexFn);
    Assert.assertNotEquals(regexDimFilter.hashCode(), regexDimFilter4.hashCode());
    Assert.assertEquals(regexDimFilter4.hashCode(), regexDimFilter5.hashCode());
}
Also used : RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) Test(org.junit.Test)

Example 24 with RegexDimExtractionFn

use of io.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.

the class SearchQueryDimFilterTest method testEquals.

@Test
public void testEquals() {
    SearchQueryDimFilter searchQueryDimFilter = new SearchQueryDimFilter("dim", new SearchQuerySpec() {

        @Override
        public boolean accept(String dimVal) {
            return false;
        }

        @Override
        public byte[] getCacheKey() {
            return StringUtils.toUtf8("value");
        }
    }, null);
    SearchQueryDimFilter searchQueryDimFilter2 = new SearchQueryDimFilter("di", new SearchQuerySpec() {

        @Override
        public boolean accept(String dimVal) {
            return false;
        }

        @Override
        public byte[] getCacheKey() {
            return StringUtils.toUtf8("mvalue");
        }
    }, null);
    Assert.assertNotEquals(searchQueryDimFilter, searchQueryDimFilter2);
    RegexDimExtractionFn regexFn = new RegexDimExtractionFn(".*", false, null);
    SearchQueryDimFilter searchQueryDimFilter3 = new SearchQueryDimFilter("dim", new SearchQuerySpec() {

        @Override
        public boolean accept(String dimVal) {
            return false;
        }

        @Override
        public byte[] getCacheKey() {
            return StringUtils.toUtf8("value");
        }
    }, regexFn);
    Assert.assertNotEquals(searchQueryDimFilter, searchQueryDimFilter3);
}
Also used : SearchQuerySpec(io.druid.query.search.search.SearchQuerySpec) RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) Test(org.junit.Test)

Example 25 with RegexDimExtractionFn

use of io.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.

the class SelectorDimFilterTest method testGetCacheKey.

@Test
public void testGetCacheKey() {
    SelectorDimFilter selectorDimFilter = new SelectorDimFilter("abc", "d", null);
    SelectorDimFilter selectorDimFilter2 = new SelectorDimFilter("ab", "cd", null);
    Assert.assertFalse(Arrays.equals(selectorDimFilter.getCacheKey(), selectorDimFilter2.getCacheKey()));
    RegexDimExtractionFn regexFn = new RegexDimExtractionFn(".*", false, null);
    SelectorDimFilter selectorDimFilter3 = new SelectorDimFilter("abc", "d", regexFn);
    Assert.assertFalse(Arrays.equals(selectorDimFilter.getCacheKey(), selectorDimFilter3.getCacheKey()));
}
Also used : RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) Test(org.junit.Test)

Aggregations

RegexDimExtractionFn (io.druid.query.extraction.RegexDimExtractionFn)35 Test (org.junit.Test)35 ExtractionDimensionSpec (io.druid.query.dimension.ExtractionDimensionSpec)11 Result (io.druid.query.Result)7 PostAggregator (io.druid.query.aggregation.PostAggregator)7 HyperUniqueFinalizingPostAggregator (io.druid.query.aggregation.hyperloglog.HyperUniqueFinalizingPostAggregator)7 DateTime (org.joda.time.DateTime)7 ExtractionFn (io.druid.query.extraction.ExtractionFn)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)4 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)4 RegexFilteredDimensionSpec (io.druid.query.dimension.RegexFilteredDimensionSpec)4 IdentityExtractionFn (io.druid.query.extraction.IdentityExtractionFn)4 Row (io.druid.data.input.Row)3 LongSumAggregatorFactory (io.druid.query.aggregation.LongSumAggregatorFactory)3 DimensionSpec (io.druid.query.dimension.DimensionSpec)3 ListFilteredDimensionSpec (io.druid.query.dimension.ListFilteredDimensionSpec)3 SearchQuerySpec (io.druid.query.search.search.SearchQuerySpec)3 CascadeExtractionFn (io.druid.query.extraction.CascadeExtractionFn)2 DimExtractionFn (io.druid.query.extraction.DimExtractionFn)2