Fix Extraction Filter cast problems for empty results

This commit is contained in:
Charles Allen 2015-05-22 15:20:11 -07:00
parent e1399b7ce4
commit e97d22a10a
2 changed files with 78 additions and 4 deletions

View File

@ -19,7 +19,7 @@ package io.druid.segment.filter;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.metamx.collections.bitmap.ImmutableBitmap; import com.metamx.collections.bitmap.ImmutableBitmap;
import com.metamx.collections.bitmap.WrappedConciseBitmap; import com.metamx.collections.bitmap.WrappedImmutableConciseBitmap;
import io.druid.query.extraction.ExtractionFn; import io.druid.query.extraction.ExtractionFn;
import io.druid.query.filter.BitmapIndexSelector; import io.druid.query.filter.BitmapIndexSelector;
import io.druid.query.filter.Filter; import io.druid.query.filter.Filter;
@ -27,6 +27,7 @@ import io.druid.query.filter.ValueMatcher;
import io.druid.query.filter.ValueMatcherFactory; import io.druid.query.filter.ValueMatcherFactory;
import io.druid.segment.ColumnSelectorFactory; import io.druid.segment.ColumnSelectorFactory;
import io.druid.segment.data.Indexed; import io.druid.segment.data.Indexed;
import it.uniroma3.mat.extendedset.intset.ImmutableConciseSet;
import java.util.List; import java.util.List;
@ -65,12 +66,14 @@ 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 new WrappedConciseBitmap(); return ZERO_LENGTH_SET;
} }
return new OrFilter(makeFilters(selector)).getBitmapIndex(selector); return new OrFilter(makeFilters(selector)).getBitmapIndex(selector);
} }

View File

@ -22,6 +22,7 @@ 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.WrappedConciseBitmap;
import com.metamx.collections.bitmap.WrappedImmutableConciseBitmap;
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,6 +32,7 @@ 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.ConciseSet;
import it.uniroma3.mat.extendedset.intset.ImmutableConciseSet;
import org.junit.Assert; import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -59,11 +61,12 @@ public class ExtractionDimFilterTest
{ {
final ConciseSet conciseSet = new ConciseSet(); final ConciseSet conciseSet = new ConciseSet();
conciseSet.add(1); conciseSet.add(1);
foo1BitMap = new WrappedConciseBitmap(conciseSet); foo1BitMap = new WrappedImmutableConciseBitmap(ImmutableConciseSet.newImmutableFromMutable(conciseSet));
} }
private static final BitmapIndexSelector BITMAP_INDEX_SELECTOR = new BitmapIndexSelector() private static 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)
{ {
@ -80,7 +83,7 @@ public class ExtractionDimFilterTest
@Override @Override
public BitmapFactory getBitmapFactory() public BitmapFactory getBitmapFactory()
{ {
return new ConciseBitmapFactory(); return factory;
} }
@Override @Override
@ -183,4 +186,72 @@ public class ExtractionDimFilterTest
).getBitmapIndex(BITMAP_INDEX_SELECTOR).size() ).getBitmapIndex(BITMAP_INDEX_SELECTOR).size()
); );
} }
@Test
public void testAnd()
{
Assert.assertEquals(
1, Filters.convertDimensionFilters(
DimFilters.or(
new ExtractionDimFilter(
"foo",
"extractDimVal",
DIM_EXTRACTION_FN,
null
)
)
).getBitmapIndex(BITMAP_INDEX_SELECTOR).size()
);
Assert.assertEquals(
1,
Filters.convertDimensionFilters(
DimFilters.and(
new ExtractionDimFilter(
"foo",
"extractDimVal",
DIM_EXTRACTION_FN,
null
),
new ExtractionDimFilter(
"foo",
"extractDimVal",
DIM_EXTRACTION_FN,
null
)
)
).getBitmapIndex(BITMAP_INDEX_SELECTOR).size()
);
}
@Test
public void testNot(){
Assert.assertEquals(
1, Filters.convertDimensionFilters(
DimFilters.or(
new ExtractionDimFilter(
"foo",
"extractDimVal",
DIM_EXTRACTION_FN,
null
)
)
).getBitmapIndex(BITMAP_INDEX_SELECTOR).size()
);
Assert.assertEquals(
1,
Filters.convertDimensionFilters(
DimFilters.not(
new ExtractionDimFilter(
"foo",
"DOES NOT EXIST",
DIM_EXTRACTION_FN,
null
)
)
).getBitmapIndex(BITMAP_INDEX_SELECTOR).size()
);
}
} }