use of io.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.
the class TopNQueryRunnerTest method testTopNLexicographicDimExtractionWithPreviousStop.
@Test
public void testTopNLexicographicDimExtractionWithPreviousStop() {
TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).dimension(new ExtractionDimensionSpec(QueryRunnerTestHelper.marketDimension, QueryRunnerTestHelper.marketDimension, new RegexDimExtractionFn("(.)", false, null))).metric(new DimensionTopNMetricSpec("s", StringComparators.LEXICOGRAPHIC)).threshold(4).intervals(QueryRunnerTestHelper.firstToThird).aggregators(QueryRunnerTestHelper.commonAggregators).postAggregators(Arrays.<PostAggregator>asList(QueryRunnerTestHelper.addRowsIndexConstant)).build();
List<Result<TopNResultValue>> expectedResults = Arrays.asList(new Result<TopNResultValue>(new DateTime("2011-04-01T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.<String, Object>of(QueryRunnerTestHelper.marketDimension, "t", "rows", 4L, "index", 5351.814697265625D, "addRowsIndexConstant", 5356.814697265625D, "uniques", QueryRunnerTestHelper.UNIQUES_2), ImmutableMap.<String, Object>of(QueryRunnerTestHelper.marketDimension, "u", "rows", 4L, "index", 4875.669677734375D, "addRowsIndexConstant", 4880.669677734375D, "uniques", QueryRunnerTestHelper.UNIQUES_2)))));
assertExpectedResults(expectedResults, query);
}
use of io.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.
the class CardinalityAggregatorTest method testSerde.
@Test
public void testSerde() throws Exception {
CardinalityAggregatorFactory factory = new CardinalityAggregatorFactory("billy", ImmutableList.<DimensionSpec>of(new DefaultDimensionSpec("b", "b"), new DefaultDimensionSpec("a", "a"), new DefaultDimensionSpec("c", "c")), true);
ObjectMapper objectMapper = new DefaultObjectMapper();
Assert.assertEquals(factory, objectMapper.readValue(objectMapper.writeValueAsString(factory), AggregatorFactory.class));
String fieldNamesOnly = "{\"type\":\"cardinality\",\"name\":\"billy\",\"fields\":[\"b\",\"a\",\"c\"],\"byRow\":true}";
Assert.assertEquals(factory, objectMapper.readValue(fieldNamesOnly, AggregatorFactory.class));
CardinalityAggregatorFactory factory2 = new CardinalityAggregatorFactory("billy", ImmutableList.<DimensionSpec>of(new ExtractionDimensionSpec("b", "b", new RegexDimExtractionFn(".*", false, null)), new RegexFilteredDimensionSpec(new DefaultDimensionSpec("a", "a"), ".*"), new DefaultDimensionSpec("c", "c")), true);
Assert.assertEquals(factory2, objectMapper.readValue(objectMapper.writeValueAsString(factory2), AggregatorFactory.class));
}
use of io.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.
the class DimensionSelectorHavingSpecTest method testGetCacheKey.
@Test
public void testGetCacheKey() {
ExtractionFn extractionFn = IdentityExtractionFn.getInstance();
byte[] dimBytes = "dimension".getBytes(Charsets.UTF_8);
byte[] valBytes = "v".getBytes(Charsets.UTF_8);
byte[] extFunKey = extractionFn.getCacheKey();
byte[] expected = ByteBuffer.allocate(3 + dimBytes.length + valBytes.length + extFunKey.length).put(CACHE_KEY).put(dimBytes).put(STRING_SEPARATOR).put(valBytes).put(STRING_SEPARATOR).put(extFunKey).array();
DimensionSelectorHavingSpec dfhs = new DimensionSelectorHavingSpec("dimension", "v", null);
DimensionSelectorHavingSpec dfhs1 = new DimensionSelectorHavingSpec("dimension", "v", null);
DimensionSelectorHavingSpec dfhs2 = new DimensionSelectorHavingSpec("dimensi", "onv", null);
byte[] actual = dfhs.getCacheKey();
Assert.assertArrayEquals(expected, actual);
Assert.assertTrue(Arrays.equals(dfhs.getCacheKey(), dfhs1.getCacheKey()));
Assert.assertFalse(Arrays.equals(dfhs.getCacheKey(), dfhs2.getCacheKey()));
extractionFn = new RegexDimExtractionFn("^([^,]*),", false, "");
extFunKey = extractionFn.getCacheKey();
dfhs = new DimensionSelectorHavingSpec("dimension", "v", extractionFn);
actual = dfhs.getCacheKey();
expected = ByteBuffer.allocate(3 + dimBytes.length + valBytes.length + extFunKey.length).put(CACHE_KEY).put(dimBytes).put(STRING_SEPARATOR).put(valBytes).put(STRING_SEPARATOR).put(extFunKey).array();
Assert.assertArrayEquals(expected, actual);
}
use of io.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.
the class DimensionSelectorHavingSpecTest method testEquals.
@Test
public void testEquals() throws Exception {
ExtractionFn extractionFn1 = new RegexDimExtractionFn("^([^,]*),", false, "");
ExtractionFn extractionFn2 = new RegexDimExtractionFn(",(.*)", false, "");
ExtractionFn extractionFn3 = new RegexDimExtractionFn("^([^,]*),", false, "");
HavingSpec dimHavingSpec1 = new DimensionSelectorHavingSpec("dim", "v", extractionFn1);
HavingSpec dimHavingSpec2 = new DimensionSelectorHavingSpec("dim", "v", extractionFn3);
HavingSpec dimHavingSpec3 = new DimensionSelectorHavingSpec("dim1", "v", null);
HavingSpec dimHavingSpec4 = new DimensionSelectorHavingSpec("dim2", "v", null);
HavingSpec dimHavingSpec5 = new DimensionSelectorHavingSpec("dim", "v1", null);
HavingSpec dimHavingSpec6 = new DimensionSelectorHavingSpec("dim", "v2", null);
HavingSpec dimHavingSpec7 = new DimensionSelectorHavingSpec("dim", null, null);
HavingSpec dimHavingSpec8 = new DimensionSelectorHavingSpec("dim", null, null);
HavingSpec dimHavingSpec9 = new DimensionSelectorHavingSpec("dim1", null, null);
HavingSpec dimHavingSpec10 = new DimensionSelectorHavingSpec("dim2", null, null);
HavingSpec dimHavingSpec11 = new DimensionSelectorHavingSpec("dim1", "v", null);
HavingSpec dimHavingSpec12 = new DimensionSelectorHavingSpec("dim2", null, null);
HavingSpec dimHavingSpec13 = new DimensionSelectorHavingSpec("dim", "value", extractionFn1);
HavingSpec dimHavingSpec14 = new DimensionSelectorHavingSpec("dim", "value", extractionFn2);
assertEquals(dimHavingSpec1, dimHavingSpec2);
assertNotEquals(dimHavingSpec3, dimHavingSpec4);
assertNotEquals(dimHavingSpec5, dimHavingSpec6);
assertEquals(dimHavingSpec7, dimHavingSpec8);
assertNotEquals(dimHavingSpec9, dimHavingSpec10);
assertNotEquals(dimHavingSpec11, dimHavingSpec12);
assertNotEquals(dimHavingSpec13, dimHavingSpec14);
}
use of io.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.
the class DimensionSelectorHavingSpecTest method testToString.
@Test
public void testToString() {
ExtractionFn extractionFn = new RegexDimExtractionFn("^([^,]*),", false, "");
String expected = "DimensionSelectorHavingSpec{" + "dimension='gender'," + " value='m'," + " extractionFunction='regex(^([^,]*),)'}";
Assert.assertEquals(new DimensionSelectorHavingSpec("gender", "m", extractionFn).toString(), expected);
expected = "DimensionSelectorHavingSpec{" + "dimension='gender'," + " value='m'," + " extractionFunction='Identity'}";
Assert.assertEquals(new DimensionSelectorHavingSpec("gender", "m", null).toString(), expected);
}
Aggregations