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