Search in sources :

Example 1 with SearchQuerySpec

use of org.apache.druid.query.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 = new ArrayList<>();
    for (String str : TEST_STRINGS) {
        String res = extractionFn.apply(str);
        if (res != null) {
            extracted.add(res);
        }
    }
    Assert.assertEquals(expected, extracted);
}
Also used : SearchQuerySpec(org.apache.druid.query.search.SearchQuerySpec) FragmentSearchQuerySpec(org.apache.druid.query.search.FragmentSearchQuerySpec) FragmentSearchQuerySpec(org.apache.druid.query.search.FragmentSearchQuerySpec) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with SearchQuerySpec

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

the class SearchQuerySpecDimExtractionFnTest method testSerde.

@Test
public void testSerde() throws Exception {
    ObjectMapper objectMapper = new DefaultObjectMapper();
    SearchQuerySpec spec = new FragmentSearchQuerySpec(Arrays.asList("to", "yo"), true);
    ExtractionFn extractionFn = new SearchQuerySpecDimExtractionFn(spec);
    ExtractionFn extractionFn2 = objectMapper.readValue(objectMapper.writeValueAsBytes(extractionFn), ExtractionFn.class);
    FragmentSearchQuerySpec spec2 = (FragmentSearchQuerySpec) ((SearchQuerySpecDimExtractionFn) extractionFn2).getSearchQuerySpec();
    Assert.assertEquals(extractionFn, extractionFn2);
    Assert.assertEquals(true, spec2.isCaseSensitive());
    Assert.assertEquals(ImmutableList.of("to", "yo"), spec2.getValues());
}
Also used : SearchQuerySpec(org.apache.druid.query.search.SearchQuerySpec) FragmentSearchQuerySpec(org.apache.druid.query.search.FragmentSearchQuerySpec) FragmentSearchQuerySpec(org.apache.druid.query.search.FragmentSearchQuerySpec) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 3 with SearchQuerySpec

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

Example 4 with SearchQuerySpec

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

Example 5 with SearchQuerySpec

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

Aggregations

SearchQuerySpec (org.apache.druid.query.search.SearchQuerySpec)8 Test (org.junit.Test)7 FragmentSearchQuerySpec (org.apache.druid.query.search.FragmentSearchQuerySpec)4 ArrayList (java.util.ArrayList)3 RegexDimExtractionFn (org.apache.druid.query.extraction.RegexDimExtractionFn)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Nullable (javax.annotation.Nullable)1 RexCall (org.apache.calcite.rex.RexCall)1 RexNode (org.apache.calcite.rex.RexNode)1 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)1 SearchQueryDimFilter (org.apache.druid.query.filter.SearchQueryDimFilter)1 ContainsSearchQuerySpec (org.apache.druid.query.search.ContainsSearchQuerySpec)1 DruidExpression (org.apache.druid.sql.calcite.expression.DruidExpression)1