use of org.apache.druid.query.filter.LikeDimFilter in project druid by druid-io.
the class LikeFilterTest method testNewlineMatchWithExtractionFn.
@Test
public void testNewlineMatchWithExtractionFn() {
assertFilterMatches(new LikeDimFilter("dim1", "e%", null, new SubstringDimExtractionFn(1, 100)), ImmutableList.of("6"));
assertFilterMatches(new LikeDimFilter("dim1", "%ine", null, new SubstringDimExtractionFn(1, 100)), ImmutableList.of("6"));
assertFilterMatches(new LikeDimFilter("dim1", "ew_line", null, new SubstringDimExtractionFn(1, 100)), ImmutableList.of("6"));
}
use of org.apache.druid.query.filter.LikeDimFilter in project druid by druid-io.
the class CalciteMultiValueStringQueryTest method testFilterOnMultiValueListFilterMatchLike.
@Test
public void testFilterOnMultiValueListFilterMatchLike() throws Exception {
// Cannot vectorize due to usage of expressions.
cannotVectorize();
testQuery("SELECT dim3, SUM(cnt) FROM druid.numfoo WHERE MV_FILTER_ONLY(dim3, ARRAY['b']) LIKE 'b%' GROUP BY 1 ORDER BY 2 DESC", ImmutableList.of(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE3).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setVirtualColumns(new ListFilteredVirtualColumn("v0", DefaultDimensionSpec.of("dim3"), ImmutableSet.of("b"), true)).setDimFilter(new LikeDimFilter("v0", "b%", null, null)).setDimensions(dimensions(new DefaultDimensionSpec("dim3", "_d0", ColumnType.STRING))).setAggregatorSpecs(aggregators(new LongSumAggregatorFactory("a0", "cnt"))).setLimitSpec(new DefaultLimitSpec(ImmutableList.of(new OrderByColumnSpec("a0", OrderByColumnSpec.Direction.DESCENDING, StringComparators.NUMERIC)), Integer.MAX_VALUE)).setContext(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { "b", 2L }, new Object[] { "a", 1L }, new Object[] { "c", 1L }));
}
use of org.apache.druid.query.filter.LikeDimFilter in project druid by druid-io.
the class LikeFilterTest method testNewlineMatch.
@Test
public void testNewlineMatch() {
assertFilterMatches(new LikeDimFilter("dim1", "ne%", null, null), ImmutableList.of("6"));
assertFilterMatches(new LikeDimFilter("dim1", "%ine", null, null), ImmutableList.of("6"));
assertFilterMatches(new LikeDimFilter("dim1", "new_line", null, null), ImmutableList.of("6"));
}
use of org.apache.druid.query.filter.LikeDimFilter in project druid by druid-io.
the class LikeFilterTest method testRequiredColumnRewrite.
@Test
public void testRequiredColumnRewrite() {
Filter filter = new LikeDimFilter("dim0", "e%", null, new SubstringDimExtractionFn(1, 100)).toFilter();
Filter filter2 = new LikeDimFilter("dim1", "e%", null, new SubstringDimExtractionFn(1, 100)).toFilter();
Assert.assertTrue(filter.supportsRequiredColumnRewrite());
Assert.assertTrue(filter2.supportsRequiredColumnRewrite());
Filter rewrittenFilter = filter.rewriteRequiredColumns(ImmutableMap.of("dim0", "dim1"));
Assert.assertEquals(filter2, rewrittenFilter);
expectedException.expect(IAE.class);
expectedException.expectMessage("Received a non-applicable rewrite: {invalidName=dim1}, filter's dimension: dim0");
filter.rewriteRequiredColumns(ImmutableMap.of("invalidName", "dim1"));
}
use of org.apache.druid.query.filter.LikeDimFilter in project druid by druid-io.
the class LikeOperatorConversion 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;
}
if (druidExpression.isSimpleExtraction()) {
return new LikeDimFilter(druidExpression.getSimpleExtraction().getColumn(), RexLiteral.stringValue(operands.get(1)), operands.size() > 2 ? RexLiteral.stringValue(operands.get(2)) : null, druidExpression.getSimpleExtraction().getExtractionFn());
} else if (virtualColumnRegistry != null) {
String v = virtualColumnRegistry.getOrCreateVirtualColumnForExpression(druidExpression, operands.get(0).getType());
return new LikeDimFilter(v, RexLiteral.stringValue(operands.get(1)), operands.size() > 2 ? RexLiteral.stringValue(operands.get(2)) : null, null);
} else {
return null;
}
}
Aggregations