Search in sources :

Example 1 with StringFormatExtractionFn

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

the class TopNQueryRunnerTest method testTopNOnMissingColumnWithExtractionFn.

@Test
public void testTopNOnMissingColumnWithExtractionFn() {
    TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.ALL_GRAN).dimension(new ExtractionDimensionSpec("nonexistentColumn", "alias", new StringFormatExtractionFn("theValue"))).metric("rows").threshold(4).intervals(QueryRunnerTestHelper.FULL_ON_INTERVAL_SPEC).aggregators(new CountAggregatorFactory("rows")).build();
    List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<>(DateTimes.of("2011-01-12T00:00:00.000Z"), new TopNResultValue(Collections.<Map<String, Object>>singletonList(ImmutableMap.<String, Object>builder().put("alias", "theValue").put("rows", 1209L).build()))));
    assertExpectedResults(expectedResults, query);
}
Also used : CountAggregatorFactory(org.apache.druid.query.aggregation.CountAggregatorFactory) StringFormatExtractionFn(org.apache.druid.query.extraction.StringFormatExtractionFn) ExtractionDimensionSpec(org.apache.druid.query.dimension.ExtractionDimensionSpec) Result(org.apache.druid.query.Result) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 2 with StringFormatExtractionFn

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

the class GroupByQueryRunnerTest method testGroupByOnMissingColumn.

@Test
public void testGroupByOnMissingColumn() {
    // Cannot vectorize due to extraction dimension spec.
    cannotVectorize();
    GroupByQuery query = makeQueryBuilder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setDimensions(new DefaultDimensionSpec("nonexistent0", "alias0"), new ExtractionDimensionSpec("nonexistent1", "alias1", new StringFormatExtractionFn("foo"))).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT).setGranularity(QueryRunnerTestHelper.ALL_GRAN).build();
    List<ResultRow> expectedResults = Collections.singletonList(makeRow(query, "2011-04-01", "alias0", null, "alias1", "foo", "rows", 26L));
    Iterable<ResultRow> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
    TestHelper.assertExpectedObjects(expectedResults, results, "missing-column");
}
Also used : StringFormatExtractionFn(org.apache.druid.query.extraction.StringFormatExtractionFn) 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

ExtractionDimensionSpec (org.apache.druid.query.dimension.ExtractionDimensionSpec)2 StringFormatExtractionFn (org.apache.druid.query.extraction.StringFormatExtractionFn)2 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)2 Test (org.junit.Test)2 Result (org.apache.druid.query.Result)1 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)1 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)1