Search in sources :

Example 26 with MapBasedRow

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);
}
Also used : MapBasedRow(io.druid.data.input.MapBasedRow) DateTime(org.joda.time.DateTime)

Example 27 with MapBasedRow

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));
}
Also used : LongSumAggregatorFactory(io.druid.query.aggregation.LongSumAggregatorFactory) MapBasedRow(io.druid.data.input.MapBasedRow) CountAggregatorFactory(io.druid.query.aggregation.CountAggregatorFactory) Test(org.junit.Test)

Example 28 with MapBasedRow

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)));
}
Also used : MapBasedRow(io.druid.data.input.MapBasedRow) Test(org.junit.Test)

Example 29 with MapBasedRow

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);
}
Also used : MapBasedRow(io.druid.data.input.MapBasedRow) SelectorDimFilter(io.druid.query.filter.SelectorDimFilter) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 30 with MapBasedRow

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);
}
Also used : MapBasedRow(io.druid.data.input.MapBasedRow) DateTime(org.joda.time.DateTime)

Aggregations

MapBasedRow (io.druid.data.input.MapBasedRow)34 Test (org.junit.Test)21 Row (io.druid.data.input.Row)16 GroupByQueryRunnerTest (io.druid.query.groupby.GroupByQueryRunnerTest)12 DateTime (org.joda.time.DateTime)11 File (java.io.File)9 Sequence (io.druid.java.util.common.guava.Sequence)7 Function (com.google.common.base.Function)6 MapBasedInputRow (io.druid.data.input.MapBasedInputRow)4 AggregationTestHelper (io.druid.query.aggregation.AggregationTestHelper)4 LongSumAggregatorFactory (io.druid.query.aggregation.LongSumAggregatorFactory)4 DimensionSpec (io.druid.query.dimension.DimensionSpec)4 List (java.util.List)4 Map (java.util.Map)4 Interval (org.joda.time.Interval)4 AggregatorsModule (io.druid.jackson.AggregatorsModule)3 AggregatorFactory (io.druid.query.aggregation.AggregatorFactory)3 SelectorDimFilter (io.druid.query.filter.SelectorDimFilter)3 GroupByQueryEngine (io.druid.query.groupby.GroupByQueryEngine)3 ISE (io.druid.java.util.common.ISE)2