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());
}
}
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());
}
});
}
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());
}
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;
}
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);
}
}
Aggregations