use of org.apache.druid.query.filter.RegexDimFilter in project druid by druid-io.
the class DummyStringVirtualColumnTest method testGroupByWithRegexFilter.
private void testGroupByWithRegexFilter(List<Segment> segments, boolean enableRowBasedMethods, boolean enableColumnBasedMethods, boolean enableBitmaps, boolean disableValueMatchers) {
GroupByQuery query = new GroupByQuery.Builder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setGranularity(Granularities.ALL).setVirtualColumns(new DummyStringVirtualColumn(QueryRunnerTestHelper.MARKET_DIMENSION, VSTRING_DIM, enableRowBasedMethods, enableColumnBasedMethods, enableBitmaps, disableValueMatchers)).addDimension(VSTRING_DIM).setAggregatorSpecs(new CountAggregatorFactory(COUNT)).setInterval("2000/2030").addOrderByColumn(VSTRING_DIM).setDimFilter(new RegexDimFilter(VSTRING_DIM, "(spot)|(upfront)", null)).build();
List<ResultRow> rows = groupByTestHelper.runQueryOnSegmentsObjs(segments, query).toList();
List<ResultRow> expectedRows = Arrays.asList(GroupByQueryRunnerTestHelper.createExpectedRow(query, "2000", COUNT, 1674L, VSTRING_DIM, "spot"), GroupByQueryRunnerTestHelper.createExpectedRow(query, "2000", COUNT, 372L, VSTRING_DIM, "upfront"));
TestHelper.assertExpectedObjects(expectedRows, rows, "failed");
}
use of org.apache.druid.query.filter.RegexDimFilter in project druid by druid-io.
the class FilteredAggregatorTest method testAggregateWithExtractionFns.
@Test
public void testAggregateWithExtractionFns() {
final float[] values = { 0.15f, 0.27f };
TestFloatColumnSelector selector;
FilteredAggregatorFactory factory;
String extractionJsFn = "function(str) { return str + 'AARDVARK'; }";
ExtractionFn extractionFn = new JavaScriptExtractionFn(extractionJsFn, false, JavaScriptConfig.getEnabledInstance());
factory = new FilteredAggregatorFactory(new DoubleSumAggregatorFactory("billy", "value"), new SelectorDimFilter("dim", "aAARDVARK", extractionFn));
selector = new TestFloatColumnSelector(values);
validateFilteredAggs(factory, values, selector);
factory = new FilteredAggregatorFactory(new DoubleSumAggregatorFactory("billy", "value"), new InDimFilter("dim", Arrays.asList("NOT-aAARDVARK", "FOOBAR", "aAARDVARK"), extractionFn));
selector = new TestFloatColumnSelector(values);
validateFilteredAggs(factory, values, selector);
factory = new FilteredAggregatorFactory(new DoubleSumAggregatorFactory("billy", "value"), new BoundDimFilter("dim", "aAARDVARK", "aAARDVARK", false, false, true, extractionFn, StringComparators.ALPHANUMERIC));
selector = new TestFloatColumnSelector(values);
validateFilteredAggs(factory, values, selector);
factory = new FilteredAggregatorFactory(new DoubleSumAggregatorFactory("billy", "value"), new RegexDimFilter("dim", "aAARDVARK", extractionFn));
selector = new TestFloatColumnSelector(values);
validateFilteredAggs(factory, values, selector);
factory = new FilteredAggregatorFactory(new DoubleSumAggregatorFactory("billy", "value"), new SearchQueryDimFilter("dim", new ContainsSearchQuerySpec("aAARDVARK", true), extractionFn));
selector = new TestFloatColumnSelector(values);
validateFilteredAggs(factory, values, selector);
String jsFn = "function(x) { return(x === 'aAARDVARK') }";
factory = new FilteredAggregatorFactory(new DoubleSumAggregatorFactory("billy", "value"), new JavaScriptDimFilter("dim", jsFn, extractionFn, JavaScriptConfig.getEnabledInstance()));
selector = new TestFloatColumnSelector(values);
validateFilteredAggs(factory, values, selector);
}
use of org.apache.druid.query.filter.RegexDimFilter in project druid by druid-io.
the class ExpressionsTest method testRegexpLikeAsFilter.
@Test
public void testRegexpLikeAsFilter() {
testHelper.testFilter(new RegexpLikeOperatorConversion().calciteOperator(), ImmutableList.of(testHelper.makeInputRef("s"), testHelper.makeLiteral("f.")), Collections.emptyList(), new RegexDimFilter("s", "f.", null), true);
testHelper.testFilter(new RegexpLikeOperatorConversion().calciteOperator(), ImmutableList.of(testHelper.makeInputRef("s"), testHelper.makeLiteral("o")), Collections.emptyList(), // Column "s" contains an 'o', but not at the beginning, so we don't match
new RegexDimFilter("s", "o", null), true);
testHelper.testFilter(new RegexpLikeOperatorConversion().calciteOperator(), ImmutableList.of(testHelper.makeInputRef("s"), testHelper.makeLiteral("x.")), Collections.emptyList(), new RegexDimFilter("s", "x.", null), false);
testHelper.testFilter(new RegexpLikeOperatorConversion().calciteOperator(), ImmutableList.of(testHelper.makeInputRef("s"), testHelper.makeLiteral("")), Collections.emptyList(), new RegexDimFilter("s", "", null), true);
testHelper.testFilter(new RegexpLikeOperatorConversion().calciteOperator(), ImmutableList.of(testHelper.makeInputRef("newliney"), testHelper.makeLiteral("^beep$")), Collections.emptyList(), new RegexDimFilter("newliney", "^beep$", null), false);
testHelper.testFilter(new RegexpLikeOperatorConversion().calciteOperator(), ImmutableList.of(testHelper.makeInputRef("newliney"), testHelper.makeLiteral("^beep\\nboop$")), Collections.emptyList(), new RegexDimFilter("newliney", "^beep\\nboop$", null), true);
testHelper.testFilter(new RegexpLikeOperatorConversion().calciteOperator(), ImmutableList.of(testHelper.makeCall(SqlStdOperatorTable.CONCAT, testHelper.makeLiteral("Z"), testHelper.makeInputRef("s")), testHelper.makeLiteral("x(.)")), ImmutableList.of(new ExpressionVirtualColumn("v0", "concat('Z',\"s\")", ColumnType.STRING, TestExprMacroTable.INSTANCE)), new RegexDimFilter("v0", "x(.)", null), false);
}
use of org.apache.druid.query.filter.RegexDimFilter in project druid by druid-io.
the class RegexpLikeOperatorConversion method toDruidFilter.
@Nullable
@Override
public DimFilter toDruidFilter(final PlannerContext plannerContext, final RowSignature rowSignature, @Nullable final VirtualColumnRegistry virtualColumnRegistry, final 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 pattern = RexLiteral.stringValue(operands.get(1));
if (druidExpression.isSimpleExtraction()) {
return new RegexDimFilter(druidExpression.getSimpleExtraction().getColumn(), pattern, druidExpression.getSimpleExtraction().getExtractionFn(), null);
} else if (virtualColumnRegistry != null) {
String v = virtualColumnRegistry.getOrCreateVirtualColumnForExpression(druidExpression, operands.get(0).getType());
return new RegexDimFilter(v, pattern, null, null);
} else {
return null;
}
}
Aggregations