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