Search in sources :

Example 1 with SearchQuerySpecDimExtractionFn

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

the class GroupByQueryRunnerTest method testGroupByNestedWithInnerQueryOutputNullNumerics.

@Test
public void testGroupByNestedWithInnerQueryOutputNullNumerics() {
    cannotVectorize();
    if (config.getDefaultStrategy().equals(GroupByStrategySelector.STRATEGY_V1)) {
        expectedException.expect(UnsupportedOperationException.class);
        expectedException.expectMessage("GroupBy v1 only supports dimensions with an outputType of STRING.");
    }
    // Following extractionFn will generate null value for one kind of quality
    ExtractionFn extractionFn = new SearchQuerySpecDimExtractionFn(new ContainsSearchQuerySpec("1200", false));
    GroupByQuery subquery = makeQueryBuilder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setDimensions(new DefaultDimensionSpec("quality", "alias"), new ExtractionDimensionSpec("qualityLong", "ql_alias", ColumnType.LONG, extractionFn), new ExtractionDimensionSpec("qualityFloat", "qf_alias", ColumnType.FLOAT, extractionFn), new ExtractionDimensionSpec("qualityDouble", "qd_alias", ColumnType.DOUBLE, extractionFn)).setDimFilter(new InDimFilter("quality", Arrays.asList("entertainment", "business"), null)).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT, new LongSumAggregatorFactory("idx", "index")).setGranularity(QueryRunnerTestHelper.DAY_GRAN).build();
    GroupByQuery outerQuery = makeQueryBuilder().setDataSource(subquery).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setDimensions(new DefaultDimensionSpec("ql_alias", "quallong", ColumnType.LONG), new DefaultDimensionSpec("qf_alias", "qualfloat", ColumnType.FLOAT), new DefaultDimensionSpec("qd_alias", "qualdouble", ColumnType.DOUBLE)).setAggregatorSpecs(new LongSumAggregatorFactory("ql_alias_sum", "ql_alias"), new DoubleSumAggregatorFactory("qf_alias_sum", "qf_alias"), new DoubleSumAggregatorFactory("qd_alias_sum", "qd_alias")).setGranularity(QueryRunnerTestHelper.ALL_GRAN).build();
    List<ResultRow> expectedResults = Arrays.asList(makeRow(outerQuery, "2011-04-01", "quallong", NullHandling.defaultLongValue(), "qualfloat", NullHandling.defaultFloatValue(), "qualdouble", NullHandling.defaultDoubleValue(), "ql_alias_sum", NullHandling.defaultLongValue(), "qf_alias_sum", NullHandling.defaultFloatValue(), "qd_alias_sum", NullHandling.defaultDoubleValue()), makeRow(outerQuery, "2011-04-01", "quallong", 1200L, "qualfloat", 12000.0, "qualdouble", 12000.0, "ql_alias_sum", 2400L, "qf_alias_sum", 24000.0, "qd_alias_sum", 24000.0));
    Iterable<ResultRow> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, outerQuery);
    TestHelper.assertExpectedObjects(expectedResults, results, "numerics");
}
Also used : RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) StringFormatExtractionFn(org.apache.druid.query.extraction.StringFormatExtractionFn) LookupExtractionFn(org.apache.druid.query.lookup.LookupExtractionFn) CascadeExtractionFn(org.apache.druid.query.extraction.CascadeExtractionFn) StrlenExtractionFn(org.apache.druid.query.extraction.StrlenExtractionFn) SubstringDimExtractionFn(org.apache.druid.query.extraction.SubstringDimExtractionFn) ExtractionFn(org.apache.druid.query.extraction.ExtractionFn) DimExtractionFn(org.apache.druid.query.extraction.DimExtractionFn) JavaScriptExtractionFn(org.apache.druid.query.extraction.JavaScriptExtractionFn) SearchQuerySpecDimExtractionFn(org.apache.druid.query.extraction.SearchQuerySpecDimExtractionFn) TimeFormatExtractionFn(org.apache.druid.query.extraction.TimeFormatExtractionFn) DoubleSumAggregatorFactory(org.apache.druid.query.aggregation.DoubleSumAggregatorFactory) ContainsSearchQuerySpec(org.apache.druid.query.search.ContainsSearchQuerySpec) InDimFilter(org.apache.druid.query.filter.InDimFilter) LongSumAggregatorFactory(org.apache.druid.query.aggregation.LongSumAggregatorFactory) SearchQuerySpecDimExtractionFn(org.apache.druid.query.extraction.SearchQuerySpecDimExtractionFn) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Aggregations

DoubleSumAggregatorFactory (org.apache.druid.query.aggregation.DoubleSumAggregatorFactory)1 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)1 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)1 ExtractionDimensionSpec (org.apache.druid.query.dimension.ExtractionDimensionSpec)1 CascadeExtractionFn (org.apache.druid.query.extraction.CascadeExtractionFn)1 DimExtractionFn (org.apache.druid.query.extraction.DimExtractionFn)1 ExtractionFn (org.apache.druid.query.extraction.ExtractionFn)1 JavaScriptExtractionFn (org.apache.druid.query.extraction.JavaScriptExtractionFn)1 RegexDimExtractionFn (org.apache.druid.query.extraction.RegexDimExtractionFn)1 SearchQuerySpecDimExtractionFn (org.apache.druid.query.extraction.SearchQuerySpecDimExtractionFn)1 StringFormatExtractionFn (org.apache.druid.query.extraction.StringFormatExtractionFn)1 StrlenExtractionFn (org.apache.druid.query.extraction.StrlenExtractionFn)1 SubstringDimExtractionFn (org.apache.druid.query.extraction.SubstringDimExtractionFn)1 TimeFormatExtractionFn (org.apache.druid.query.extraction.TimeFormatExtractionFn)1 InDimFilter (org.apache.druid.query.filter.InDimFilter)1 LookupExtractionFn (org.apache.druid.query.lookup.LookupExtractionFn)1 ContainsSearchQuerySpec (org.apache.druid.query.search.ContainsSearchQuerySpec)1 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)1 Test (org.junit.Test)1