use of org.apache.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.
the class TopNQueryRunnerTest method testInvertedTopNLexicographicDimExtractionWithPreviousStop.
@Test
public void testInvertedTopNLexicographicDimExtractionWithPreviousStop() {
TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.ALL_GRAN).dimension(new ExtractionDimensionSpec(QueryRunnerTestHelper.MARKET_DIMENSION, QueryRunnerTestHelper.MARKET_DIMENSION, new RegexDimExtractionFn("(.)", false, null))).metric(new InvertedTopNMetricSpec(new DimensionTopNMetricSpec("u", StringComparators.LEXICOGRAPHIC))).threshold(4).intervals(QueryRunnerTestHelper.FIRST_TO_THIRD).aggregators(commonAggregators).postAggregators(QueryRunnerTestHelper.ADD_ROWS_INDEX_CONSTANT).build();
List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<>(DateTimes.of("2011-04-01T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "t", "rows", 4L, "index", 5351.814783D, "addRowsIndexConstant", 5356.814783D, "uniques", QueryRunnerTestHelper.UNIQUES_2), ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "s", "rows", 18L, "index", 2231.876812D, "addRowsIndexConstant", 2250.876812D, "uniques", QueryRunnerTestHelper.UNIQUES_9)))));
assertExpectedResults(expectedResults, query);
}
use of org.apache.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.
the class BloomFilterAggregatorTest method testSerde.
@Test
public void testSerde() throws Exception {
BloomFilterAggregatorFactory factory = new BloomFilterAggregatorFactory("billy", new DefaultDimensionSpec("b", "b"), MAX_NUM_VALUES);
ObjectMapper objectMapper = new DefaultObjectMapper();
new BloomFilterExtensionModule().getJacksonModules().forEach(objectMapper::registerModule);
Assert.assertEquals(factory, objectMapper.readValue(objectMapper.writeValueAsString(factory), AggregatorFactory.class));
String fieldNamesOnly = "{" + "\"type\":\"bloom\"," + "\"name\":\"billy\"," + "\"field\":\"b\"," + "\"maxNumEntries\":15" + "}";
Assert.assertEquals(factory, objectMapper.readValue(fieldNamesOnly, AggregatorFactory.class));
BloomFilterAggregatorFactory factory2 = new BloomFilterAggregatorFactory("billy", new ExtractionDimensionSpec("b", "b", new RegexDimExtractionFn(".*", false, null)), MAX_NUM_VALUES);
Assert.assertEquals(factory2, objectMapper.readValue(objectMapper.writeValueAsString(factory2), AggregatorFactory.class));
BloomFilterAggregatorFactory factory3 = new BloomFilterAggregatorFactory("billy", new RegexFilteredDimensionSpec(new DefaultDimensionSpec("a", "a"), ".*"), MAX_NUM_VALUES);
Assert.assertEquals(factory3, objectMapper.readValue(objectMapper.writeValueAsString(factory3), AggregatorFactory.class));
}
use of org.apache.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.
the class SearchQueryDimFilterTest method testHashcode.
@Test
public void testHashcode() {
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.hashCode(), searchQueryDimFilter2.hashCode());
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.hashCode(), searchQueryDimFilter3.hashCode());
}
use of org.apache.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 org.apache.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.
the class SearchQueryDimFilterTest method testGetCacheKey.
@Test
public void testGetCacheKey() {
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.assertFalse(Arrays.equals(searchQueryDimFilter.getCacheKey(), searchQueryDimFilter2.getCacheKey()));
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.assertFalse(Arrays.equals(searchQueryDimFilter.getCacheKey(), searchQueryDimFilter3.getCacheKey()));
}
Aggregations