use of io.druid.query.dimension.ExtractionDimensionSpec in project druid by druid-io.
the class TopNQueryRunnerTest method testInvertedTopNLexicographicDimExtractionWithPreviousStop2.
@Test
public void testInvertedTopNLexicographicDimExtractionWithPreviousStop2() {
TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).dimension(new ExtractionDimensionSpec(QueryRunnerTestHelper.marketDimension, QueryRunnerTestHelper.marketDimension, new RegexDimExtractionFn("..(.)", false, null))).metric(new InvertedTopNMetricSpec(new DimensionTopNMetricSpec("p", 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, "o", "rows", 18L, "index", 2231.8768157958984D, "addRowsIndexConstant", 2250.8768157958984D, "uniques", QueryRunnerTestHelper.UNIQUES_9), ImmutableMap.<String, Object>of(QueryRunnerTestHelper.marketDimension, "f", "rows", 4L, "index", 4875.669677734375D, "addRowsIndexConstant", 4880.669677734375D, "uniques", QueryRunnerTestHelper.UNIQUES_2)))));
assertExpectedResults(expectedResults, query);
}
use of io.druid.query.dimension.ExtractionDimensionSpec in project druid by druid-io.
the class TopNQueryRunnerTest method testTopNTimeExtraction.
@Test
public void testTopNTimeExtraction() {
TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).dimension(new ExtractionDimensionSpec(Column.TIME_COLUMN_NAME, "dayOfWeek", new TimeFormatExtractionFn("EEEE", null, null, null, false))).metric("index").threshold(2).intervals(QueryRunnerTestHelper.fullOnInterval).aggregators(Arrays.asList(QueryRunnerTestHelper.rowsCount, QueryRunnerTestHelper.indexDoubleSum)).postAggregators(Arrays.<PostAggregator>asList(QueryRunnerTestHelper.addRowsIndexConstant)).build();
List<Result<TopNResultValue>> expectedResults = Arrays.asList(new Result<>(new DateTime("2011-01-12T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.<String, Object>of("dayOfWeek", "Wednesday", "rows", 182L, "index", 76010.28100585938, "addRowsIndexConstant", 76193.28100585938), ImmutableMap.<String, Object>of("dayOfWeek", "Thursday", "rows", 182L, "index", 75203.26300811768, "addRowsIndexConstant", 75386.26300811768)))));
assertExpectedResults(expectedResults, query);
}
use of io.druid.query.dimension.ExtractionDimensionSpec in project druid by druid-io.
the class TopNQueryRunnerTest method testTopNWithEmptyStringProducingDimExtractionFn.
@Test
public /**
* This test exists only to show what the current behavior is and not necessarily to define that this is
* correct behavior. In fact, the behavior when returning the empty string from a DimExtractionFn is, by
* contract, undefined, so this can do anything.
*/
void testTopNWithEmptyStringProducingDimExtractionFn() {
final ExtractionFn emptyStringDimExtraction = new DimExtractionFn() {
@Override
public byte[] getCacheKey() {
return new byte[] { (byte) 0xFF };
}
@Override
public String apply(String dimValue) {
return dimValue.equals("total_market") ? "" : dimValue;
}
@Override
public boolean preservesOrdering() {
return false;
}
@Override
public ExtractionType getExtractionType() {
return ExtractionType.MANY_TO_ONE;
}
};
final TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).metric("rows").threshold(4).intervals(QueryRunnerTestHelper.firstToThird).aggregators(QueryRunnerTestHelper.commonAggregators).postAggregators(Arrays.<PostAggregator>asList(QueryRunnerTestHelper.addRowsIndexConstant)).dimension(new ExtractionDimensionSpec(QueryRunnerTestHelper.marketDimension, QueryRunnerTestHelper.marketDimension, emptyStringDimExtraction)).build();
List<Result<TopNResultValue>> expectedResults = Arrays.asList(new Result<>(new DateTime("2011-04-01T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.<String, Object>of(QueryRunnerTestHelper.marketDimension, "spot", "rows", 18L, "index", 2231.8768157958984D, "addRowsIndexConstant", 2250.8768157958984D, "uniques", QueryRunnerTestHelper.UNIQUES_9), new LinkedHashMap<String, Object>() {
{
put(QueryRunnerTestHelper.marketDimension, "");
put("rows", 4L);
put("index", 5351.814697265625D);
put("addRowsIndexConstant", 5356.814697265625D);
put("uniques", QueryRunnerTestHelper.UNIQUES_2);
}
}, ImmutableMap.<String, Object>of(QueryRunnerTestHelper.marketDimension, "upfront", "rows", 4L, "index", 4875.669677734375D, "addRowsIndexConstant", 4880.669677734375D, "uniques", QueryRunnerTestHelper.UNIQUES_2)))));
assertExpectedResults(expectedResults, query);
}
use of io.druid.query.dimension.ExtractionDimensionSpec 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);
}
use of io.druid.query.dimension.ExtractionDimensionSpec in project druid by druid-io.
the class CalciteQueryTest method testFilterAndGroupByLookup.
@Test
public void testFilterAndGroupByLookup() throws Exception {
final RegisteredLookupExtractionFn extractionFn = new RegisteredLookupExtractionFn(null, "lookyloo", false, null, false, true);
testQuery("SELECT LOOKUP(dim1, 'lookyloo'), COUNT(*) FROM foo\n" + "WHERE LOOKUP(dim1, 'lookyloo') <> 'xxx'\n" + "GROUP BY LOOKUP(dim1, 'lookyloo')", ImmutableList.<Query>of(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE1).setInterval(QSS(Filtration.eternity())).setGranularity(Granularities.ALL).setDimFilter(NOT(SELECTOR("dim1", "xxx", extractionFn))).setDimensions(DIMS(new ExtractionDimensionSpec("dim1", "d0", ValueType.STRING, extractionFn))).setAggregatorSpecs(AGGS(new CountAggregatorFactory("a0"))).setContext(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { "", 5L }, new Object[] { "xabc", 1L }));
}
Aggregations