Search in sources :

Example 76 with DateTime

use of org.joda.time.DateTime in project druid by druid-io.

the class SelectBinaryFnTest method testColumnMerge.

@Test
public void testColumnMerge() throws Exception {
    SelectBinaryFn binaryFn = new SelectBinaryFn(Granularities.ALL, new PagingSpec(null, 5), false);
    Result<SelectResultValue> res1 = new Result<>(new DateTime("2013-01-01"), new SelectResultValue(ImmutableMap.<String, Integer>of(), Sets.newHashSet("first", "second", "fourth"), Sets.newHashSet("eight", "nineth"), Lists.<EventHolder>newArrayList(new EventHolder(segmentId1, 0, ImmutableMap.<String, Object>of(EventHolder.timestampKey, new DateTime("2013-01-01T00"), "dim", "first")))));
    Result<SelectResultValue> res2 = new Result<>(new DateTime("2013-01-01"), new SelectResultValue(ImmutableMap.<String, Integer>of(), Sets.newHashSet("third", "second", "fifth"), Sets.newHashSet("seventh"), Lists.<EventHolder>newArrayList(new EventHolder(segmentId2, 0, ImmutableMap.<String, Object>of(EventHolder.timestampKey, new DateTime("2013-01-01T00"), "dim", "second")))));
    Result<SelectResultValue> merged = binaryFn.apply(res1, res2);
    Set<String> exDimensions = Sets.newHashSet("first", "second", "fourth", "third", "fifth");
    Set<String> exMetrics = Sets.newHashSet("eight", "nineth", "seventh");
    Set<String> acDimensions = merged.getValue().getDimensions();
    Set<String> acMetrics = merged.getValue().getMetrics();
    Assert.assertEquals(exDimensions, acDimensions);
    Assert.assertEquals(exMetrics, acMetrics);
}
Also used : DateTime(org.joda.time.DateTime) Result(io.druid.query.Result) Test(org.junit.Test)

Example 77 with DateTime

use of org.joda.time.DateTime in project druid by druid-io.

the class SearchQueryRunnerTest method checkSearchQuery.

private void checkSearchQuery(Query searchQuery, QueryRunner runner, List<SearchHit> expectedResults) {
    Iterable<Result<SearchResultValue>> results = Sequences.toList(runner.run(searchQuery, ImmutableMap.of()), Lists.<Result<SearchResultValue>>newArrayList());
    List<SearchHit> copy = Lists.newLinkedList(expectedResults);
    for (Result<SearchResultValue> result : results) {
        Assert.assertEquals(new DateTime("2011-01-12T00:00:00.000Z"), result.getTimestamp());
        Assert.assertTrue(result.getValue() instanceof Iterable);
        Iterable<SearchHit> resultValues = result.getValue();
        for (SearchHit resultValue : resultValues) {
            int index = copy.indexOf(resultValue);
            if (index < 0) {
                fail(expectedResults, results, "No result found containing " + resultValue.getDimension() + " and " + resultValue.getValue());
            }
            SearchHit expected = copy.remove(index);
            if (!resultValue.toString().equals(expected.toString())) {
                fail(expectedResults, results, "Invalid count for " + resultValue + ".. which was expected to be " + expected.getCount());
            }
        }
    }
    if (!copy.isEmpty()) {
        fail(expectedResults, results, "Some expected results are not shown: " + copy);
    }
}
Also used : SearchHit(io.druid.query.search.search.SearchHit) DateTime(org.joda.time.DateTime) Result(io.druid.query.Result)

Example 78 with DateTime

use of org.joda.time.DateTime 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"));
}
Also used : DimensionSpec(io.druid.query.dimension.DimensionSpec) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) HashMap(java.util.HashMap) JavaScriptExtractionFn(io.druid.query.extraction.JavaScriptExtractionFn) DateTime(org.joda.time.DateTime) ImmutableMap(com.google.common.collect.ImmutableMap) Result(io.druid.query.Result) LookupExtractionFn(io.druid.query.lookup.LookupExtractionFn) JavaScriptExtractionFn(io.druid.query.extraction.JavaScriptExtractionFn) ExtractionFn(io.druid.query.extraction.ExtractionFn) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Example 79 with DateTime

use of org.joda.time.DateTime in project druid by druid-io.

the class SelectQueryRunnerTest method testFullOnSelectWithDimensionSpec.

@Test
public void testFullOnSelectWithDimensionSpec() {
    Map<String, String> map = new HashMap<>();
    map.put("automotive", "automotive0");
    map.put("business", "business0");
    map.put("entertainment", "entertainment0");
    map.put("health", "health0");
    map.put("mezzanine", "mezzanine0");
    map.put("news", "news0");
    map.put("premium", "premium0");
    map.put("technology", "technology0");
    map.put("travel", "travel0");
    SelectQuery query = newTestQuery().dimensionSpecs(Arrays.<DimensionSpec>asList(new DefaultDimensionSpec(QueryRunnerTestHelper.marketDimension, "mar"), new ExtractionDimensionSpec(QueryRunnerTestHelper.qualityDimension, "qual", new LookupExtractionFn(new MapLookupExtractor(map, true), false, null, true, false)), new DefaultDimensionSpec(QueryRunnerTestHelper.placementDimension, "place"))).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("mar", "qual", "place"), Sets.newHashSet("index", "quality_uniques", "indexMin", "indexMaxPlusTen"), Arrays.asList(new EventHolder(QueryRunnerTestHelper.segmentId, 0, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-01-12T00:00:00.000Z")).put("mar", "spot").put("qual", "automotive0").put("place", "preferred").put(QueryRunnerTestHelper.indexMetric, 100.000000F).build()), new EventHolder(QueryRunnerTestHelper.segmentId, 1, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-01-12T00:00:00.000Z")).put("mar", "spot").put("qual", "business0").put("place", "preferred").put(QueryRunnerTestHelper.indexMetric, 100.000000F).build()), new EventHolder(QueryRunnerTestHelper.segmentId, 2, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-01-12T00:00:00.000Z")).put("mar", "spot").put("qual", "entertainment0").put("place", "preferred").put(QueryRunnerTestHelper.indexMetric, 100.000000F).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("mar", "qual", "place"), Sets.newHashSet("index", "quality_uniques", "indexMin", "indexMaxPlusTen"), Arrays.asList(new EventHolder(QueryRunnerTestHelper.segmentId, -1, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-04-15T00:00:00.000Z")).put("mar", "upfront").put("qual", "premium0").put("place", "preferred").put(QueryRunnerTestHelper.indexMetric, 780.27197265625F).build()), new EventHolder(QueryRunnerTestHelper.segmentId, -2, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-04-15T00:00:00.000Z")).put("mar", "upfront").put("qual", "mezzanine0").put("place", "preferred").put(QueryRunnerTestHelper.indexMetric, 962.731201171875F).build()), new EventHolder(QueryRunnerTestHelper.segmentId, -3, new ImmutableMap.Builder<String, Object>().put(EventHolder.timestampKey, new DateTime("2011-04-15T00:00:00.000Z")).put("mar", "total_market").put("qual", "premium0").put("place", "preferred").put(QueryRunnerTestHelper.indexMetric, 1029.0570068359375F).build())))));
    verify(descending ? expectedResultsDsc : expectedResultsAsc, results);
}
Also used : DimensionSpec(io.druid.query.dimension.DimensionSpec) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) HashMap(java.util.HashMap) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) DateTime(org.joda.time.DateTime) ImmutableMap(com.google.common.collect.ImmutableMap) Result(io.druid.query.Result) LookupExtractionFn(io.druid.query.lookup.LookupExtractionFn) MapLookupExtractor(io.druid.query.extraction.MapLookupExtractor) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Example 80 with DateTime

use of org.joda.time.DateTime in project druid by druid-io.

the class SpecificSegmentQueryRunnerTest method testRetry2.

@SuppressWarnings("unchecked")
@Test
public void testRetry2() throws Exception {
    final ObjectMapper mapper = new DefaultObjectMapper();
    SegmentDescriptor descriptor = new SegmentDescriptor(new Interval("2012-01-01T00:00:00Z/P1D"), "version", 0);
    TimeseriesResultBuilder builder = new TimeseriesResultBuilder(new DateTime("2012-01-01T00:00:00Z"));
    CountAggregator rows = new CountAggregator();
    rows.aggregate();
    builder.addMetric("rows", rows);
    final Result<TimeseriesResultValue> value = builder.build();
    final SpecificSegmentQueryRunner queryRunner = new SpecificSegmentQueryRunner(new QueryRunner() {

        @Override
        public Sequence run(Query query, Map responseContext) {
            return Sequences.withEffect(Sequences.simple(Arrays.asList(value)), new Runnable() {

                @Override
                public void run() {
                    throw new SegmentMissingException("FAILSAUCE");
                }
            }, MoreExecutors.sameThreadExecutor());
        }
    }, new SpecificSegmentSpec(descriptor));
    final Map<String, Object> responseContext = Maps.newHashMap();
    TimeseriesQuery query = Druids.newTimeseriesQueryBuilder().dataSource("foo").granularity(Granularities.ALL).intervals(ImmutableList.of(new Interval("2012-01-01T00:00:00Z/P1D"))).aggregators(ImmutableList.<AggregatorFactory>of(new CountAggregatorFactory("rows"))).build();
    Sequence results = queryRunner.run(query, responseContext);
    List<Result<TimeseriesResultValue>> res = Sequences.toList(results, Lists.<Result<TimeseriesResultValue>>newArrayList());
    Assert.assertEquals(1, res.size());
    Result<TimeseriesResultValue> theVal = res.get(0);
    Assert.assertTrue(1L == theVal.getValue().getLongMetric("rows"));
    validate(mapper, descriptor, responseContext);
}
Also used : TimeseriesResultValue(io.druid.query.timeseries.TimeseriesResultValue) TimeseriesQuery(io.druid.query.timeseries.TimeseriesQuery) Query(io.druid.query.Query) SegmentMissingException(io.druid.segment.SegmentMissingException) DateTime(org.joda.time.DateTime) Result(io.druid.query.Result) SegmentDescriptor(io.druid.query.SegmentDescriptor) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TimeseriesQuery(io.druid.query.timeseries.TimeseriesQuery) TimeseriesResultBuilder(io.druid.query.timeseries.TimeseriesResultBuilder) Sequence(io.druid.java.util.common.guava.Sequence) AggregatorFactory(io.druid.query.aggregation.AggregatorFactory) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) QueryRunner(io.druid.query.QueryRunner) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) CountAggregator(io.druid.query.aggregation.CountAggregator) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Map(java.util.Map) Interval(org.joda.time.Interval) Test(org.junit.Test)

Aggregations

DateTime (org.joda.time.DateTime)5683 Test (org.junit.Test)1667 Test (org.testng.annotations.Test)774 ArrayList (java.util.ArrayList)545 Date (java.util.Date)389 LocalDate (org.joda.time.LocalDate)374 DateTimeRfc1123 (com.microsoft.rest.DateTimeRfc1123)353 ResponseBody (okhttp3.ResponseBody)335 Interval (org.joda.time.Interval)307 Test (org.junit.jupiter.api.Test)281 HashMap (java.util.HashMap)272 BigDecimal (java.math.BigDecimal)234 DateTimeZone (org.joda.time.DateTimeZone)220 UUID (java.util.UUID)195 List (java.util.List)194 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)178 Map (java.util.Map)171 IOException (java.io.IOException)158 Result (io.druid.query.Result)153 ServiceCall (com.microsoft.rest.ServiceCall)148