use of io.druid.data.input.MapBasedRow in project druid by druid-io.
the class GroupByQueryRunnerTestHelper method createExpectedRow.
public static Row createExpectedRow(final DateTime timestamp, Object... vals) {
Preconditions.checkArgument(vals.length % 2 == 0);
Map<String, Object> theVals = Maps.newHashMap();
for (int i = 0; i < vals.length; i += 2) {
theVals.put(vals[i].toString(), vals[i + 1]);
}
DateTime ts = new DateTime(timestamp);
return new MapBasedRow(ts, theVals);
}
use of io.druid.data.input.MapBasedRow in project druid by druid-io.
the class BufferGrouperTest method testSimple.
@Test
public void testSimple() {
final TestColumnSelectorFactory columnSelectorFactory = GrouperTestUtil.newColumnSelectorFactory();
final Grouper<Integer> grouper = new BufferGrouper<>(Suppliers.ofInstance(ByteBuffer.allocate(1000)), GrouperTestUtil.intKeySerde(), columnSelectorFactory, new AggregatorFactory[] { new LongSumAggregatorFactory("valueSum", "value"), new CountAggregatorFactory("count") }, Integer.MAX_VALUE, 0, 0);
grouper.init();
columnSelectorFactory.setRow(new MapBasedRow(0, ImmutableMap.<String, Object>of("value", 10L)));
grouper.aggregate(12);
grouper.aggregate(6);
grouper.aggregate(10);
grouper.aggregate(6);
grouper.aggregate(12);
grouper.aggregate(12);
final List<Grouper.Entry<Integer>> expected = ImmutableList.of(new Grouper.Entry<>(6, new Object[] { 20L, 2L }), new Grouper.Entry<>(10, new Object[] { 10L, 1L }), new Grouper.Entry<>(12, new Object[] { 30L, 3L }));
final List<Grouper.Entry<Integer>> unsortedEntries = Lists.newArrayList(grouper.iterator(false));
final List<Grouper.Entry<Integer>> sortedEntries = Lists.newArrayList(grouper.iterator(true));
Assert.assertEquals(expected, sortedEntries);
Assert.assertEquals(expected, Ordering.from(new Comparator<Grouper.Entry<Integer>>() {
@Override
public int compare(Grouper.Entry<Integer> o1, Grouper.Entry<Integer> o2) {
return Ints.compare(o1.getKey(), o2.getKey());
}
}).sortedCopy(unsortedEntries));
}
use of io.druid.data.input.MapBasedRow in project druid by druid-io.
the class BufferGrouperTest method testNoGrowing.
@Test
public void testNoGrowing() {
final TestColumnSelectorFactory columnSelectorFactory = GrouperTestUtil.newColumnSelectorFactory();
final Grouper<Integer> grouper = makeGrouper(columnSelectorFactory, 10000, Integer.MAX_VALUE);
final int expectedMaxSize = 267;
columnSelectorFactory.setRow(new MapBasedRow(0, ImmutableMap.<String, Object>of("value", 10L)));
for (int i = 0; i < expectedMaxSize; i++) {
Assert.assertTrue(String.valueOf(i), grouper.aggregate(i));
}
Assert.assertFalse(grouper.aggregate(expectedMaxSize));
// Aggregate slightly different row
columnSelectorFactory.setRow(new MapBasedRow(0, ImmutableMap.<String, Object>of("value", 11L)));
for (int i = 0; i < expectedMaxSize; i++) {
Assert.assertTrue(String.valueOf(i), grouper.aggregate(i));
}
Assert.assertFalse(grouper.aggregate(expectedMaxSize));
final List<Grouper.Entry<Integer>> expected = Lists.newArrayList();
for (int i = 0; i < expectedMaxSize; i++) {
expected.add(new Grouper.Entry<>(i, new Object[] { 21L, 2L }));
}
Assert.assertEquals(expected, Lists.newArrayList(grouper.iterator(true)));
}
use of io.druid.data.input.MapBasedRow in project druid by druid-io.
the class DimFilterHavingSpecTest method testConcurrentUsage.
@Test(timeout = 60_000L)
// Doesn't always pass. The check in "eval" is best effort and not guaranteed to detect concurrent usage.
@Ignore
public void testConcurrentUsage() throws Exception {
final ExecutorService exec = Executors.newFixedThreadPool(2);
final DimFilterHavingSpec havingSpec = new DimFilterHavingSpec(new SelectorDimFilter("foo", "1", null));
final List<Future<?>> futures = new ArrayList<>();
for (int i = 0; i < 2; i++) {
final MapBasedRow row = new MapBasedRow(0, ImmutableMap.<String, Object>of("foo", String.valueOf(i)));
futures.add(exec.submit(new Runnable() {
@Override
public void run() {
havingSpec.setRowSignature(null);
while (!Thread.interrupted()) {
havingSpec.eval(row);
}
}
}));
}
expectedException.expect(ExecutionException.class);
expectedException.expectCause(CoreMatchers.<IllegalStateException>instanceOf(IllegalStateException.class));
expectedException.expectCause(ThrowableMessageMatcher.hasMessage(CoreMatchers.containsString("concurrent 'eval' calls not permitted")));
try {
for (Future<?> future : futures) {
future.get();
}
} finally {
exec.shutdownNow();
}
// Not reached
Assert.assertTrue(false);
}
use of io.druid.data.input.MapBasedRow in project druid by druid-io.
the class DefaultLimitSpecTest method createRow.
private Row createRow(String timestamp, Object... vals) {
Preconditions.checkArgument(vals.length % 2 == 0);
Map<String, Object> theVals = Maps.newHashMap();
for (int i = 0; i < vals.length; i += 2) {
theVals.put(vals[i].toString(), vals[i + 1]);
}
DateTime ts = new DateTime(timestamp);
return new MapBasedRow(ts, theVals);
}
Aggregations