use of io.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.
the class DimensionSelectorHavingSpecTest method testDimensionFilterSpec.
@Test
public void testDimensionFilterSpec() {
DimensionSelectorHavingSpec spec = new DimensionSelectorHavingSpec("dimension", "v", null);
assertTrue(spec.eval(getTestRow("v")));
assertTrue(spec.eval(getTestRow(ImmutableList.of("v", "v1"))));
assertFalse(spec.eval(getTestRow(ImmutableList.of())));
assertFalse(spec.eval(getTestRow("v1")));
spec = new DimensionSelectorHavingSpec("dimension", null, null);
assertTrue(spec.eval(getTestRow(ImmutableList.of())));
assertTrue(spec.eval(getTestRow(ImmutableList.of(""))));
assertFalse(spec.eval(getTestRow(ImmutableList.of("v"))));
assertFalse(spec.eval(getTestRow(ImmutableList.of("v", "v1"))));
spec = new DimensionSelectorHavingSpec("dimension", "", null);
assertTrue(spec.eval(getTestRow(ImmutableList.of())));
assertTrue(spec.eval(getTestRow(ImmutableList.of(""))));
assertTrue(spec.eval(getTestRow(ImmutableList.of("v", "v1", ""))));
assertFalse(spec.eval(getTestRow(ImmutableList.of("v"))));
assertFalse(spec.eval(getTestRow(ImmutableList.of("v", "v1"))));
ExtractionFn extractionFn = new RegexDimExtractionFn("^([^,]*),", true, "default");
spec = new DimensionSelectorHavingSpec("dimension", "v", extractionFn);
assertTrue(spec.eval(getTestRow(ImmutableList.of("v,v1", "v2,v3"))));
assertFalse(spec.eval(getTestRow(ImmutableList.of("v1,v4"))));
assertFalse(spec.eval(getTestRow(ImmutableList.of("v"))));
assertFalse(spec.eval(getTestRow(ImmutableList.of("v1", "default"))));
assertTrue(spec.eval(getTestRow(ImmutableList.of("v,default", "none"))));
spec = new DimensionSelectorHavingSpec("dimension", "default", extractionFn);
assertTrue(spec.eval(getTestRow(ImmutableList.of("v1,v2", "none"))));
}
use of io.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.
the class GroupByQueryRunnerTest method testGroupByWithEmptyStringProducingDimExtractionFn.
@Test
@Ignore
public /**
* This test exists only to show what the current behavior is and not necessarily to define that this is
* correct behavior. In fact, the behavior when returning the empty string from a DimExtractionFn is, by
* contract, undefined, so this can do anything.
*/
void testGroupByWithEmptyStringProducingDimExtractionFn() {
final ExtractionFn emptyStringExtractionFn = new RegexDimExtractionFn("(\\w{1})", false, null) {
@Override
public byte[] getCacheKey() {
return new byte[] { (byte) 0xFF };
}
@Override
public String apply(String dimValue) {
return dimValue.equals("mezzanine") ? "" : super.apply(dimValue);
}
};
GroupByQuery query = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.dataSource).setQuerySegmentSpec(QueryRunnerTestHelper.firstToThird).setAggregatorSpecs(Arrays.asList(QueryRunnerTestHelper.rowsCount, new LongSumAggregatorFactory("idx", "index"))).setGranularity(QueryRunnerTestHelper.dayGran).setDimensions(Lists.<DimensionSpec>newArrayList(new ExtractionDimensionSpec("quality", "alias", emptyStringExtractionFn))).build();
List<Row> expectedResults = Arrays.asList(GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "", "rows", 3L, "idx", 2870L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "a", "rows", 1L, "idx", 135L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "b", "rows", 1L, "idx", 118L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "e", "rows", 1L, "idx", 158L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "h", "rows", 1L, "idx", 120L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "n", "rows", 1L, "idx", 121L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "p", "rows", 3L, "idx", 2900L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "t", "rows", 2L, "idx", 197L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "", "rows", 3L, "idx", 2447L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "a", "rows", 1L, "idx", 147L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "b", "rows", 1L, "idx", 112L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "e", "rows", 1L, "idx", 166L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "h", "rows", 1L, "idx", 113L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "n", "rows", 1L, "idx", 114L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "p", "rows", 3L, "idx", 2505L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "t", "rows", 2L, "idx", 223L));
TestHelper.assertExpectedObjects(expectedResults, GroupByQueryRunnerTestHelper.runQuery(factory, runner, query), "");
}
use of io.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 io.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.
the class SearchQueryDimFilterTest method testEquals.
@Test
public void testEquals() {
SearchQueryDimFilter searchQueryDimFilter = new SearchQueryDimFilter("dim", new SearchQuerySpec() {
@Override
public boolean accept(String dimVal) {
return false;
}
@Override
public byte[] getCacheKey() {
return StringUtils.toUtf8("value");
}
}, null);
SearchQueryDimFilter searchQueryDimFilter2 = new SearchQueryDimFilter("di", new SearchQuerySpec() {
@Override
public boolean accept(String dimVal) {
return false;
}
@Override
public byte[] getCacheKey() {
return StringUtils.toUtf8("mvalue");
}
}, null);
Assert.assertNotEquals(searchQueryDimFilter, searchQueryDimFilter2);
RegexDimExtractionFn regexFn = new RegexDimExtractionFn(".*", false, null);
SearchQueryDimFilter searchQueryDimFilter3 = new SearchQueryDimFilter("dim", new SearchQuerySpec() {
@Override
public boolean accept(String dimVal) {
return false;
}
@Override
public byte[] getCacheKey() {
return StringUtils.toUtf8("value");
}
}, regexFn);
Assert.assertNotEquals(searchQueryDimFilter, searchQueryDimFilter3);
}
use of io.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.
the class SelectorDimFilterTest method testGetCacheKey.
@Test
public void testGetCacheKey() {
SelectorDimFilter selectorDimFilter = new SelectorDimFilter("abc", "d", null);
SelectorDimFilter selectorDimFilter2 = new SelectorDimFilter("ab", "cd", null);
Assert.assertFalse(Arrays.equals(selectorDimFilter.getCacheKey(), selectorDimFilter2.getCacheKey()));
RegexDimExtractionFn regexFn = new RegexDimExtractionFn(".*", false, null);
SelectorDimFilter selectorDimFilter3 = new SelectorDimFilter("abc", "d", regexFn);
Assert.assertFalse(Arrays.equals(selectorDimFilter.getCacheKey(), selectorDimFilter3.getCacheKey()));
}
Aggregations