use of io.druid.query.extraction.JavaScriptExtractionFn 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);
}
use of io.druid.query.extraction.JavaScriptExtractionFn in project druid by druid-io.
the class TopNQueryRunnerTest method testFullOnTopNFloatColumnWithExFn.
@Test
public void testFullOnTopNFloatColumnWithExFn() {
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(QueryRunnerTestHelper.indexMetric, "index_alias", 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();
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("index_alias", "super-1000").put(QueryRunnerTestHelper.indexMetric, 2000.0D).put("rows", 2L).put("addRowsIndexConstant", 2003.0D).put("uniques", QueryRunnerTestHelper.UNIQUES_2).put("maxIndex", 1000.0D).put("minIndex", 1000.0D).build(), ImmutableMap.<String, Object>builder().put("index_alias", "super-1870.06103515625").put(QueryRunnerTestHelper.indexMetric, 1870.06103515625D).put("rows", 1L).put("addRowsIndexConstant", 1872.06103515625D).put("uniques", QueryRunnerTestHelper.UNIQUES_1).put("maxIndex", 1870.06103515625D).put("minIndex", 1870.06103515625D).build(), ImmutableMap.<String, Object>builder().put("index_alias", "super-1862.7379150390625").put(QueryRunnerTestHelper.indexMetric, 1862.7379150390625D).put("rows", 1L).put("addRowsIndexConstant", 1864.7379150390625D).put("uniques", QueryRunnerTestHelper.UNIQUES_1).put("maxIndex", 1862.7379150390625D).put("minIndex", 1862.7379150390625D).build(), ImmutableMap.<String, Object>builder().put("index_alias", "super-1743.9217529296875").put(QueryRunnerTestHelper.indexMetric, 1743.9217529296875D).put("rows", 1L).put("addRowsIndexConstant", 1745.9217529296875D).put("uniques", QueryRunnerTestHelper.UNIQUES_1).put("maxIndex", 1743.9217529296875D).put("minIndex", 1743.9217529296875D).build()))));
assertExpectedResults(expectedResults, query);
}
use of io.druid.query.extraction.JavaScriptExtractionFn in project druid by druid-io.
the class TimeFilteringTest method testIntervalFilterOnStringDimension.
@Test
public void testIntervalFilterOnStringDimension() {
assertFilterMatches(new IntervalDimFilter("dim0", Arrays.asList(Interval.parse("1970-01-01T00:00:00.001Z/1970-01-01T00:00:00.005Z")), null), ImmutableList.<String>of("1", "2", "3", "4"));
assertFilterMatches(new IntervalDimFilter("dim0", Arrays.asList(Interval.parse("1970-01-01T00:00:00.000Z/1970-01-01T00:00:00.003Z"), Interval.parse("1970-01-01T00:00:00.004Z/1970-01-01T00:00:00.006Z")), null), ImmutableList.<String>of("0", "1", "2", "4", "5"));
assertFilterMatches(new IntervalDimFilter("dim0", Arrays.asList(Interval.parse("1970-01-01T00:00:00.000Z/1970-01-01T00:00:00.001Z"), Interval.parse("1970-01-01T00:00:00.003Z/1970-01-01T00:00:00.006Z"), Interval.parse("1970-01-01T00:00:00.002Z/1970-01-01T00:00:00.005Z")), null), ImmutableList.<String>of("0", "2", "3", "4", "5"));
assertFilterMatches(new IntervalDimFilter("dim1", Arrays.asList(Interval.parse("1970-01-01T00:00:00.002Z/1970-01-01T00:00:00.011Z")), null), ImmutableList.<String>of("1", "2"));
// increment timestamp by 2 hours
String timeBoosterJsFn = "function(x) { return(Number(x) + 7200000) }";
ExtractionFn exFn = new JavaScriptExtractionFn(timeBoosterJsFn, true, JavaScriptConfig.getEnabledInstance());
assertFilterMatches(new IntervalDimFilter("dim0", Arrays.asList(Interval.parse("1970-01-01T02:00:00.001Z/1970-01-01T02:00:00.005Z")), exFn), ImmutableList.<String>of("1", "2", "3", "4"));
}
use of io.druid.query.extraction.JavaScriptExtractionFn in project druid by druid-io.
the class RegexFilterTest method testRegexWithExtractionFn.
@Test
public void testRegexWithExtractionFn() {
String nullJsFn = "function(str) { if (str === null) { return 'NOT_NULL_ANYMORE'; } else { return str;} }";
ExtractionFn changeNullFn = new JavaScriptExtractionFn(nullJsFn, false, JavaScriptConfig.getEnabledInstance());
assertFilterMatches(new RegexDimFilter("dim1", ".*ANYMORE", changeNullFn), ImmutableList.of("0"));
assertFilterMatches(new RegexDimFilter("dim1", "ab.*", changeNullFn), ImmutableList.<String>of("4", "5"));
assertFilterMatches(new RegexDimFilter("dim2", ".*ANYMORE", changeNullFn), ImmutableList.of("1", "2", "5"));
assertFilterMatches(new RegexDimFilter("dim2", "a.*", changeNullFn), ImmutableList.of("0", "3"));
assertFilterMatches(new RegexDimFilter("dim3", ".*ANYMORE", changeNullFn), ImmutableList.of("0", "1", "2", "3", "4", "5"));
assertFilterMatches(new RegexDimFilter("dim3", "a.*", changeNullFn), ImmutableList.<String>of());
assertFilterMatches(new RegexDimFilter("dim4", ".*ANYMORE", changeNullFn), ImmutableList.of("0", "1", "2", "3", "4", "5"));
assertFilterMatches(new RegexDimFilter("dim4", "a.*", changeNullFn), ImmutableList.<String>of());
}
use of io.druid.query.extraction.JavaScriptExtractionFn in project druid by druid-io.
the class GroupByQueryRunnerTest method testGroupByLongTimeColumnWithExFn.
@Test
public void testGroupByLongTimeColumnWithExFn() {
String jsFn = "function(str) { return 'super-' + str; }";
ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getEnabledInstance());
GroupByQuery query = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.dataSource).setQuerySegmentSpec(QueryRunnerTestHelper.firstToThird).setDimensions(Lists.<DimensionSpec>newArrayList(new ExtractionDimensionSpec("__time", "time_alias", jsExtractionFn))).setDimFilter(new SelectorDimFilter("quality", "entertainment", null)).setAggregatorSpecs(Arrays.asList(QueryRunnerTestHelper.rowsCount, new LongSumAggregatorFactory("idx", "index"))).setGranularity(QueryRunnerTestHelper.dayGran).build();
List<Row> expectedResults = Arrays.asList(GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "time_alias", "super-1301616000000", "rows", 1L, "idx", 158L), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "time_alias", "super-1301702400000", "rows", 1L, "idx", 166L));
Iterable<Row> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
TestHelper.assertExpectedObjects(expectedResults, results, "");
}
Aggregations