Search in sources :

Example 1 with RegexDimExtractionFn

use of org.apache.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.

the class CalciteQueryTest method testRegexpExtract.

@Test
public void testRegexpExtract() throws Exception {
    // Cannot vectorize due to extractionFn in dimension spec.
    cannotVectorize();
    testQuery("SELECT DISTINCT\n" + "  REGEXP_EXTRACT(dim1, '^.'),\n" + "  REGEXP_EXTRACT(dim1, '^(.)', 1)\n" + "FROM foo\n" + "WHERE REGEXP_EXTRACT(dim1, '^(.)', 1) <> 'x'", ImmutableList.of(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE1).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setDimFilter(not(selector("dim1", "x", new RegexDimExtractionFn("^(.)", 1, true, null)))).setDimensions(dimensions(new ExtractionDimensionSpec("dim1", "d0", new RegexDimExtractionFn("^.", 0, true, null)), new ExtractionDimensionSpec("dim1", "d1", new RegexDimExtractionFn("^(.)", 1, true, null)))).setContext(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { NULL_STRING, NULL_STRING }, new Object[] { "1", "1" }, new Object[] { "2", "2" }, new Object[] { "a", "a" }, new Object[] { "d", "d" }));
}
Also used : RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Example 2 with RegexDimExtractionFn

use of org.apache.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.

the class CalciteQueryTest method testRegexpExtractFilterViaNotNullCheck.

@Test
public void testRegexpExtractFilterViaNotNullCheck() throws Exception {
    // Cannot vectorize due to extractionFn in dimension spec.
    cannotVectorize();
    testQuery("SELECT COUNT(*)\n" + "FROM foo\n" + "WHERE REGEXP_EXTRACT(dim1, '^1') IS NOT NULL OR REGEXP_EXTRACT('Z' || dim1, '^Z2') IS NOT NULL", ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(querySegmentSpec(Filtration.eternity())).granularity(Granularities.ALL).virtualColumns(expressionVirtualColumn("v0", "regexp_extract(concat('Z',\"dim1\"),'^Z2')", ColumnType.STRING)).filters(or(not(selector("dim1", null, new RegexDimExtractionFn("^1", 0, true, null))), not(selector("v0", null, null)))).aggregators(new CountAggregatorFactory("a0")).context(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { 3L }));
}
Also used : CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) Test(org.junit.Test)

Example 3 with RegexDimExtractionFn

use of org.apache.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.

the class RegexDimFilterTest method testHashcode.

@Test
public void testHashcode() {
    RegexDimFilter regexDimFilter = new RegexDimFilter("dim", "reg", null);
    RegexDimFilter regexDimFilter2 = new RegexDimFilter("di", "mreg", null);
    RegexDimFilter regexDimFilter3 = new RegexDimFilter("di", "mreg", null);
    Assert.assertNotEquals(regexDimFilter.hashCode(), regexDimFilter2.hashCode());
    Assert.assertEquals(regexDimFilter2.hashCode(), regexDimFilter3.hashCode());
    RegexDimExtractionFn regexFn = new RegexDimExtractionFn(".*", false, null);
    RegexDimFilter regexDimFilter4 = new RegexDimFilter("dim", "reg", regexFn);
    RegexDimFilter regexDimFilter5 = new RegexDimFilter("dim", "reg", regexFn);
    Assert.assertNotEquals(regexDimFilter.hashCode(), regexDimFilter4.hashCode());
    Assert.assertEquals(regexDimFilter4.hashCode(), regexDimFilter5.hashCode());
}
Also used : RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) Test(org.junit.Test)

Example 4 with RegexDimExtractionFn

use of org.apache.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.

the class RegexDimFilterTest method testGetCacheKey.

@Test
public void testGetCacheKey() {
    RegexDimFilter regexDimFilter = new RegexDimFilter("dim", "reg", null);
    RegexDimFilter regexDimFilter2 = new RegexDimFilter("di", "mreg", null);
    Assert.assertFalse(Arrays.equals(regexDimFilter.getCacheKey(), regexDimFilter2.getCacheKey()));
    RegexDimExtractionFn regexFn = new RegexDimExtractionFn(".*", false, null);
    RegexDimFilter regexDimFilter3 = new RegexDimFilter("dim", "reg", regexFn);
    Assert.assertFalse(Arrays.equals(regexDimFilter.getCacheKey(), regexDimFilter3.getCacheKey()));
}
Also used : RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) Test(org.junit.Test)

Example 5 with RegexDimExtractionFn

use of org.apache.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.

the class RegexDimFilterTest method testEquals.

@Test
public void testEquals() {
    RegexDimFilter regexDimFilter = new RegexDimFilter("dim", "reg", null);
    RegexDimFilter regexDimFilter2 = new RegexDimFilter("di", "mreg", null);
    RegexDimFilter regexDimFilter3 = new RegexDimFilter("di", "mreg", null);
    Assert.assertNotEquals(regexDimFilter, regexDimFilter2);
    Assert.assertEquals(regexDimFilter2, regexDimFilter3);
    RegexDimExtractionFn regexFn = new RegexDimExtractionFn(".*", false, null);
    RegexDimFilter regexDimFilter4 = new RegexDimFilter("dim", "reg", regexFn);
    RegexDimFilter regexDimFilter5 = new RegexDimFilter("dim", "reg", regexFn);
    Assert.assertNotEquals(regexDimFilter, regexDimFilter4);
    Assert.assertEquals(regexDimFilter4, regexDimFilter5);
}
Also used : RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) Test(org.junit.Test)

Aggregations

RegexDimExtractionFn (org.apache.druid.query.extraction.RegexDimExtractionFn)41 Test (org.junit.Test)40 ExtractionDimensionSpec (org.apache.druid.query.dimension.ExtractionDimensionSpec)15 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)13 Result (org.apache.druid.query.Result)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)5 ExtractionFn (org.apache.druid.query.extraction.ExtractionFn)5 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)4 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)4 SearchQuerySpec (org.apache.druid.query.search.SearchQuerySpec)3 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)2 RegexFilteredDimensionSpec (org.apache.druid.query.dimension.RegexFilteredDimensionSpec)2 CascadeExtractionFn (org.apache.druid.query.extraction.CascadeExtractionFn)2 DimExtractionFn (org.apache.druid.query.extraction.DimExtractionFn)2 JavaScriptExtractionFn (org.apache.druid.query.extraction.JavaScriptExtractionFn)2 SearchQuerySpecDimExtractionFn (org.apache.druid.query.extraction.SearchQuerySpecDimExtractionFn)2 StringFormatExtractionFn (org.apache.druid.query.extraction.StringFormatExtractionFn)2 StrlenExtractionFn (org.apache.druid.query.extraction.StrlenExtractionFn)2 SubstringDimExtractionFn (org.apache.druid.query.extraction.SubstringDimExtractionFn)2