Search in sources :

Example 26 with RegexDimExtractionFn

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

the class TopNQueryRunnerTest method testInvertedTopNLexicographicDimExtractionWithPreviousStop.

@Test
public void testInvertedTopNLexicographicDimExtractionWithPreviousStop() {
    TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.ALL_GRAN).dimension(new ExtractionDimensionSpec(QueryRunnerTestHelper.MARKET_DIMENSION, QueryRunnerTestHelper.MARKET_DIMENSION, new RegexDimExtractionFn("(.)", false, null))).metric(new InvertedTopNMetricSpec(new DimensionTopNMetricSpec("u", StringComparators.LEXICOGRAPHIC))).threshold(4).intervals(QueryRunnerTestHelper.FIRST_TO_THIRD).aggregators(commonAggregators).postAggregators(QueryRunnerTestHelper.ADD_ROWS_INDEX_CONSTANT).build();
    List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<>(DateTimes.of("2011-04-01T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "t", "rows", 4L, "index", 5351.814783D, "addRowsIndexConstant", 5356.814783D, "uniques", QueryRunnerTestHelper.UNIQUES_2), ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "s", "rows", 18L, "index", 2231.876812D, "addRowsIndexConstant", 2250.876812D, "uniques", QueryRunnerTestHelper.UNIQUES_9)))));
    assertExpectedResults(expectedResults, query);
}
Also used : RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) Result(org.apache.druid.query.Result) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 27 with RegexDimExtractionFn

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

the class BloomFilterAggregatorTest method testSerde.

@Test
public void testSerde() throws Exception {
    BloomFilterAggregatorFactory factory = new BloomFilterAggregatorFactory("billy", new DefaultDimensionSpec("b", "b"), MAX_NUM_VALUES);
    ObjectMapper objectMapper = new DefaultObjectMapper();
    new BloomFilterExtensionModule().getJacksonModules().forEach(objectMapper::registerModule);
    Assert.assertEquals(factory, objectMapper.readValue(objectMapper.writeValueAsString(factory), AggregatorFactory.class));
    String fieldNamesOnly = "{" + "\"type\":\"bloom\"," + "\"name\":\"billy\"," + "\"field\":\"b\"," + "\"maxNumEntries\":15" + "}";
    Assert.assertEquals(factory, objectMapper.readValue(fieldNamesOnly, AggregatorFactory.class));
    BloomFilterAggregatorFactory factory2 = new BloomFilterAggregatorFactory("billy", new ExtractionDimensionSpec("b", "b", new RegexDimExtractionFn(".*", false, null)), MAX_NUM_VALUES);
    Assert.assertEquals(factory2, objectMapper.readValue(objectMapper.writeValueAsString(factory2), AggregatorFactory.class));
    BloomFilterAggregatorFactory factory3 = new BloomFilterAggregatorFactory("billy", new RegexFilteredDimensionSpec(new DefaultDimensionSpec("a", "a"), ".*"), MAX_NUM_VALUES);
    Assert.assertEquals(factory3, objectMapper.readValue(objectMapper.writeValueAsString(factory3), AggregatorFactory.class));
}
Also used : BloomFilterExtensionModule(org.apache.druid.guice.BloomFilterExtensionModule) RegexFilteredDimensionSpec(org.apache.druid.query.dimension.RegexFilteredDimensionSpec) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) AggregatorFactory(org.apache.druid.query.aggregation.AggregatorFactory) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) CardinalityAggregatorTest(org.apache.druid.query.aggregation.cardinality.CardinalityAggregatorTest) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 28 with RegexDimExtractionFn

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

the class SearchQueryDimFilterTest method testHashcode.

@Test
public void testHashcode() {
    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.hashCode(), searchQueryDimFilter2.hashCode());
    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.hashCode(), searchQueryDimFilter3.hashCode());
}
Also used : SearchQuerySpec(org.apache.druid.query.search.SearchQuerySpec) RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) Test(org.junit.Test)

Example 29 with RegexDimExtractionFn

use of org.apache.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(org.apache.druid.query.search.SearchQuerySpec) RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) Test(org.junit.Test)

Example 30 with RegexDimExtractionFn

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

the class SearchQueryDimFilterTest method testGetCacheKey.

@Test
public void testGetCacheKey() {
    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.assertFalse(Arrays.equals(searchQueryDimFilter.getCacheKey(), searchQueryDimFilter2.getCacheKey()));
    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.assertFalse(Arrays.equals(searchQueryDimFilter.getCacheKey(), searchQueryDimFilter3.getCacheKey()));
}
Also used : SearchQuerySpec(org.apache.druid.query.search.SearchQuerySpec) RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) Test(org.junit.Test)

Aggregations

RegexDimExtractionFn (org.apache.druid.query.extraction.RegexDimExtractionFn)41 Test (org.junit.Test)40 ExtractionDimensionSpec (org.apache.druid.query.dimension.ExtractionDimensionSpec)15 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)13 Result (org.apache.druid.query.Result)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)5 ExtractionFn (org.apache.druid.query.extraction.ExtractionFn)5 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)4 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)4 SearchQuerySpec (org.apache.druid.query.search.SearchQuerySpec)3 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)2 RegexFilteredDimensionSpec (org.apache.druid.query.dimension.RegexFilteredDimensionSpec)2 CascadeExtractionFn (org.apache.druid.query.extraction.CascadeExtractionFn)2 DimExtractionFn (org.apache.druid.query.extraction.DimExtractionFn)2 JavaScriptExtractionFn (org.apache.druid.query.extraction.JavaScriptExtractionFn)2 SearchQuerySpecDimExtractionFn (org.apache.druid.query.extraction.SearchQuerySpecDimExtractionFn)2 StringFormatExtractionFn (org.apache.druid.query.extraction.StringFormatExtractionFn)2 StrlenExtractionFn (org.apache.druid.query.extraction.StrlenExtractionFn)2 SubstringDimExtractionFn (org.apache.druid.query.extraction.SubstringDimExtractionFn)2