Search in sources :

Example 1 with LikeDimFilter

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"));
}
Also used : SubstringDimExtractionFn(org.apache.druid.query.extraction.SubstringDimExtractionFn) LikeDimFilter(org.apache.druid.query.filter.LikeDimFilter) Test(org.junit.Test)

Example 2 with LikeDimFilter

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 }));
}
Also used : OrderByColumnSpec(org.apache.druid.query.groupby.orderby.OrderByColumnSpec) DefaultLimitSpec(org.apache.druid.query.groupby.orderby.DefaultLimitSpec) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) ListFilteredVirtualColumn(org.apache.druid.segment.virtual.ListFilteredVirtualColumn) LikeDimFilter(org.apache.druid.query.filter.LikeDimFilter) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) Test(org.junit.Test)

Example 3 with LikeDimFilter

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"));
}
Also used : LikeDimFilter(org.apache.druid.query.filter.LikeDimFilter) Test(org.junit.Test)

Example 4 with LikeDimFilter

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"));
}
Also used : SubstringDimExtractionFn(org.apache.druid.query.extraction.SubstringDimExtractionFn) LikeDimFilter(org.apache.druid.query.filter.LikeDimFilter) Filter(org.apache.druid.query.filter.Filter) LikeDimFilter(org.apache.druid.query.filter.LikeDimFilter) Test(org.junit.Test)

Example 5 with LikeDimFilter

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;
    }
}
Also used : RexCall(org.apache.calcite.rex.RexCall) DruidExpression(org.apache.druid.sql.calcite.expression.DruidExpression) LikeDimFilter(org.apache.druid.query.filter.LikeDimFilter) RexNode(org.apache.calcite.rex.RexNode) Nullable(javax.annotation.Nullable)

Aggregations

LikeDimFilter (org.apache.druid.query.filter.LikeDimFilter)6 Test (org.junit.Test)5 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)2 SubstringDimExtractionFn (org.apache.druid.query.extraction.SubstringDimExtractionFn)2 DefaultLimitSpec (org.apache.druid.query.groupby.orderby.DefaultLimitSpec)2 OrderByColumnSpec (org.apache.druid.query.groupby.orderby.OrderByColumnSpec)2 Nullable (javax.annotation.Nullable)1 Parameters (junitparams.Parameters)1 RexCall (org.apache.calcite.rex.RexCall)1 RexNode (org.apache.calcite.rex.RexNode)1 GlobalTableDataSource (org.apache.druid.query.GlobalTableDataSource)1 QueryDataSource (org.apache.druid.query.QueryDataSource)1 TableDataSource (org.apache.druid.query.TableDataSource)1 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)1 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)1 Filter (org.apache.druid.query.filter.Filter)1 ListFilteredVirtualColumn (org.apache.druid.segment.virtual.ListFilteredVirtualColumn)1 DruidExpression (org.apache.druid.sql.calcite.expression.DruidExpression)1