Search in sources :

Example 11 with RegexDimExtractionFn

use of org.apache.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.

the class TopNQueryRunnerTest method testTopNDimExtraction.

@Test
public void testTopNDimExtraction() {
    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("rows").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, "s", "rows", 18L, "index", 2231.876812D, "addRowsIndexConstant", 2250.876812D, "uniques", QueryRunnerTestHelper.UNIQUES_9), ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "t", "rows", 4L, "index", 5351.814783D, "addRowsIndexConstant", 5356.814783D, "uniques", QueryRunnerTestHelper.UNIQUES_2), ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "u", "rows", 4L, "index", 4875.669692D, "addRowsIndexConstant", 4880.669692D, "uniques", QueryRunnerTestHelper.UNIQUES_2)))));
    assertExpectedResults(expectedResults, query);
}
Also used : RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) Result(org.apache.druid.query.Result) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 12 with RegexDimExtractionFn

use of org.apache.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.

the class TopNQueryRunnerTest method testInvertedTopNLexicographicDimExtractionWithPreviousStop2.

@Test
public void testInvertedTopNLexicographicDimExtractionWithPreviousStop2() {
    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("p", 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, "o", "rows", 18L, "index", 2231.876812D, "addRowsIndexConstant", 2250.876812D, "uniques", QueryRunnerTestHelper.UNIQUES_9), ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "f", "rows", 4L, "index", 4875.669692D, "addRowsIndexConstant", 4880.669692D, "uniques", QueryRunnerTestHelper.UNIQUES_2)))));
    assertExpectedResults(expectedResults, query);
}
Also used : RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) Result(org.apache.druid.query.Result) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 13 with RegexDimExtractionFn

use of org.apache.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.

the class TopNQueryRunnerTest method testTopNLexicographicDimExtraction.

@Test
public void testTopNLexicographicDimExtraction() {
    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 DimensionTopNMetricSpec(null, 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, "s", "rows", 18L, "index", 2231.876812D, "addRowsIndexConstant", 2250.876812D, "uniques", QueryRunnerTestHelper.UNIQUES_9), ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "t", "rows", 4L, "index", 5351.814783D, "addRowsIndexConstant", 5356.814783D, "uniques", QueryRunnerTestHelper.UNIQUES_2), ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "u", "rows", 4L, "index", 4875.669692D, "addRowsIndexConstant", 4880.669692D, "uniques", QueryRunnerTestHelper.UNIQUES_2)))));
    assertExpectedResults(expectedResults, query);
}
Also used : RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) Result(org.apache.druid.query.Result) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 14 with RegexDimExtractionFn

use of org.apache.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.

the class TopNQueryRunnerTest method testInvertedTopNLexicographicDimExtraction2.

@Test
public void testInvertedTopNLexicographicDimExtraction2() {
    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(null, 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, "o", "rows", 18L, "index", 2231.876812D, "addRowsIndexConstant", 2250.876812D, "uniques", QueryRunnerTestHelper.UNIQUES_9), ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "f", "rows", 4L, "index", 4875.669692D, "addRowsIndexConstant", 4880.669692D, "uniques", QueryRunnerTestHelper.UNIQUES_2)))));
    assertExpectedResults(expectedResults, query);
}
Also used : RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) Result(org.apache.druid.query.Result) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 15 with RegexDimExtractionFn

use of org.apache.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'," + " extractionFn=regex(/^([^,]*),/, 1)}";
    Assert.assertEquals(expected, new DimensionSelectorHavingSpec("gender", "m", extractionFn).toString());
    expected = "DimensionSelectorHavingSpec{" + "dimension='gender'," + " value='m'," + " extractionFn=Identity}";
    Assert.assertEquals(expected, new DimensionSelectorHavingSpec("gender", "m", null).toString());
}
Also used : ExtractionFn(org.apache.druid.query.extraction.ExtractionFn) RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) Test(org.junit.Test)

Aggregations

RegexDimExtractionFn (org.apache.druid.query.extraction.RegexDimExtractionFn)41 Test (org.junit.Test)40 ExtractionDimensionSpec (org.apache.druid.query.dimension.ExtractionDimensionSpec)15 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)13 Result (org.apache.druid.query.Result)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)5 ExtractionFn (org.apache.druid.query.extraction.ExtractionFn)5 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)4 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)4 SearchQuerySpec (org.apache.druid.query.search.SearchQuerySpec)3 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)2 RegexFilteredDimensionSpec (org.apache.druid.query.dimension.RegexFilteredDimensionSpec)2 CascadeExtractionFn (org.apache.druid.query.extraction.CascadeExtractionFn)2 DimExtractionFn (org.apache.druid.query.extraction.DimExtractionFn)2 JavaScriptExtractionFn (org.apache.druid.query.extraction.JavaScriptExtractionFn)2 SearchQuerySpecDimExtractionFn (org.apache.druid.query.extraction.SearchQuerySpecDimExtractionFn)2 StringFormatExtractionFn (org.apache.druid.query.extraction.StringFormatExtractionFn)2 StrlenExtractionFn (org.apache.druid.query.extraction.StrlenExtractionFn)2 SubstringDimExtractionFn (org.apache.druid.query.extraction.SubstringDimExtractionFn)2