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);
}
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);
}
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;
}
}
Aggregations