Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,42 @@ public Object apply(@Nullable int[] input)
}
) + '}';
}

@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

TimeAndDims that = (TimeAndDims) o;

if (timestamp != that.timestamp) {
return false;
}
if (dims.length != that.dims.length) {
return false;
}
for (int i = 0; i < dims.length; i++) {
if (!Arrays.equals(dims[i], that.dims[i])) {
return false;
}
}
return true;
}

@Override
public int hashCode()
{
int hash = (int) timestamp;
for (int i = 0; i < dims.length; i++) {
hash = 31 * hash + Arrays.hashCode(dims[i]);
}
return hash;
}
}

protected final Comparator<TimeAndDims> dimsComparator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package io.druid.segment.incremental;

import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.metamx.common.ISE;
Expand Down Expand Up @@ -47,6 +48,7 @@
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

/**
*/
Expand Down Expand Up @@ -91,41 +93,47 @@ public static Collection<?> constructorFeeder() throws IOException
dimensions,
metrics
);
return Arrays.asList(
new Object[][]{
{
new IndexCreator()

final List<Object[]> constructors = Lists.newArrayList();
for (final Boolean sortFacts : ImmutableList.of(false, true)) {
constructors.add(
new Object[]{
new IndexCreator()
{
@Override
public IncrementalIndex createIndex()
{
@Override
public IncrementalIndex createIndex()
{
return new OnheapIncrementalIndex(schema, true, 1000);
}
return new OnheapIncrementalIndex(schema, false, true, sortFacts, 1000);
}
},
{
new IndexCreator()
}
}
);
constructors.add(
new Object[]{
new IndexCreator()
{
@Override
public IncrementalIndex createIndex()
{
@Override
public IncrementalIndex createIndex()
{
return new OffheapIncrementalIndex(
schema, true, true, true, 1000000, new StupidPool<ByteBuffer>(
new Supplier<ByteBuffer>()
{
@Override
public ByteBuffer get()
{
return ByteBuffer.allocate(256 * 1024);
}
}
)
);
}
return new OffheapIncrementalIndex(
schema, true, true, sortFacts, 1000000, new StupidPool<ByteBuffer>(
new Supplier<ByteBuffer>()
{
@Override
public ByteBuffer get()
{
return ByteBuffer.allocate(256 * 1024);
}
}
)
);
}
}
}
);
}
}
);
}

return constructors;
}

@Test(expected = ISE.class)
Expand Down Expand Up @@ -199,7 +207,8 @@ public void testNullDimensionTransform() throws IndexSizeExceededException
ImmutableMap.<String, Object>of(
"string", Arrays.asList("A", null, ""),
"float", Arrays.asList(Float.MAX_VALUE, null, ""),
"long", Arrays.asList(Long.MIN_VALUE, null, ""))
"long", Arrays.asList(Long.MIN_VALUE, null, "")
)
)
);

Expand All @@ -209,4 +218,20 @@ public void testNullDimensionTransform() throws IndexSizeExceededException
Assert.assertArrayEquals(new Float[]{null, null, Float.MAX_VALUE}, (Object[]) row.getRaw("float"));
Assert.assertArrayEquals(new Long[]{null, null, Long.MIN_VALUE}, (Object[]) row.getRaw("long"));
}

@Test
public void sameRow() throws IndexSizeExceededException
{
MapBasedInputRow row = new MapBasedInputRow(
new DateTime().minus(1).getMillis(),
Lists.newArrayList("billy", "joe"),
ImmutableMap.<String, Object>of("billy", "A", "joe", "B")
);
IncrementalIndex index = closer.closeLater(indexCreator.createIndex());
index.add(row);
index.add(row);
index.add(row);

Assert.assertEquals(1, index.size());
}
}