Search in sources :

Example 1 with SubstringDimExtractionFn

use of io.druid.query.extraction.SubstringDimExtractionFn in project druid by druid-io.

the class LikeDimFilterTest method testEqualsAndHashCode.

@Test
public void testEqualsAndHashCode() {
    final DimFilter filter = new LikeDimFilter("foo", "bar%", "@", new SubstringDimExtractionFn(1, 2));
    final DimFilter filter2 = new LikeDimFilter("foo", "bar%", "@", new SubstringDimExtractionFn(1, 2));
    final DimFilter filter3 = new LikeDimFilter("foo", "bar%", null, new SubstringDimExtractionFn(1, 2));
    Assert.assertEquals(filter, filter2);
    Assert.assertNotEquals(filter, filter3);
    Assert.assertEquals(filter.hashCode(), filter2.hashCode());
    Assert.assertNotEquals(filter.hashCode(), filter3.hashCode());
}
Also used : SubstringDimExtractionFn(io.druid.query.extraction.SubstringDimExtractionFn) Test(org.junit.Test)

Example 2 with SubstringDimExtractionFn

use of io.druid.query.extraction.SubstringDimExtractionFn in project druid by druid-io.

the class LikeDimFilterTest method testSerde.

@Test
public void testSerde() throws IOException {
    final ObjectMapper objectMapper = new DefaultObjectMapper();
    final DimFilter filter = new LikeDimFilter("foo", "bar%", "@", new SubstringDimExtractionFn(1, 2));
    final DimFilter filter2 = objectMapper.readValue(objectMapper.writeValueAsString(filter), DimFilter.class);
    Assert.assertEquals(filter, filter2);
}
Also used : SubstringDimExtractionFn(io.druid.query.extraction.SubstringDimExtractionFn) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with SubstringDimExtractionFn

use of io.druid.query.extraction.SubstringDimExtractionFn in project druid by druid-io.

the class LikeDimFilterTest method testGetCacheKey.

@Test
public void testGetCacheKey() {
    final DimFilter filter = new LikeDimFilter("foo", "bar%", "@", new SubstringDimExtractionFn(1, 2));
    final DimFilter filter2 = new LikeDimFilter("foo", "bar%", "@", new SubstringDimExtractionFn(1, 2));
    final DimFilter filter3 = new LikeDimFilter("foo", "bar%", null, new SubstringDimExtractionFn(1, 2));
    Assert.assertArrayEquals(filter.getCacheKey(), filter2.getCacheKey());
    Assert.assertFalse(Arrays.equals(filter.getCacheKey(), filter3.getCacheKey()));
}
Also used : SubstringDimExtractionFn(io.druid.query.extraction.SubstringDimExtractionFn) Test(org.junit.Test)

Example 4 with SubstringDimExtractionFn

use of io.druid.query.extraction.SubstringDimExtractionFn in project druid by druid-io.

the class SearchBenchmark method basicC.

private static SearchQueryBuilder basicC(final BenchmarkSchemaInfo basicSchema) {
    final QuerySegmentSpec intervalSpec = new MultipleIntervalSegmentSpec(Arrays.asList(basicSchema.getDataInterval()));
    final List<String> dimUniformFilterVals = Lists.newArrayList();
    final int resultNum = (int) (100000 * 0.1);
    final int step = 100000 / resultNum;
    for (int i = 1; i < 100001 && dimUniformFilterVals.size() < resultNum; i += step) {
        dimUniformFilterVals.add(String.valueOf(i));
    }
    final String dimName = "dimUniform";
    final List<DimFilter> dimFilters = Lists.newArrayList();
    dimFilters.add(new InDimFilter(dimName, dimUniformFilterVals, IdentityExtractionFn.getInstance()));
    dimFilters.add(new SelectorDimFilter(dimName, "3", StrlenExtractionFn.instance()));
    dimFilters.add(new BoundDimFilter(dimName, "100", "10000", true, true, true, new DimExtractionFn() {

        @Override
        public byte[] getCacheKey() {
            return new byte[] { 0xF };
        }

        @Override
        public String apply(String value) {
            return String.valueOf(Long.parseLong(value) + 1);
        }

        @Override
        public boolean preservesOrdering() {
            return false;
        }

        @Override
        public ExtractionType getExtractionType() {
            return ExtractionType.ONE_TO_ONE;
        }
    }, null));
    dimFilters.add(new InDimFilter(dimName, dimUniformFilterVals, new LowerExtractionFn(null)));
    dimFilters.add(new InDimFilter(dimName, dimUniformFilterVals, new UpperExtractionFn(null)));
    dimFilters.add(new InDimFilter(dimName, dimUniformFilterVals, new SubstringDimExtractionFn(1, 3)));
    return Druids.newSearchQueryBuilder().dataSource("blah").granularity(Granularities.ALL).intervals(intervalSpec).query("").dimensions(Lists.newArrayList("dimUniform")).filters(new AndDimFilter(dimFilters));
}
Also used : BoundDimFilter(io.druid.query.filter.BoundDimFilter) AndDimFilter(io.druid.query.filter.AndDimFilter) MultipleIntervalSegmentSpec(io.druid.query.spec.MultipleIntervalSegmentSpec) SubstringDimExtractionFn(io.druid.query.extraction.SubstringDimExtractionFn) LowerExtractionFn(io.druid.query.extraction.LowerExtractionFn) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) InDimFilter(io.druid.query.filter.InDimFilter) QuerySegmentSpec(io.druid.query.spec.QuerySegmentSpec) BoundDimFilter(io.druid.query.filter.BoundDimFilter) InDimFilter(io.druid.query.filter.InDimFilter) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) DimFilter(io.druid.query.filter.DimFilter) AndDimFilter(io.druid.query.filter.AndDimFilter) DimExtractionFn(io.druid.query.extraction.DimExtractionFn) SubstringDimExtractionFn(io.druid.query.extraction.SubstringDimExtractionFn) UpperExtractionFn(io.druid.query.extraction.UpperExtractionFn)

Example 5 with SubstringDimExtractionFn

use of io.druid.query.extraction.SubstringDimExtractionFn in project druid by druid-io.

the class SubstringExtractionOperator method convert.

@Override
public RowExtraction convert(final DruidOperatorTable operatorTable, final PlannerContext plannerContext, final List<String> rowOrder, final RexNode expression) {
    final RexCall call = (RexCall) expression;
    final RowExtraction arg = Expressions.toRowExtraction(operatorTable, plannerContext, rowOrder, call.getOperands().get(0));
    if (arg == null) {
        return null;
    }
    final int index = RexLiteral.intValue(call.getOperands().get(1)) - 1;
    final Integer length;
    if (call.getOperands().size() > 2) {
        length = RexLiteral.intValue(call.getOperands().get(2));
    } else {
        length = null;
    }
    return RowExtraction.of(arg.getColumn(), ExtractionFns.compose(new SubstringDimExtractionFn(index, length), arg.getExtractionFn()));
}
Also used : RexCall(org.apache.calcite.rex.RexCall) SubstringDimExtractionFn(io.druid.query.extraction.SubstringDimExtractionFn)

Aggregations

SubstringDimExtractionFn (io.druid.query.extraction.SubstringDimExtractionFn)5 Test (org.junit.Test)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)1 DimExtractionFn (io.druid.query.extraction.DimExtractionFn)1 LowerExtractionFn (io.druid.query.extraction.LowerExtractionFn)1 UpperExtractionFn (io.druid.query.extraction.UpperExtractionFn)1 AndDimFilter (io.druid.query.filter.AndDimFilter)1 BoundDimFilter (io.druid.query.filter.BoundDimFilter)1 DimFilter (io.druid.query.filter.DimFilter)1 InDimFilter (io.druid.query.filter.InDimFilter)1 SelectorDimFilter (io.druid.query.filter.SelectorDimFilter)1 MultipleIntervalSegmentSpec (io.druid.query.spec.MultipleIntervalSegmentSpec)1 QuerySegmentSpec (io.druid.query.spec.QuerySegmentSpec)1 RexCall (org.apache.calcite.rex.RexCall)1