Search in sources :

Example 16 with RegexDimExtractionFn

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);
}
Also used : HyperUniqueFinalizingPostAggregator(io.druid.query.aggregation.hyperloglog.HyperUniqueFinalizingPostAggregator) PostAggregator(io.druid.query.aggregation.PostAggregator) DateTime(org.joda.time.DateTime) Result(io.druid.query.Result) RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Example 17 with RegexDimExtractionFn

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));
}
Also used : RegexFilteredDimensionSpec(io.druid.query.dimension.RegexFilteredDimensionSpec) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) AggregatorFactory(io.druid.query.aggregation.AggregatorFactory) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Example 18 with RegexDimExtractionFn

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);
}
Also used : ExtractionFn(io.druid.query.extraction.ExtractionFn) RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) IdentityExtractionFn(io.druid.query.extraction.IdentityExtractionFn) RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) Test(org.junit.Test)

Example 19 with RegexDimExtractionFn

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);
}
Also used : ExtractionFn(io.druid.query.extraction.ExtractionFn) RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) IdentityExtractionFn(io.druid.query.extraction.IdentityExtractionFn) RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) Test(org.junit.Test)

Example 20 with RegexDimExtractionFn

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);
}
Also used : ExtractionFn(io.druid.query.extraction.ExtractionFn) RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) IdentityExtractionFn(io.druid.query.extraction.IdentityExtractionFn) RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) Test(org.junit.Test)

Aggregations

RegexDimExtractionFn (io.druid.query.extraction.RegexDimExtractionFn)35 Test (org.junit.Test)35 ExtractionDimensionSpec (io.druid.query.dimension.ExtractionDimensionSpec)11 Result (io.druid.query.Result)7 PostAggregator (io.druid.query.aggregation.PostAggregator)7 HyperUniqueFinalizingPostAggregator (io.druid.query.aggregation.hyperloglog.HyperUniqueFinalizingPostAggregator)7 DateTime (org.joda.time.DateTime)7 ExtractionFn (io.druid.query.extraction.ExtractionFn)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)4 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)4 RegexFilteredDimensionSpec (io.druid.query.dimension.RegexFilteredDimensionSpec)4 IdentityExtractionFn (io.druid.query.extraction.IdentityExtractionFn)4 Row (io.druid.data.input.Row)3 LongSumAggregatorFactory (io.druid.query.aggregation.LongSumAggregatorFactory)3 DimensionSpec (io.druid.query.dimension.DimensionSpec)3 ListFilteredDimensionSpec (io.druid.query.dimension.ListFilteredDimensionSpec)3 SearchQuerySpec (io.druid.query.search.search.SearchQuerySpec)3 CascadeExtractionFn (io.druid.query.extraction.CascadeExtractionFn)2 DimExtractionFn (io.druid.query.extraction.DimExtractionFn)2