Search in sources :

Example 6 with SearchQuerySpec

use of org.apache.druid.query.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 = 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 7 with SearchQuerySpec

use of org.apache.druid.query.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 = 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 8 with SearchQuerySpec

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

the class ContainsOperatorConversion method toDruidFilter.

@Nullable
@Override
public DimFilter toDruidFilter(PlannerContext plannerContext, RowSignature rowSignature, @Nullable VirtualColumnRegistry virtualColumnRegistry, RexNode rexNode) {
    final List<RexNode> operands = ((RexCall) rexNode).getOperands();
    final DruidExpression druidExpression = Expressions.toDruidExpression(plannerContext, rowSignature, operands.get(0));
    if (druidExpression == null) {
        return null;
    }
    final String search = RexLiteral.stringValue(operands.get(1));
    final SearchQuerySpec spec = new ContainsSearchQuerySpec(search, caseSensitive);
    if (druidExpression.isSimpleExtraction()) {
        return new SearchQueryDimFilter(druidExpression.getSimpleExtraction().getColumn(), spec, druidExpression.getSimpleExtraction().getExtractionFn(), null);
    } else if (virtualColumnRegistry != null) {
        String v = virtualColumnRegistry.getOrCreateVirtualColumnForExpression(druidExpression, operands.get(0).getType());
        return new SearchQueryDimFilter(v, spec, null, null);
    } else {
        return null;
    }
}
Also used : RexCall(org.apache.calcite.rex.RexCall) SearchQuerySpec(org.apache.druid.query.search.SearchQuerySpec) ContainsSearchQuerySpec(org.apache.druid.query.search.ContainsSearchQuerySpec) DruidExpression(org.apache.druid.sql.calcite.expression.DruidExpression) ContainsSearchQuerySpec(org.apache.druid.query.search.ContainsSearchQuerySpec) SearchQueryDimFilter(org.apache.druid.query.filter.SearchQueryDimFilter) RexNode(org.apache.calcite.rex.RexNode) Nullable(javax.annotation.Nullable)

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