Fix roaring extraction filter on empty values

This commit is contained in:
Charles Allen 2015-05-26 13:54:18 -07:00
parent 600b30566c
commit fd64c24e43
2 changed files with 28 additions and 19 deletions

View File

@ -66,14 +66,12 @@ public class ExtractionFilter implements Filter
return filters; return filters;
} }
private static final WrappedImmutableConciseBitmap ZERO_LENGTH_SET = new WrappedImmutableConciseBitmap(new ImmutableConciseSet());
@Override @Override
public ImmutableBitmap getBitmapIndex(BitmapIndexSelector selector) public ImmutableBitmap getBitmapIndex(BitmapIndexSelector selector)
{ {
final List<Filter> filters = makeFilters(selector); final List<Filter> filters = makeFilters(selector);
if (filters.isEmpty()) { if (filters.isEmpty()) {
return ZERO_LENGTH_SET; return selector.getBitmapFactory().makeEmptyImmutableBitmap();
} }
return new OrFilter(makeFilters(selector)).getBitmapIndex(selector); return new OrFilter(makeFilters(selector)).getBitmapIndex(selector);
} }

View File

@ -17,12 +17,13 @@
package io.druid.segment.filter; package io.druid.segment.filter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.metamx.collections.bitmap.BitmapFactory; import com.metamx.collections.bitmap.BitmapFactory;
import com.metamx.collections.bitmap.ConciseBitmapFactory; import com.metamx.collections.bitmap.ConciseBitmapFactory;
import com.metamx.collections.bitmap.ImmutableBitmap; import com.metamx.collections.bitmap.ImmutableBitmap;
import com.metamx.collections.bitmap.WrappedConciseBitmap; import com.metamx.collections.bitmap.MutableBitmap;
import com.metamx.collections.bitmap.WrappedImmutableConciseBitmap; import com.metamx.collections.bitmap.RoaringBitmapFactory;
import com.metamx.collections.spatial.ImmutableRTree; import com.metamx.collections.spatial.ImmutableRTree;
import io.druid.query.extraction.DimExtractionFn; import io.druid.query.extraction.DimExtractionFn;
import io.druid.query.extraction.ExtractionFn; import io.druid.query.extraction.ExtractionFn;
@ -31,21 +32,21 @@ import io.druid.query.filter.DimFilters;
import io.druid.query.filter.ExtractionDimFilter; import io.druid.query.filter.ExtractionDimFilter;
import io.druid.segment.data.ArrayIndexed; import io.druid.segment.data.ArrayIndexed;
import io.druid.segment.data.Indexed; import io.druid.segment.data.Indexed;
import it.uniroma3.mat.extendedset.intset.ConciseSet;
import it.uniroma3.mat.extendedset.intset.ImmutableConciseSet;
import org.junit.Assert; import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Map; import java.util.Map;
/** /**
* *
*/ */
@RunWith(Parameterized.class)
public class ExtractionDimFilterTest public class ExtractionDimFilterTest
{ {
private static final Map<String, String[]> DIM_VALS = ImmutableMap.<String, String[]>of( private static final Map<String, String[]> DIM_VALS = ImmutableMap.<String, String[]>of(
"foo", new String[]{"foo1","foo2","foo3"}, "foo", new String[]{"foo1", "foo2", "foo3"},
"bar", new String[]{"bar1"}, "bar", new String[]{"bar1"},
"baz", new String[]{"foo1"} "baz", new String[]{"foo1"}
); );
@ -54,19 +55,28 @@ public class ExtractionDimFilterTest
"foo1", "extractDimVal" "foo1", "extractDimVal"
); );
private static ImmutableBitmap foo1BitMap; @Parameterized.Parameters
public static Iterable<Object[]> constructorFeeder()
@BeforeClass
public static void setupStatic()
{ {
final ConciseSet conciseSet = new ConciseSet(); return ImmutableList.of(
conciseSet.add(1); new Object[]{new ConciseBitmapFactory()},
foo1BitMap = new WrappedImmutableConciseBitmap(ImmutableConciseSet.newImmutableFromMutable(conciseSet)); new Object[]{new RoaringBitmapFactory()}
);
} }
private static final BitmapIndexSelector BITMAP_INDEX_SELECTOR = new BitmapIndexSelector() public ExtractionDimFilterTest(BitmapFactory bitmapFactory)
{
final MutableBitmap mutableBitmap = bitmapFactory.makeEmptyMutableBitmap();
mutableBitmap.add(1);
this.foo1BitMap = bitmapFactory.makeImmutableBitmap(mutableBitmap);
this.factory = bitmapFactory;
}
private final BitmapFactory factory;
private final ImmutableBitmap foo1BitMap;
private final BitmapIndexSelector BITMAP_INDEX_SELECTOR = new BitmapIndexSelector()
{ {
private final ConciseBitmapFactory factory = new ConciseBitmapFactory();
@Override @Override
public Indexed<String> getDimensionValues(String dimension) public Indexed<String> getDimensionValues(String dimension)
{ {
@ -225,7 +235,8 @@ public class ExtractionDimFilterTest
} }
@Test @Test
public void testNot(){ public void testNot()
{
Assert.assertEquals( Assert.assertEquals(
1, Filters.convertDimensionFilters( 1, Filters.convertDimensionFilters(