null check in IncrementalIndexAdapter.getDimValueLookup()

This commit is contained in:
Michael Schiff 2016-01-19 01:03:44 -08:00 committed by michael.schiff
parent fc09929503
commit 50ceec78a2
2 changed files with 84 additions and 38 deletions

View File

@ -156,45 +156,50 @@ public class IncrementalIndexAdapter implements IndexableAdapter
public Indexed<String> getDimValueLookup(String dimension) public Indexed<String> getDimValueLookup(String dimension)
{ {
final IncrementalIndex.DimDim dimDim = index.getDimensionValues(dimension); final IncrementalIndex.DimDim dimDim = index.getDimensionValues(dimension);
if (hasNullValueDimensions.contains(dimension)
&& !dimDim.contains(null)) if (dimDim != null) {
{ if (hasNullValueDimensions.contains(dimension)
dimDim.add(null); && !dimDim.contains(null))
{
dimDim.add(null);
}
dimDim.sort();
return new Indexed<String>()
{
@Override
public Class<? extends String> getClazz()
{
return String.class;
}
@Override
public int size()
{
return dimDim.size();
}
@Override
public String get(int index)
{
return dimDim.getSortedValue(index);
}
@Override
public int indexOf(String value)
{
return dimDim.getSortedId(value);
}
@Override
public Iterator<String> iterator()
{
return IndexedIterable.create(this).iterator();
}
};
} else {
return null;
} }
dimDim.sort();
return new Indexed<String>()
{
@Override
public Class<? extends String> getClazz()
{
return String.class;
}
@Override
public int size()
{
return dimDim.size();
}
@Override
public String get(int index)
{
return dimDim.getSortedValue(index);
}
@Override
public int indexOf(String value)
{
return dimDim.getSortedId(value);
}
@Override
public Iterator<String> iterator()
{
return IndexedIterable.create(this).iterator();
}
};
} }
@Override @Override

View File

@ -26,6 +26,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.metamx.collections.bitmap.RoaringBitmapFactory;
import io.druid.data.input.MapBasedInputRow; import io.druid.data.input.MapBasedInputRow;
import io.druid.data.input.impl.DimensionsSpec; import io.druid.data.input.impl.DimensionsSpec;
import io.druid.granularity.QueryGranularity; import io.druid.granularity.QueryGranularity;
@ -44,6 +45,9 @@ import io.druid.segment.incremental.IncrementalIndex;
import io.druid.segment.incremental.IncrementalIndexAdapter; import io.druid.segment.incremental.IncrementalIndexAdapter;
import io.druid.segment.incremental.IncrementalIndexSchema; import io.druid.segment.incremental.IncrementalIndexSchema;
import io.druid.segment.incremental.OnheapIncrementalIndex; import io.druid.segment.incremental.OnheapIncrementalIndex;
import org.joda.time.DateTime;
import io.druid.segment.incremental.IndexSizeExceededException;
import org.joda.time.Interval;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@ -53,6 +57,7 @@ import org.junit.runners.Parameterized;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -1428,6 +1433,42 @@ public class IndexMergerTest
} }
public void testMismatchedDimensions() throws IOException, IndexSizeExceededException
{
IncrementalIndex index1 = IncrementalIndexTest.createIndex(new AggregatorFactory[]{
new LongSumAggregatorFactory("A", "A")
});
index1.add(new MapBasedInputRow(1L, Lists.newArrayList("d1", "d2"), ImmutableMap.<String, Object>of("d1", "a", "d2", "z", "A", 1)));
closer.closeLater(index1);
IncrementalIndex index2 = IncrementalIndexTest.createIndex(new AggregatorFactory[]{
new LongSumAggregatorFactory("A", "A"),
new LongSumAggregatorFactory("C", "C")
});
index2.add(new MapBasedInputRow(1l, Lists.newArrayList("d2"), ImmutableMap.<String, Object>of("d2", "z", "A", 2, "C", 100)));
closer.closeLater(index2);
Interval interval = new Interval(0, new DateTime().getMillis());
RoaringBitmapFactory factory = new RoaringBitmapFactory();
ArrayList<IndexableAdapter> toMerge = Lists.<IndexableAdapter>newArrayList(
new IncrementalIndexAdapter(interval, index1, factory),
new IncrementalIndexAdapter(interval, index2, factory)
);
final File tmpDirMerged = temporaryFolder.newFolder();
INDEX_MERGER.merge(
toMerge,
new AggregatorFactory[] {
new LongSumAggregatorFactory("A", "A"),
new LongSumAggregatorFactory("C", "C"),
},
tmpDirMerged,
indexSpec
);
}
private IncrementalIndex getIndexD3() throws Exception private IncrementalIndex getIndexD3() throws Exception
{ {
IncrementalIndex toPersist1 = new OnheapIncrementalIndex( IncrementalIndex toPersist1 = new OnheapIncrementalIndex(