Search in sources :

Example 11 with ContainsSearchQuerySpec

use of org.apache.druid.query.search.ContainsSearchQuerySpec in project druid by druid-io.

the class TimeFilteringTest method testTimeFilterAsLong.

@Test
public void testTimeFilterAsLong() {
    assertFilterMatches(new SelectorDimFilter(ColumnHolder.TIME_COLUMN_NAME, "0", null), ImmutableList.of("0"));
    assertFilterMatches(new SelectorDimFilter(ColumnHolder.TIME_COLUMN_NAME, "9000", null), ImmutableList.of());
    assertFilterMatches(new BoundDimFilter(ColumnHolder.TIME_COLUMN_NAME, "0", "4", false, false, null, null, StringComparators.NUMERIC), ImmutableList.of("0", "1", "2", "3", "4"));
    assertFilterMatches(new BoundDimFilter(ColumnHolder.TIME_COLUMN_NAME, "0", "4", true, true, null, null, StringComparators.NUMERIC), ImmutableList.of("1", "2", "3"));
    assertFilterMatches(new InDimFilter(ColumnHolder.TIME_COLUMN_NAME, Arrays.asList("2", "4", "8"), null), ImmutableList.of("2", "4"));
    // cross the hashing threshold to test hashset implementation, filter on even values
    List<String> infilterValues = new ArrayList<>(NUM_FILTER_VALUES);
    for (int i = 0; i < NUM_FILTER_VALUES; i++) {
        infilterValues.add(String.valueOf(i * 2));
    }
    assertFilterMatches(new InDimFilter(ColumnHolder.TIME_COLUMN_NAME, infilterValues, null), ImmutableList.of("0", "2", "4"));
    String jsFn = "function(x) { return(x === 3 || x === 5) }";
    assertFilterMatchesSkipVectorize(new JavaScriptDimFilter(ColumnHolder.TIME_COLUMN_NAME, jsFn, null, JavaScriptConfig.getEnabledInstance()), ImmutableList.of("3", "5"));
    assertFilterMatches(new RegexDimFilter(ColumnHolder.TIME_COLUMN_NAME, "4", null), ImmutableList.of("4"));
    assertFilterMatches(new SearchQueryDimFilter(ColumnHolder.TIME_COLUMN_NAME, new ContainsSearchQuerySpec("2", true), null), ImmutableList.of("2"));
}
Also used : RegexDimFilter(org.apache.druid.query.filter.RegexDimFilter) BoundDimFilter(org.apache.druid.query.filter.BoundDimFilter) ContainsSearchQuerySpec(org.apache.druid.query.search.ContainsSearchQuerySpec) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) InDimFilter(org.apache.druid.query.filter.InDimFilter) ArrayList(java.util.ArrayList) SearchQueryDimFilter(org.apache.druid.query.filter.SearchQueryDimFilter) JavaScriptDimFilter(org.apache.druid.query.filter.JavaScriptDimFilter) Test(org.junit.Test)

Example 12 with ContainsSearchQuerySpec

use of org.apache.druid.query.search.ContainsSearchQuerySpec in project druid by druid-io.

the class LongFilteringTest method testLongColumnFiltering.

@Test
public void testLongColumnFiltering() {
    assertFilterMatches(new SelectorDimFilter(LONG_COLUMN, "0", null), ImmutableList.of());
    assertFilterMatches(new SelectorDimFilter(LONG_COLUMN, "3", null), ImmutableList.of("3"));
    assertFilterMatches(new SelectorDimFilter(LONG_COLUMN, "3.0", null), ImmutableList.of("3"));
    assertFilterMatches(new SelectorDimFilter(LONG_COLUMN, "3.00000000000000000000001", null), ImmutableList.of());
    assertFilterMatches(new SelectorDimFilter(LONG_COLUMN, "100000001.0", null), ImmutableList.of("8"));
    assertFilterMatches(new SelectorDimFilter(LONG_COLUMN, "-100000001.0", null), ImmutableList.of("10"));
    assertFilterMatches(new SelectorDimFilter(LONG_COLUMN, "111119223372036854775807.674398674398", null), ImmutableList.of());
    assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "2", "5", false, false, null, null, StringComparators.NUMERIC), ImmutableList.of("2", "3", "4", "5"));
    assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "1", "4", true, true, null, null, StringComparators.NUMERIC), ImmutableList.of("2", "3"));
    assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "2.0", "5.0", false, false, null, null, StringComparators.NUMERIC), ImmutableList.of("2", "3", "4", "5"));
    assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "2.0", "5.0", true, true, null, null, StringComparators.NUMERIC), ImmutableList.of("3", "4"));
    assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "1.9", "5.9", true, true, null, null, StringComparators.NUMERIC), ImmutableList.of("2", "3", "4", "5"));
    assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "2.1", "5.9", false, false, null, null, StringComparators.NUMERIC), ImmutableList.of("3", "4", "5"));
    assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "111119223372036854775807.67", "5.9", false, false, null, null, StringComparators.NUMERIC), ImmutableList.of());
    assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "-111119223372036854775807.67", "5.9", false, false, null, null, StringComparators.NUMERIC), ImmutableList.of("1", "2", "3", "4", "5", "9", "10"));
    assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "2.1", "111119223372036854775807.67", false, false, null, null, StringComparators.NUMERIC), ImmutableList.of("3", "4", "5", "6", "7", "8"));
    assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "2.1", "-111119223372036854775807.67", false, false, null, null, StringComparators.NUMERIC), ImmutableList.of());
    assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "100000000.0", "100000001.0", true, true, null, null, StringComparators.NUMERIC), ImmutableList.of());
    assertFilterMatches(new BoundDimFilter(LONG_COLUMN, "100000000.0", "100000001.0", false, false, null, null, StringComparators.NUMERIC), ImmutableList.of("7", "8"));
    assertFilterMatches(new InDimFilter(LONG_COLUMN, Arrays.asList("2", "4", "8"), null), ImmutableList.of("2", "4"));
    assertFilterMatches(new InDimFilter(LONG_COLUMN, Arrays.asList("1.999999999999999999", "4.00000000000000000000001"), null), ImmutableList.of());
    assertFilterMatches(new InDimFilter(LONG_COLUMN, Arrays.asList("100000001.0", "99999999.999999999"), null), ImmutableList.of("8"));
    assertFilterMatches(new InDimFilter(LONG_COLUMN, Arrays.asList("-25.0", "-99999999.999999999"), null), ImmutableList.of("9"));
    // cross the hashing threshold to test hashset implementation, filter on even values
    List<String> infilterValues = new ArrayList<>(NUM_FILTER_VALUES);
    for (int i = 0; i < NUM_FILTER_VALUES; i++) {
        infilterValues.add(String.valueOf(i * 2));
    }
    assertFilterMatches(new InDimFilter(LONG_COLUMN, infilterValues, null), ImmutableList.of("2", "4", "6"));
    String jsFn = "function(x) { return(x === 3 || x === 5) }";
    assertFilterMatchesSkipVectorize(new JavaScriptDimFilter(LONG_COLUMN, jsFn, null, JavaScriptConfig.getEnabledInstance()), ImmutableList.of("3", "5"));
    assertFilterMatches(new RegexDimFilter(LONG_COLUMN, "4", null), ImmutableList.of("4"));
    assertFilterMatches(new SearchQueryDimFilter(LONG_COLUMN, new ContainsSearchQuerySpec("2", true), null), ImmutableList.of("2", "9"));
}
Also used : RegexDimFilter(org.apache.druid.query.filter.RegexDimFilter) BoundDimFilter(org.apache.druid.query.filter.BoundDimFilter) ContainsSearchQuerySpec(org.apache.druid.query.search.ContainsSearchQuerySpec) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) InDimFilter(org.apache.druid.query.filter.InDimFilter) ArrayList(java.util.ArrayList) SearchQueryDimFilter(org.apache.druid.query.filter.SearchQueryDimFilter) JavaScriptDimFilter(org.apache.druid.query.filter.JavaScriptDimFilter) Test(org.junit.Test)

Example 13 with ContainsSearchQuerySpec

use of org.apache.druid.query.search.ContainsSearchQuerySpec 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);
}
Also used : RegexDimFilter(org.apache.druid.query.filter.RegexDimFilter) BoundDimFilter(org.apache.druid.query.filter.BoundDimFilter) ContainsSearchQuerySpec(org.apache.druid.query.search.ContainsSearchQuerySpec) JavaScriptExtractionFn(org.apache.druid.query.extraction.JavaScriptExtractionFn) ExtractionFn(org.apache.druid.query.extraction.ExtractionFn) JavaScriptExtractionFn(org.apache.druid.query.extraction.JavaScriptExtractionFn) SelectorDimFilter(org.apache.druid.query.filter.SelectorDimFilter) InDimFilter(org.apache.druid.query.filter.InDimFilter) SearchQueryDimFilter(org.apache.druid.query.filter.SearchQueryDimFilter) JavaScriptDimFilter(org.apache.druid.query.filter.JavaScriptDimFilter) Test(org.junit.Test)

Example 14 with ContainsSearchQuerySpec

use of org.apache.druid.query.search.ContainsSearchQuerySpec in project druid by druid-io.

the class ExpressionsTest method testContainsAsFilter.

@Test
public void testContainsAsFilter() {
    testHelper.testFilter(ContainsOperatorConversion.caseSensitive().calciteOperator(), ImmutableList.of(testHelper.makeInputRef("spacey"), testHelper.makeLiteral("there")), Collections.emptyList(), new SearchQueryDimFilter("spacey", new ContainsSearchQuerySpec("there", true), null), true);
    testHelper.testFilter(ContainsOperatorConversion.caseSensitive().calciteOperator(), ImmutableList.of(testHelper.makeInputRef("spacey"), testHelper.makeLiteral("There")), Collections.emptyList(), new SearchQueryDimFilter("spacey", new ContainsSearchQuerySpec("There", true), null), false);
    testHelper.testFilter(ContainsOperatorConversion.caseInsensitive().calciteOperator(), ImmutableList.of(testHelper.makeInputRef("spacey"), testHelper.makeLiteral("There")), Collections.emptyList(), new SearchQueryDimFilter("spacey", new ContainsSearchQuerySpec("There", false), null), true);
    testHelper.testFilter(ContainsOperatorConversion.caseSensitive().calciteOperator(), ImmutableList.of(testHelper.makeCall(SqlStdOperatorTable.CONCAT, testHelper.makeLiteral("what is"), testHelper.makeInputRef("spacey")), testHelper.makeLiteral("what")), ImmutableList.of(new ExpressionVirtualColumn("v0", "concat('what is',\"spacey\")", ColumnType.STRING, TestExprMacroTable.INSTANCE)), new SearchQueryDimFilter("v0", new ContainsSearchQuerySpec("what", true), null), true);
    testHelper.testFilter(ContainsOperatorConversion.caseSensitive().calciteOperator(), ImmutableList.of(testHelper.makeCall(SqlStdOperatorTable.CONCAT, testHelper.makeLiteral("what is"), testHelper.makeInputRef("spacey")), testHelper.makeLiteral("there")), ImmutableList.of(new ExpressionVirtualColumn("v0", "concat('what is',\"spacey\")", ColumnType.STRING, TestExprMacroTable.INSTANCE)), new SearchQueryDimFilter("v0", new ContainsSearchQuerySpec("there", true), null), true);
    testHelper.testFilter(ContainsOperatorConversion.caseInsensitive().calciteOperator(), ImmutableList.of(testHelper.makeCall(SqlStdOperatorTable.CONCAT, testHelper.makeLiteral("what is"), testHelper.makeInputRef("spacey")), testHelper.makeLiteral("What")), ImmutableList.of(new ExpressionVirtualColumn("v0", "concat('what is',\"spacey\")", ColumnType.STRING, TestExprMacroTable.INSTANCE)), new SearchQueryDimFilter("v0", new ContainsSearchQuerySpec("What", false), null), true);
    testHelper.testFilter(ContainsOperatorConversion.caseSensitive().calciteOperator(), ImmutableList.of(testHelper.makeInputRef("spacey"), testHelper.makeLiteral("")), Collections.emptyList(), new SearchQueryDimFilter("spacey", new ContainsSearchQuerySpec("", true), null), true);
}
Also used : ExpressionVirtualColumn(org.apache.druid.segment.virtual.ExpressionVirtualColumn) ContainsSearchQuerySpec(org.apache.druid.query.search.ContainsSearchQuerySpec) SearchQueryDimFilter(org.apache.druid.query.filter.SearchQueryDimFilter) Test(org.junit.Test)

Example 15 with ContainsSearchQuerySpec

use of org.apache.druid.query.search.ContainsSearchQuerySpec in project druid by druid-io.

the class ContainsOperatorConversion 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;
    }
    final String search = RexLiteral.stringValue(operands.get(1));
    final SearchQuerySpec spec = new ContainsSearchQuerySpec(search, caseSensitive);
    if (druidExpression.isSimpleExtraction()) {
        return new SearchQueryDimFilter(druidExpression.getSimpleExtraction().getColumn(), spec, druidExpression.getSimpleExtraction().getExtractionFn(), null);
    } else if (virtualColumnRegistry != null) {
        String v = virtualColumnRegistry.getOrCreateVirtualColumnForExpression(druidExpression, operands.get(0).getType());
        return new SearchQueryDimFilter(v, spec, null, null);
    } else {
        return null;
    }
}
Also used : RexCall(org.apache.calcite.rex.RexCall) SearchQuerySpec(org.apache.druid.query.search.SearchQuerySpec) ContainsSearchQuerySpec(org.apache.druid.query.search.ContainsSearchQuerySpec) DruidExpression(org.apache.druid.sql.calcite.expression.DruidExpression) ContainsSearchQuerySpec(org.apache.druid.query.search.ContainsSearchQuerySpec) SearchQueryDimFilter(org.apache.druid.query.filter.SearchQueryDimFilter) RexNode(org.apache.calcite.rex.RexNode) Nullable(javax.annotation.Nullable)

Aggregations

ContainsSearchQuerySpec (org.apache.druid.query.search.ContainsSearchQuerySpec)15 SearchQueryDimFilter (org.apache.druid.query.filter.SearchQueryDimFilter)14 BoundDimFilter (org.apache.druid.query.filter.BoundDimFilter)12 InDimFilter (org.apache.druid.query.filter.InDimFilter)12 RegexDimFilter (org.apache.druid.query.filter.RegexDimFilter)12 JavaScriptDimFilter (org.apache.druid.query.filter.JavaScriptDimFilter)11 Test (org.junit.Test)10 SelectorDimFilter (org.apache.druid.query.filter.SelectorDimFilter)9 ArrayList (java.util.ArrayList)6 LookupExtractionFn (org.apache.druid.query.lookup.LookupExtractionFn)6 HashMap (java.util.HashMap)4 MapLookupExtractor (org.apache.druid.query.extraction.MapLookupExtractor)4 OrDimFilter (org.apache.druid.query.filter.OrDimFilter)4 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)3 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)3 ExtractionFn (org.apache.druid.query.extraction.ExtractionFn)3 JavaScriptExtractionFn (org.apache.druid.query.extraction.JavaScriptExtractionFn)3 DimFilter (org.apache.druid.query.filter.DimFilter)3 LookupExtractor (org.apache.druid.query.lookup.LookupExtractor)3 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)3