Search in sources :

Example 6 with DimExtractionFn

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

the class TopNQueryRunnerTest method testTopNWithNullProducingDimExtractionFn.

@Test
public void testTopNWithNullProducingDimExtractionFn() {
    final ExtractionFn nullStringDimExtraction = new DimExtractionFn() {

        @Override
        public byte[] getCacheKey() {
            return new byte[] { (byte) 0xFF };
        }

        @Override
        public String apply(String dimValue) {
            return "total_market".equals(dimValue) ? null : dimValue;
        }

        @Override
        public boolean preservesOrdering() {
            return false;
        }

        @Override
        public ExtractionType getExtractionType() {
            return ExtractionType.MANY_TO_ONE;
        }
    };
    final TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.ALL_GRAN).metric("rows").threshold(4).intervals(QueryRunnerTestHelper.FIRST_TO_THIRD).aggregators(commonAggregators).postAggregators(QueryRunnerTestHelper.ADD_ROWS_INDEX_CONSTANT).dimension(new ExtractionDimensionSpec(QueryRunnerTestHelper.MARKET_DIMENSION, QueryRunnerTestHelper.MARKET_DIMENSION, nullStringDimExtraction)).build();
    List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<>(DateTimes.of("2011-04-01T00:00:00.000Z"), new TopNResultValue(Arrays.asList(ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "spot", "rows", 18L, "index", 2231.876812D, "addRowsIndexConstant", 2250.876812D, "uniques", QueryRunnerTestHelper.UNIQUES_9), QueryRunnerTestHelper.orderedMap(QueryRunnerTestHelper.MARKET_DIMENSION, null, "rows", 4L, "index", 5351.814783D, "addRowsIndexConstant", 5356.814783D, "uniques", QueryRunnerTestHelper.UNIQUES_2), ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "upfront", "rows", 4L, "index", 4875.669692D, "addRowsIndexConstant", 4880.669692D, "uniques", QueryRunnerTestHelper.UNIQUES_2)))));
    assertExpectedResults(expectedResults, query);
}
Also used : ExtractionFn(org.apache.druid.query.extraction.ExtractionFn) DimExtractionFn(org.apache.druid.query.extraction.DimExtractionFn) RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) StringFormatExtractionFn(org.apache.druid.query.extraction.StringFormatExtractionFn) JavaScriptExtractionFn(org.apache.druid.query.extraction.JavaScriptExtractionFn) LookupExtractionFn(org.apache.druid.query.lookup.LookupExtractionFn) TimeFormatExtractionFn(org.apache.druid.query.extraction.TimeFormatExtractionFn) StrlenExtractionFn(org.apache.druid.query.extraction.StrlenExtractionFn) DimExtractionFn(org.apache.druid.query.extraction.DimExtractionFn) 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)

Aggregations

DimExtractionFn (org.apache.druid.query.extraction.DimExtractionFn)6 ExtractionDimensionSpec (org.apache.druid.query.dimension.ExtractionDimensionSpec)5 RegexDimExtractionFn (org.apache.druid.query.extraction.RegexDimExtractionFn)5 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)5 Test (org.junit.Test)5 ExtractionFn (org.apache.druid.query.extraction.ExtractionFn)4 JavaScriptExtractionFn (org.apache.druid.query.extraction.JavaScriptExtractionFn)4 StringFormatExtractionFn (org.apache.druid.query.extraction.StringFormatExtractionFn)4 StrlenExtractionFn (org.apache.druid.query.extraction.StrlenExtractionFn)4 TimeFormatExtractionFn (org.apache.druid.query.extraction.TimeFormatExtractionFn)4 LookupExtractionFn (org.apache.druid.query.lookup.LookupExtractionFn)4 Result (org.apache.druid.query.Result)3 SubstringDimExtractionFn (org.apache.druid.query.extraction.SubstringDimExtractionFn)3 CascadeExtractionFn (org.apache.druid.query.extraction.CascadeExtractionFn)2 SearchQuerySpecDimExtractionFn (org.apache.druid.query.extraction.SearchQuerySpecDimExtractionFn)2 SelectorDimFilter (org.apache.druid.query.filter.SelectorDimFilter)2 ArrayList (java.util.ArrayList)1 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)1 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)1 LowerExtractionFn (org.apache.druid.query.extraction.LowerExtractionFn)1