Search in sources :

Example 1 with SearchQuerySpec

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

Example 2 with SearchQuerySpec

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

Example 3 with SearchQuerySpec

use of io.druid.query.search.search.SearchQuerySpec in project druid by druid-io.

the class SearchQuerySpecDimExtractionFnTest method testCaseSensitiveExtraction2.

@Test
public void testCaseSensitiveExtraction2() {
    SearchQuerySpec spec = new FragmentSearchQuerySpec(Arrays.asList("To", "yo"), true);
    ExtractionFn extractionFn = new SearchQuerySpecDimExtractionFn(spec);
    List<String> expected = ImmutableList.of("Tokyo", "Toyokawa");
    List<String> extracted = Lists.newArrayList();
    for (String str : testStrings) {
        String res = extractionFn.apply(str);
        if (res != null) {
            extracted.add(res);
        }
    }
    Assert.assertEquals(expected, extracted);
}
Also used : FragmentSearchQuerySpec(io.druid.query.search.search.FragmentSearchQuerySpec) SearchQuerySpec(io.druid.query.search.search.SearchQuerySpec) FragmentSearchQuerySpec(io.druid.query.search.search.FragmentSearchQuerySpec) Test(org.junit.Test)

Example 4 with SearchQuerySpec

use of io.druid.query.search.search.SearchQuerySpec 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 5 with SearchQuerySpec

use of io.druid.query.search.search.SearchQuerySpec in project druid by druid-io.

the class SearchQuerySpecDimExtractionFnTest method testCaseSensitiveExtraction.

@Test
public void testCaseSensitiveExtraction() {
    SearchQuerySpec spec = new FragmentSearchQuerySpec(Arrays.asList("to", "yo"), true);
    ExtractionFn extractionFn = new SearchQuerySpecDimExtractionFn(spec);
    List<String> expected = ImmutableList.of("Kyoto");
    List<String> extracted = Lists.newArrayList();
    for (String str : testStrings) {
        String res = extractionFn.apply(str);
        if (res != null) {
            extracted.add(res);
        }
    }
    Assert.assertEquals(expected, extracted);
}
Also used : FragmentSearchQuerySpec(io.druid.query.search.search.FragmentSearchQuerySpec) SearchQuerySpec(io.druid.query.search.search.SearchQuerySpec) FragmentSearchQuerySpec(io.druid.query.search.search.FragmentSearchQuerySpec) Test(org.junit.Test)

Aggregations

SearchQuerySpec (io.druid.query.search.search.SearchQuerySpec)7 Test (org.junit.Test)7 FragmentSearchQuerySpec (io.druid.query.search.search.FragmentSearchQuerySpec)4 RegexDimExtractionFn (io.druid.query.extraction.RegexDimExtractionFn)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)1