mirror of https://github.com/apache/druid.git
Merge pull request #2769 from gianm/optimize-tests
BaseFilterTest: Test optimized filters too.
This commit is contained in:
commit
ad39080246
|
@ -21,6 +21,7 @@ package io.druid.segment.filter;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
@ -75,16 +76,19 @@ public abstract class BaseFilterTest
|
||||||
protected final Function<IndexBuilder, Pair<StorageAdapter, Closeable>> finisher;
|
protected final Function<IndexBuilder, Pair<StorageAdapter, Closeable>> finisher;
|
||||||
protected StorageAdapter adapter;
|
protected StorageAdapter adapter;
|
||||||
protected Closeable closeable;
|
protected Closeable closeable;
|
||||||
|
protected boolean optimize;
|
||||||
|
|
||||||
public BaseFilterTest(
|
public BaseFilterTest(
|
||||||
List<InputRow> rows,
|
List<InputRow> rows,
|
||||||
IndexBuilder indexBuilder,
|
IndexBuilder indexBuilder,
|
||||||
Function<IndexBuilder, Pair<StorageAdapter, Closeable>> finisher
|
Function<IndexBuilder, Pair<StorageAdapter, Closeable>> finisher,
|
||||||
|
boolean optimize
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this.rows = rows;
|
this.rows = rows;
|
||||||
this.indexBuilder = indexBuilder;
|
this.indexBuilder = indexBuilder;
|
||||||
this.finisher = finisher;
|
this.finisher = finisher;
|
||||||
|
this.optimize = optimize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@ -186,21 +190,24 @@ public abstract class BaseFilterTest
|
||||||
for (Map.Entry<String, BitmapSerdeFactory> bitmapSerdeFactoryEntry : bitmapSerdeFactories.entrySet()) {
|
for (Map.Entry<String, BitmapSerdeFactory> bitmapSerdeFactoryEntry : bitmapSerdeFactories.entrySet()) {
|
||||||
for (Map.Entry<String, IndexMerger> indexMergerEntry : indexMergers.entrySet()) {
|
for (Map.Entry<String, IndexMerger> indexMergerEntry : indexMergers.entrySet()) {
|
||||||
for (Map.Entry<String, Function<IndexBuilder, Pair<StorageAdapter, Closeable>>> finisherEntry : finishers.entrySet()) {
|
for (Map.Entry<String, Function<IndexBuilder, Pair<StorageAdapter, Closeable>>> finisherEntry : finishers.entrySet()) {
|
||||||
final String testName = String.format(
|
for (boolean optimize : ImmutableList.of(false, true)) {
|
||||||
"bitmaps[%s], indexMerger[%s], finisher[%s]",
|
final String testName = String.format(
|
||||||
bitmapSerdeFactoryEntry.getKey(),
|
"bitmaps[%s], indexMerger[%s], finisher[%s], optimize[%s]",
|
||||||
indexMergerEntry.getKey(),
|
bitmapSerdeFactoryEntry.getKey(),
|
||||||
finisherEntry.getKey()
|
indexMergerEntry.getKey(),
|
||||||
);
|
finisherEntry.getKey(),
|
||||||
final IndexBuilder indexBuilder = IndexBuilder.create()
|
optimize
|
||||||
.indexSpec(new IndexSpec(
|
);
|
||||||
bitmapSerdeFactoryEntry.getValue(),
|
final IndexBuilder indexBuilder = IndexBuilder.create()
|
||||||
null,
|
.indexSpec(new IndexSpec(
|
||||||
null
|
bitmapSerdeFactoryEntry.getValue(),
|
||||||
))
|
null,
|
||||||
.indexMerger(indexMergerEntry.getValue());
|
null
|
||||||
|
))
|
||||||
|
.indexMerger(indexMergerEntry.getValue());
|
||||||
|
|
||||||
constructors.add(new Object[]{testName, indexBuilder, finisherEntry.getValue()});
|
constructors.add(new Object[]{testName, indexBuilder, finisherEntry.getValue(), optimize});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -213,7 +220,7 @@ public abstract class BaseFilterTest
|
||||||
*/
|
*/
|
||||||
protected List<String> selectColumnValuesMatchingFilter(final DimFilter filter, final String selectColumn)
|
protected List<String> selectColumnValuesMatchingFilter(final DimFilter filter, final String selectColumn)
|
||||||
{
|
{
|
||||||
final Cursor cursor = makeCursor(Filters.toFilter(filter));
|
final Cursor cursor = makeCursor(Filters.toFilter(maybeOptimize(filter)));
|
||||||
final List<String> values = Lists.newArrayList();
|
final List<String> values = Lists.newArrayList();
|
||||||
final DimensionSelector selector = cursor.makeDimensionSelector(
|
final DimensionSelector selector = cursor.makeDimensionSelector(
|
||||||
new DefaultDimensionSpec(selectColumn, selectColumn)
|
new DefaultDimensionSpec(selectColumn, selectColumn)
|
||||||
|
@ -233,7 +240,7 @@ public abstract class BaseFilterTest
|
||||||
final Cursor cursor = makeCursor(null);
|
final Cursor cursor = makeCursor(null);
|
||||||
final Aggregator agg = new FilteredAggregatorFactory(
|
final Aggregator agg = new FilteredAggregatorFactory(
|
||||||
new CountAggregatorFactory("count"),
|
new CountAggregatorFactory("count"),
|
||||||
filter
|
maybeOptimize(filter)
|
||||||
).factorize(cursor);
|
).factorize(cursor);
|
||||||
|
|
||||||
for (; !cursor.isDone(); cursor.advance()) {
|
for (; !cursor.isDone(); cursor.advance()) {
|
||||||
|
@ -243,6 +250,14 @@ public abstract class BaseFilterTest
|
||||||
return agg.getLong();
|
return agg.getLong();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DimFilter maybeOptimize(final DimFilter dimFilter)
|
||||||
|
{
|
||||||
|
if (dimFilter == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return optimize ? dimFilter.optimize() : dimFilter;
|
||||||
|
}
|
||||||
|
|
||||||
private Cursor makeCursor(final Filter filter)
|
private Cursor makeCursor(final Filter filter)
|
||||||
{
|
{
|
||||||
final Sequence<Cursor> cursors = adapter.makeCursors(
|
final Sequence<Cursor> cursors = adapter.makeCursors(
|
||||||
|
|
|
@ -67,10 +67,11 @@ public class BoundFilterTest extends BaseFilterTest
|
||||||
public BoundFilterTest(
|
public BoundFilterTest(
|
||||||
String testName,
|
String testName,
|
||||||
IndexBuilder indexBuilder,
|
IndexBuilder indexBuilder,
|
||||||
Function<IndexBuilder, Pair<StorageAdapter, Closeable>> finisher
|
Function<IndexBuilder, Pair<StorageAdapter, Closeable>> finisher,
|
||||||
|
boolean optimize
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
super(ROWS, indexBuilder, finisher);
|
super(ROWS, indexBuilder, finisher, optimize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -80,10 +80,11 @@ public class InFilterTest extends BaseFilterTest
|
||||||
public InFilterTest(
|
public InFilterTest(
|
||||||
String testName,
|
String testName,
|
||||||
IndexBuilder indexBuilder,
|
IndexBuilder indexBuilder,
|
||||||
Function<IndexBuilder, Pair<StorageAdapter, Closeable>> finisher
|
Function<IndexBuilder, Pair<StorageAdapter, Closeable>> finisher,
|
||||||
|
boolean optimize
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
super(ROWS, indexBuilder, finisher);
|
super(ROWS, indexBuilder, finisher, optimize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
|
|
@ -68,10 +68,11 @@ public class NotFilterTest extends BaseFilterTest
|
||||||
public NotFilterTest(
|
public NotFilterTest(
|
||||||
String testName,
|
String testName,
|
||||||
IndexBuilder indexBuilder,
|
IndexBuilder indexBuilder,
|
||||||
Function<IndexBuilder, Pair<StorageAdapter, Closeable>> finisher
|
Function<IndexBuilder, Pair<StorageAdapter, Closeable>> finisher,
|
||||||
|
boolean optimize
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
super(ROWS, indexBuilder, finisher);
|
super(ROWS, indexBuilder, finisher, optimize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -71,10 +71,11 @@ public class SelectorFilterTest extends BaseFilterTest
|
||||||
public SelectorFilterTest(
|
public SelectorFilterTest(
|
||||||
String testName,
|
String testName,
|
||||||
IndexBuilder indexBuilder,
|
IndexBuilder indexBuilder,
|
||||||
Function<IndexBuilder, Pair<StorageAdapter, Closeable>> finisher
|
Function<IndexBuilder, Pair<StorageAdapter, Closeable>> finisher,
|
||||||
|
boolean optimize
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
super(ROWS, indexBuilder, finisher);
|
super(ROWS, indexBuilder, finisher, optimize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue