Search in sources :

Example 6 with SearchQuerySpec

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

the class SearchQuerySpecDimExtractionFnTest method testExtraction.

@Test
public void testExtraction() {
    SearchQuerySpec spec = new FragmentSearchQuerySpec(Arrays.asList("tO", "yO"));
    ExtractionFn extractionFn = new SearchQuerySpecDimExtractionFn(spec);
    List<String> expected = ImmutableList.of("Kyoto", "Tokyo", "Toyokawa", "Yorktown");
    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 7 with SearchQuerySpec

use of io.druid.query.search.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 : FragmentSearchQuerySpec(io.druid.query.search.search.FragmentSearchQuerySpec) SearchQuerySpec(io.druid.query.search.search.SearchQuerySpec) FragmentSearchQuerySpec(io.druid.query.search.search.FragmentSearchQuerySpec) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) 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