Skip to content

Commit

Permalink
Merge pull request apache#2769 from gianm/optimize-tests
Browse files Browse the repository at this point in the history
BaseFilterTest: Test optimized filters too.
  • Loading branch information
fjy committed Apr 1, 2016
2 parents 693a4b4 + 23364a4 commit ad39080
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -75,16 +76,19 @@ public abstract class BaseFilterTest
protected final Function<IndexBuilder, Pair<StorageAdapter, Closeable>> finisher;
protected StorageAdapter adapter;
protected Closeable closeable;
protected boolean optimize;

public BaseFilterTest(
List<InputRow> rows,
IndexBuilder indexBuilder,
Function<IndexBuilder, Pair<StorageAdapter, Closeable>> finisher
Function<IndexBuilder, Pair<StorageAdapter, Closeable>> finisher,
boolean optimize
)
{
this.rows = rows;
this.indexBuilder = indexBuilder;
this.finisher = finisher;
this.optimize = optimize;
}

@Before
Expand Down Expand Up @@ -186,21 +190,24 @@ public void close() throws IOException
for (Map.Entry<String, BitmapSerdeFactory> bitmapSerdeFactoryEntry : bitmapSerdeFactories.entrySet()) {
for (Map.Entry<String, IndexMerger> indexMergerEntry : indexMergers.entrySet()) {
for (Map.Entry<String, Function<IndexBuilder, Pair<StorageAdapter, Closeable>>> finisherEntry : finishers.entrySet()) {
final String testName = String.format(
"bitmaps[%s], indexMerger[%s], finisher[%s]",
bitmapSerdeFactoryEntry.getKey(),
indexMergerEntry.getKey(),
finisherEntry.getKey()
);
final IndexBuilder indexBuilder = IndexBuilder.create()
.indexSpec(new IndexSpec(
bitmapSerdeFactoryEntry.getValue(),
null,
null
))
.indexMerger(indexMergerEntry.getValue());
for (boolean optimize : ImmutableList.of(false, true)) {
final String testName = String.format(
"bitmaps[%s], indexMerger[%s], finisher[%s], optimize[%s]",
bitmapSerdeFactoryEntry.getKey(),
indexMergerEntry.getKey(),
finisherEntry.getKey(),
optimize
);
final IndexBuilder indexBuilder = IndexBuilder.create()
.indexSpec(new IndexSpec(
bitmapSerdeFactoryEntry.getValue(),
null,
null
))
.indexMerger(indexMergerEntry.getValue());

constructors.add(new Object[]{testName, indexBuilder, finisherEntry.getValue()});
constructors.add(new Object[]{testName, indexBuilder, finisherEntry.getValue(), optimize});
}
}
}
}
Expand All @@ -213,7 +220,7 @@ public void close() throws IOException
*/
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 DimensionSelector selector = cursor.makeDimensionSelector(
new DefaultDimensionSpec(selectColumn, selectColumn)
Expand All @@ -233,7 +240,7 @@ protected long selectCountUsingFilteredAggregator(final DimFilter filter)
final Cursor cursor = makeCursor(null);
final Aggregator agg = new FilteredAggregatorFactory(
new CountAggregatorFactory("count"),
filter
maybeOptimize(filter)
).factorize(cursor);

for (; !cursor.isDone(); cursor.advance()) {
Expand All @@ -243,6 +250,14 @@ protected long selectCountUsingFilteredAggregator(final DimFilter filter)
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)
{
final Sequence<Cursor> cursors = adapter.makeCursors(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ public class BoundFilterTest extends BaseFilterTest
public BoundFilterTest(
String testName,
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ public static Collection<Object[]> constructorFeeder() throws IOException
public InFilterTest(
String testName,
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ public class NotFilterTest extends BaseFilterTest
public NotFilterTest(
String testName,
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ public class SelectorFilterTest extends BaseFilterTest
public SelectorFilterTest(
String testName,
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
Expand Down

0 comments on commit ad39080

Please sign in to comment.