use of io.druid.query.extraction.ExtractionFn in project druid by druid-io.
the class GroupByQueryRunnerTest method testGroupByWithNullProducingDimExtractionFn.
@Test
public void testGroupByWithNullProducingDimExtractionFn() {
final ExtractionFn nullExtractionFn = new RegexDimExtractionFn("(\\w{1})", false, null) {
@Override
public byte[] getCacheKey() {
return new byte[] { (byte) 0xFF };
}
@Override
public String apply(String dimValue) {
return dimValue.equals("mezzanine") ? null : super.apply(dimValue);
}
};
GroupByQuery query = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.dataSource).setQuerySegmentSpec(QueryRunnerTestHelper.firstToThird).setAggregatorSpecs(Arrays.asList(QueryRunnerTestHelper.rowsCount, new LongSumAggregatorFactory("idx", "index"))).setGranularity(QueryRunnerTestHelper.dayGran).setDimensions(Lists.<DimensionSpec>newArrayList(new ExtractionDimensionSpec("quality", "alias", nullExtractionFn))).build();
List<Row> expectedResults = Arrays.asList(GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", null, "rows", 3L, "idx", 2870L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "a", "rows", 1L, "idx", 135L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "b", "rows", 1L, "idx", 118L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "e", "rows", 1L, "idx", 158L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "h", "rows", 1L, "idx", 120L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "n", "rows", 1L, "idx", 121L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "p", "rows", 3L, "idx", 2900L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "alias", "t", "rows", 2L, "idx", 197L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", null, "rows", 3L, "idx", 2447L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "a", "rows", 1L, "idx", 147L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "b", "rows", 1L, "idx", 112L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "e", "rows", 1L, "idx", 166L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "h", "rows", 1L, "idx", 113L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "n", "rows", 1L, "idx", 114L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "p", "rows", 3L, "idx", 2505L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "alias", "t", "rows", 2L, "idx", 223L));
TestHelper.assertExpectedObjects(expectedResults, GroupByQueryRunnerTestHelper.runQuery(factory, runner, query), "");
}
use of io.druid.query.extraction.ExtractionFn in project druid by druid-io.
the class SelectQueryRunnerTest method testFullOnSelectWithLongAndFloatWithExFn.
@Test
public void testFullOnSelectWithLongAndFloatWithExFn() {
String jsFn = "function(str) { return 'super-' + str; }";
ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getEnabledInstance());
List<DimensionSpec> dimSpecs = Arrays.<DimensionSpec>asList(new ExtractionDimensionSpec(QueryRunnerTestHelper.indexMetric, "floatIndex", jsExtractionFn), new ExtractionDimensionSpec(Column.TIME_COLUMN_NAME, "longTime", jsExtractionFn));
SelectQuery query = newTestQuery().dimensionSpecs(dimSpecs).metrics(Arrays.asList(Column.TIME_COLUMN_NAME, "index")).intervals(I_0112_0114).build();
HashMap<String, Object> context = new HashMap<String, Object>();
Iterable<Result<SelectResultValue>> results = Sequences.toList(runner.run(query, context), Lists.<Result<SelectResultValue>>newArrayList());
List<Result<SelectResultValue>> expectedResultsAsc = Arrays.asList(new Result<SelectResultValue>(new DateTime("2011-01-12T00:00:00.000Z"), new SelectResultValue(ImmutableMap.of(QueryRunnerTestHelper.segmentId, 2), Sets.newHashSet("null_column", "floatIndex", "longTime"), Sets.newHashSet("__time", "index"), Arrays.asList(new EventHolder(QueryRunnerTestHelper.segmentId, 0, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-01-12T00:00:00.000Z")).put("longTime", "super-1294790400000").put("floatIndex", "super-100").put(QueryRunnerTestHelper.indexMetric, 100.000000F).put(Column.TIME_COLUMN_NAME, 1294790400000L).build()), new EventHolder(QueryRunnerTestHelper.segmentId, 1, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-01-12T00:00:00.000Z")).put("longTime", "super-1294790400000").put("floatIndex", "super-100").put(QueryRunnerTestHelper.indexMetric, 100.000000F).put(Column.TIME_COLUMN_NAME, 1294790400000L).build()), new EventHolder(QueryRunnerTestHelper.segmentId, 2, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-01-12T00:00:00.000Z")).put("longTime", "super-1294790400000").put("floatIndex", "super-100").put(QueryRunnerTestHelper.indexMetric, 100.000000F).put(Column.TIME_COLUMN_NAME, 1294790400000L).build())))));
List<Result<SelectResultValue>> expectedResultsDsc = Arrays.asList(new Result<SelectResultValue>(new DateTime("2011-01-12T00:00:00.000Z"), new SelectResultValue(ImmutableMap.of(QueryRunnerTestHelper.segmentId, -3), Sets.newHashSet("null_column", "floatIndex", "longTime"), Sets.newHashSet("__time", "index"), Arrays.asList(new EventHolder(QueryRunnerTestHelper.segmentId, -1, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-01-13T00:00:00.000Z")).put("longTime", "super-1294876800000").put("floatIndex", "super-1564.61767578125").put(QueryRunnerTestHelper.indexMetric, 1564.6177f).put(Column.TIME_COLUMN_NAME, 1294876800000L).build()), new EventHolder(QueryRunnerTestHelper.segmentId, -2, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-01-13T00:00:00.000Z")).put("longTime", "super-1294876800000").put("floatIndex", "super-826.0601806640625").put(QueryRunnerTestHelper.indexMetric, 826.0602f).put(Column.TIME_COLUMN_NAME, 1294876800000L).build()), new EventHolder(QueryRunnerTestHelper.segmentId, -3, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-01-13T00:00:00.000Z")).put("longTime", "super-1294876800000").put("floatIndex", "super-1689.0128173828125").put(QueryRunnerTestHelper.indexMetric, 1689.0128f).put(Column.TIME_COLUMN_NAME, 1294876800000L).build())))));
verify(descending ? expectedResultsDsc : expectedResultsAsc, populateNullColumnAtLastForQueryableIndexCase(results, "null_column"));
}
use of io.druid.query.extraction.ExtractionFn in project druid by druid-io.
the class TopNQueryRunnerTest method testFullOnTopNDimExtractionAllNulls.
@Test
public void testFullOnTopNDimExtractionAllNulls() {
String jsFn = "function(str) { return null; }";
ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getEnabledInstance());
TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).dimension(new ExtractionDimensionSpec(QueryRunnerTestHelper.marketDimension, QueryRunnerTestHelper.marketDimension, jsExtractionFn)).metric(QueryRunnerTestHelper.indexMetric).threshold(4).intervals(QueryRunnerTestHelper.fullOnInterval).aggregators(Lists.<AggregatorFactory>newArrayList(Iterables.concat(QueryRunnerTestHelper.commonAggregators, Lists.newArrayList(new DoubleMaxAggregatorFactory("maxIndex", "index"), new DoubleMinAggregatorFactory("minIndex", "index"))))).postAggregators(Arrays.<PostAggregator>asList(QueryRunnerTestHelper.addRowsIndexConstant)).build();
Map<String, Object> expectedMap = new HashMap<>();
expectedMap.put(QueryRunnerTestHelper.marketDimension, null);
expectedMap.put("rows", 1209L);
expectedMap.put("index", 503332.5071372986D);
expectedMap.put("addRowsIndexConstant", 504542.5071372986D);
expectedMap.put("uniques", 9.019833517963864);
expectedMap.put("maxIndex", 1870.06103515625D);
expectedMap.put("minIndex", 59.02102279663086D);
List<Result<TopNResultValue>> expectedResults = Arrays.asList(new Result<TopNResultValue>(new DateTime("2011-01-12T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(expectedMap))));
assertExpectedResults(expectedResults, query);
}
use of io.druid.query.extraction.ExtractionFn in project druid by druid-io.
the class TopNQueryRunnerTest method testFullOnTopNStringOutputAsLong.
@Test
public void testFullOnTopNStringOutputAsLong() {
ExtractionFn strlenFn = StrlenExtractionFn.instance();
TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).dimension(new ExtractionDimensionSpec(QueryRunnerTestHelper.qualityDimension, "alias", ValueType.LONG, strlenFn)).metric("maxIndex").threshold(4).intervals(QueryRunnerTestHelper.fullOnInterval).aggregators(Lists.<AggregatorFactory>newArrayList(Iterables.concat(QueryRunnerTestHelper.commonAggregators, Lists.newArrayList(new DoubleMaxAggregatorFactory("maxIndex", "index"), new DoubleMinAggregatorFactory("minIndex", "index"))))).postAggregators(Arrays.<PostAggregator>asList(QueryRunnerTestHelper.addRowsIndexConstant)).build();
List<Result<TopNResultValue>> expectedResults = Arrays.asList(new Result<TopNResultValue>(new DateTime("2011-01-12T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.<String, Object>builder().put("alias", 9L).put(QueryRunnerTestHelper.indexMetric, 217725.42022705078D).put("rows", 279L).put("addRowsIndexConstant", 218005.42022705078D).put("uniques", QueryRunnerTestHelper.UNIQUES_1).put("maxIndex", 1870.06103515625D).put("minIndex", 91.27055358886719D).build(), ImmutableMap.<String, Object>builder().put("alias", 7L).put(QueryRunnerTestHelper.indexMetric, 210865.67966461182D).put("rows", 279L).put("addRowsIndexConstant", 211145.67966461182D).put("uniques", QueryRunnerTestHelper.UNIQUES_1).put("maxIndex", 1862.7379150390625D).put("minIndex", 99.2845230102539D).build(), ImmutableMap.<String, Object>builder().put("alias", 10L).put(QueryRunnerTestHelper.indexMetric, 20479.497562408447D).put("rows", 186L).put("addRowsIndexConstant", 20666.497562408447D).put("uniques", QueryRunnerTestHelper.UNIQUES_2).put("maxIndex", 277.2735290527344D).put("minIndex", 59.02102279663086D).build(), ImmutableMap.<String, Object>builder().put("alias", 13L).put(QueryRunnerTestHelper.indexMetric, 12086.472755432129D).put("rows", 93L).put("addRowsIndexConstant", 12180.472755432129D).put("uniques", QueryRunnerTestHelper.UNIQUES_1).put("maxIndex", 193.78756713867188D).put("minIndex", 84.71052551269531D).build()))));
assertExpectedResults(expectedResults, query);
}
use of io.druid.query.extraction.ExtractionFn in project druid by druid-io.
the class TopNQueryRunnerTest method testFullOnTopNLongColumnWithExFn.
@Test
public void testFullOnTopNLongColumnWithExFn() {
String jsFn = "function(str) { return 'super-' + str; }";
ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getEnabledInstance());
TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).dimension(new ExtractionDimensionSpec("qualityLong", "ql_alias", jsExtractionFn)).metric("maxIndex").threshold(4).intervals(QueryRunnerTestHelper.fullOnInterval).aggregators(Lists.<AggregatorFactory>newArrayList(Iterables.concat(QueryRunnerTestHelper.commonAggregators, Lists.newArrayList(new DoubleMaxAggregatorFactory("maxIndex", "index"), new DoubleMinAggregatorFactory("minIndex", "index"))))).postAggregators(Arrays.<PostAggregator>asList(QueryRunnerTestHelper.addRowsIndexConstant)).build();
List<Result<TopNResultValue>> expectedResults = Arrays.asList(new Result<TopNResultValue>(new DateTime("2011-01-12T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.<String, Object>builder().put("ql_alias", "super-1400").put(QueryRunnerTestHelper.indexMetric, 217725.42022705078D).put("rows", 279L).put("addRowsIndexConstant", 218005.42022705078D).put("uniques", QueryRunnerTestHelper.UNIQUES_1).put("maxIndex", 1870.06103515625D).put("minIndex", 91.27055358886719D).build(), ImmutableMap.<String, Object>builder().put("ql_alias", "super-1600").put(QueryRunnerTestHelper.indexMetric, 210865.67966461182D).put("rows", 279L).put("addRowsIndexConstant", 211145.67966461182D).put("uniques", QueryRunnerTestHelper.UNIQUES_1).put("maxIndex", 1862.7379150390625D).put("minIndex", 99.2845230102539D).build(), ImmutableMap.<String, Object>builder().put("ql_alias", "super-1000").put(QueryRunnerTestHelper.indexMetric, 12270.807106018066D).put("rows", 93L).put("addRowsIndexConstant", 12364.807106018066D).put("uniques", QueryRunnerTestHelper.UNIQUES_1).put("maxIndex", 277.2735290527344D).put("minIndex", 71.31593322753906D).build(), ImmutableMap.<String, Object>builder().put("ql_alias", "super-1200").put(QueryRunnerTestHelper.indexMetric, 12086.472755432129D).put("rows", 93L).put("addRowsIndexConstant", 12180.472755432129D).put("uniques", QueryRunnerTestHelper.UNIQUES_1).put("maxIndex", 193.78756713867188D).put("minIndex", 84.71052551269531D).build()))));
assertExpectedResults(expectedResults, query);
}
Aggregations