mirror of https://github.com/apache/druid.git
Fix Extraction Filter cast problems for empty results
This commit is contained in:
parent
e1399b7ce4
commit
e97d22a10a
|
@ -19,7 +19,7 @@ package io.druid.segment.filter;
|
|||
|
||||
import com.google.common.collect.Lists;
|
||||
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.filter.BitmapIndexSelector;
|
||||
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.segment.ColumnSelectorFactory;
|
||||
import io.druid.segment.data.Indexed;
|
||||
import it.uniroma3.mat.extendedset.intset.ImmutableConciseSet;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -65,12 +66,14 @@ public class ExtractionFilter implements Filter
|
|||
return filters;
|
||||
}
|
||||
|
||||
private static final WrappedImmutableConciseBitmap ZERO_LENGTH_SET = new WrappedImmutableConciseBitmap(new ImmutableConciseSet());
|
||||
|
||||
@Override
|
||||
public ImmutableBitmap getBitmapIndex(BitmapIndexSelector selector)
|
||||
{
|
||||
final List<Filter> filters = makeFilters(selector);
|
||||
if (filters.isEmpty()) {
|
||||
return new WrappedConciseBitmap();
|
||||
return ZERO_LENGTH_SET;
|
||||
}
|
||||
return new OrFilter(makeFilters(selector)).getBitmapIndex(selector);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import com.metamx.collections.bitmap.BitmapFactory;
|
|||
import com.metamx.collections.bitmap.ConciseBitmapFactory;
|
||||
import com.metamx.collections.bitmap.ImmutableBitmap;
|
||||
import com.metamx.collections.bitmap.WrappedConciseBitmap;
|
||||
import com.metamx.collections.bitmap.WrappedImmutableConciseBitmap;
|
||||
import com.metamx.collections.spatial.ImmutableRTree;
|
||||
import io.druid.query.extraction.DimExtractionFn;
|
||||
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.Indexed;
|
||||
import it.uniroma3.mat.extendedset.intset.ConciseSet;
|
||||
import it.uniroma3.mat.extendedset.intset.ImmutableConciseSet;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
@ -59,11 +61,12 @@ public class ExtractionDimFilterTest
|
|||
{
|
||||
final ConciseSet conciseSet = new ConciseSet();
|
||||
conciseSet.add(1);
|
||||
foo1BitMap = new WrappedConciseBitmap(conciseSet);
|
||||
foo1BitMap = new WrappedImmutableConciseBitmap(ImmutableConciseSet.newImmutableFromMutable(conciseSet));
|
||||
}
|
||||
|
||||
private static final BitmapIndexSelector BITMAP_INDEX_SELECTOR = new BitmapIndexSelector()
|
||||
{
|
||||
private final ConciseBitmapFactory factory = new ConciseBitmapFactory();
|
||||
@Override
|
||||
public Indexed<String> getDimensionValues(String dimension)
|
||||
{
|
||||
|
@ -80,7 +83,7 @@ public class ExtractionDimFilterTest
|
|||
@Override
|
||||
public BitmapFactory getBitmapFactory()
|
||||
{
|
||||
return new ConciseBitmapFactory();
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -183,4 +186,72 @@ public class ExtractionDimFilterTest
|
|||
).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()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue