Search in sources :

Example 36 with Pair

use of io.druid.java.util.common.Pair in project druid by druid-io.

the class ServerManagerTest method testMultipleDrops.

@Test
public void testMultipleDrops() throws Exception {
    loadQueryable("test", "3", new Interval("2011-04-04/2011-04-05"));
    Future future = assertQueryable(Granularities.DAY, "test", new Interval("2011-04-04/2011-04-06"), ImmutableList.<Pair<String, Interval>>of(new Pair<String, Interval>("3", new Interval("2011-04-04/2011-04-05"))));
    queryNotifyLatch.await(1000, TimeUnit.MILLISECONDS);
    Assert.assertEquals(1, factory.getSegmentReferences().size());
    for (ReferenceCountingSegment referenceCountingSegment : factory.getSegmentReferences()) {
        Assert.assertEquals(1, referenceCountingSegment.getNumReferences());
    }
    queryWaitYieldLatch.countDown();
    Assert.assertEquals(1, factory.getAdapters().size());
    for (SegmentForTesting segmentForTesting : factory.getAdapters()) {
        Assert.assertFalse(segmentForTesting.isClosed());
    }
    dropQueryable("test", "3", new Interval("2011-04-04/2011-04-05"));
    dropQueryable("test", "3", new Interval("2011-04-04/2011-04-05"));
    for (SegmentForTesting segmentForTesting : factory.getAdapters()) {
        Assert.assertFalse(segmentForTesting.isClosed());
    }
    queryWaitLatch.countDown();
    future.get();
    for (SegmentForTesting segmentForTesting : factory.getAdapters()) {
        Assert.assertTrue(segmentForTesting.isClosed());
    }
}
Also used : ReferenceCountingSegment(io.druid.segment.ReferenceCountingSegment) Future(java.util.concurrent.Future) Interval(org.joda.time.Interval) Pair(io.druid.java.util.common.Pair) Test(org.junit.Test)

Example 37 with Pair

use of io.druid.java.util.common.Pair in project druid by druid-io.

the class ServerManagerTest method assertQueryable.

private <T> Future assertQueryable(Granularity granularity, String dataSource, Interval interval, List<Pair<String, Interval>> expected) {
    final Iterator<Pair<String, Interval>> expectedIter = expected.iterator();
    final List<Interval> intervals = Arrays.asList(interval);
    final SearchQuery query = Druids.newSearchQueryBuilder().dataSource(dataSource).intervals(intervals).granularity(granularity).limit(10000).query("wow").build();
    final QueryRunner<Result<SearchResultValue>> runner = serverManager.getQueryRunnerForIntervals(query, intervals);
    return serverManagerExec.submit(new Runnable() {

        @Override
        public void run() {
            Map<String, Object> context = new HashMap<String, Object>();
            Sequence<Result<SearchResultValue>> seq = runner.run(query, context);
            Sequences.toList(seq, Lists.<Result<SearchResultValue>>newArrayList());
            Iterator<SegmentForTesting> adaptersIter = factory.getAdapters().iterator();
            while (expectedIter.hasNext() && adaptersIter.hasNext()) {
                Pair<String, Interval> expectedVals = expectedIter.next();
                SegmentForTesting value = adaptersIter.next();
                Assert.assertEquals(expectedVals.lhs, value.getVersion());
                Assert.assertEquals(expectedVals.rhs, value.getInterval());
            }
            Assert.assertFalse(expectedIter.hasNext());
            Assert.assertFalse(adaptersIter.hasNext());
        }
    });
}
Also used : SearchQuery(io.druid.query.search.search.SearchQuery) Sequence(io.druid.java.util.common.guava.Sequence) Result(io.druid.query.Result) SearchResultValue(io.druid.query.search.SearchResultValue) Iterator(java.util.Iterator) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Pair(io.druid.java.util.common.Pair) Interval(org.joda.time.Interval)

Example 38 with Pair

use of io.druid.java.util.common.Pair in project druid by druid-io.

the class QueryHostFinderTest method testFindServer.

@Test
public void testFindServer() throws Exception {
    EasyMock.expect(brokerSelector.select(EasyMock.<Query>anyObject())).andReturn(new Pair("hotBroker", selector));
    EasyMock.replay(brokerSelector);
    EasyMock.expect(selector.pick()).andReturn(server).once();
    EasyMock.replay(selector);
    QueryHostFinder queryRunner = new QueryHostFinder(brokerSelector);
    Server server = queryRunner.findServer(new TimeBoundaryQuery(new TableDataSource("test"), new MultipleIntervalSegmentSpec(Arrays.<Interval>asList(new Interval("2011-08-31/2011-09-01"))), null, null, null));
    Assert.assertEquals("foo", server.getHost());
}
Also used : DruidServer(io.druid.client.DruidServer) Server(io.druid.client.selector.Server) TableDataSource(io.druid.query.TableDataSource) MultipleIntervalSegmentSpec(io.druid.query.spec.MultipleIntervalSegmentSpec) TimeBoundaryQuery(io.druid.query.timeboundary.TimeBoundaryQuery) Pair(io.druid.java.util.common.Pair) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 39 with Pair

use of io.druid.java.util.common.Pair in project druid by druid-io.

the class JSONPathParser method generateFieldPaths.

private Map<String, Pair<FieldType, JsonPath>> generateFieldPaths(List<FieldSpec> fieldSpecs) {
    Map<String, Pair<FieldType, JsonPath>> map = new LinkedHashMap<>();
    for (FieldSpec fieldSpec : fieldSpecs) {
        String fieldName = fieldSpec.getName();
        if (map.get(fieldName) != null) {
            throw new IllegalArgumentException("Cannot have duplicate field definition: " + fieldName);
        }
        JsonPath path = fieldSpec.getType() == FieldType.PATH ? JsonPath.compile(fieldSpec.getExpr()) : null;
        Pair<FieldType, JsonPath> pair = new Pair<>(fieldSpec.getType(), path);
        map.put(fieldName, pair);
    }
    return map;
}
Also used : JsonPath(com.jayway.jsonpath.JsonPath) LinkedHashMap(java.util.LinkedHashMap) Pair(io.druid.java.util.common.Pair)

Example 40 with Pair

use of io.druid.java.util.common.Pair in project druid by druid-io.

the class JSONPathParser method parse.

/**
   * @param input JSON string. The root must be a JSON object, not an array.
   *              e.g., {"valid": "true"} and {"valid":[1,2,3]} are supported
   *              but [{"invalid": "true"}] and [1,2,3] are not.
   *
   * @return A map of field names and values
   */
@Override
public Map<String, Object> parse(String input) {
    try {
        Map<String, Object> map = new LinkedHashMap<>();
        Map<String, Object> document = mapper.readValue(input, new TypeReference<Map<String, Object>>() {
        });
        for (Map.Entry<String, Pair<FieldType, JsonPath>> entry : fieldPathMap.entrySet()) {
            String fieldName = entry.getKey();
            Pair<FieldType, JsonPath> pair = entry.getValue();
            JsonPath path = pair.rhs;
            Object parsedVal;
            if (pair.lhs == FieldType.ROOT) {
                parsedVal = document.get(fieldName);
            } else {
                parsedVal = path.read(document, jsonPathConfig);
            }
            if (parsedVal == null) {
                continue;
            }
            parsedVal = valueConversionFunction(parsedVal);
            map.put(fieldName, parsedVal);
        }
        if (useFieldDiscovery) {
            discoverFields(map, document);
        }
        return map;
    } catch (Exception e) {
        throw new ParseException(e, "Unable to parse row [%s]", input);
    }
}
Also used : JsonPath(com.jayway.jsonpath.JsonPath) LinkedHashMap(java.util.LinkedHashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Pair(io.druid.java.util.common.Pair)

Aggregations

Pair (io.druid.java.util.common.Pair)62 Test (org.junit.Test)26 Interval (org.joda.time.Interval)15 DataSegment (io.druid.timeline.DataSegment)11 Map (java.util.Map)11 ByteBuffer (java.nio.ByteBuffer)10 HashMap (java.util.HashMap)9 SerializablePair (io.druid.collections.SerializablePair)8 SegmentDescriptor (io.druid.query.SegmentDescriptor)8 List (java.util.List)8 ImmutableMap (com.google.common.collect.ImmutableMap)7 Executor (java.util.concurrent.Executor)7 DateTime (org.joda.time.DateTime)7 Function (com.google.common.base.Function)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)6 MapBasedInputRow (io.druid.data.input.MapBasedInputRow)6 TaskStatus (io.druid.indexing.common.TaskStatus)6 ISE (io.druid.java.util.common.ISE)6 Access (io.druid.server.security.Access)6 Action (io.druid.server.security.Action)6