address code review comments

This commit is contained in:
fjy 2014-05-27 19:47:13 -07:00
parent 9f62589d71
commit 8bcf4bc60e
12 changed files with 155 additions and 12 deletions

View File

@ -77,7 +77,7 @@ public class DefaultDimensionSpec implements DimensionSpec
}
@Override
public boolean canTransformValues()
public boolean preservesOrdering()
{
return false;
}

View File

@ -40,5 +40,5 @@ public interface DimensionSpec
public byte[] getCacheKey();
public boolean canTransformValues();
public boolean preservesOrdering();
}

View File

@ -84,9 +84,9 @@ public class ExtractionDimensionSpec implements DimensionSpec
}
@Override
public boolean canTransformValues()
public boolean preservesOrdering()
{
return dimExtractionFn.canTransformValues();
return dimExtractionFn.preservesOrdering();
}
@Override

View File

@ -38,5 +38,5 @@ public interface DimExtractionFn
public String apply(String dimValue);
public boolean canTransformValues();
public boolean preservesOrdering();
}

View File

@ -94,7 +94,7 @@ public class JavascriptDimExtractionFn implements DimExtractionFn
}
@Override
public boolean canTransformValues()
public boolean preservesOrdering()
{
return true;
}

View File

@ -68,7 +68,7 @@ public class PartialDimExtractionFn implements DimExtractionFn
}
@Override
public boolean canTransformValues()
public boolean preservesOrdering()
{
return false;
}

View File

@ -68,7 +68,7 @@ public class RegexDimExtractionFn implements DimExtractionFn
}
@Override
public boolean canTransformValues()
public boolean preservesOrdering()
{
return true;
}

View File

@ -64,7 +64,7 @@ public class SearchQuerySpecDimExtractionFn implements DimExtractionFn
}
@Override
public boolean canTransformValues()
public boolean preservesOrdering()
{
return false;
}

View File

@ -88,7 +88,7 @@ public class TimeDimExtractionFn implements DimExtractionFn
}
@Override
public boolean canTransformValues()
public boolean preservesOrdering()
{
return true;
}

View File

@ -65,7 +65,7 @@ public class DimExtractionTopNAlgorithm extends BaseTopNAlgorithm<Aggregator[][]
query,
params.getCardinality()
);
if (query.getDimensionSpec().canTransformValues()) {
if (query.getDimensionSpec().preservesOrdering()) {
return provider.build();
}
return query.getTopNMetricSpec().configureOptimizer(provider).build();

View File

@ -116,7 +116,7 @@ public class PooledTopNAlgorithm
{
final TopNMetricSpecBuilder<int[]> arrayProvider = params.getArrayProvider();
if (query.getDimensionSpec().canTransformValues()) {
if (query.getDimensionSpec().preservesOrdering()) {
return arrayProvider.build();
}

View File

@ -1211,6 +1211,149 @@ public class TopNQueryRunnerTest
TestHelper.assertExpectedResults(expectedResults, runner.run(query));
}
@Test
public void testTopNLexicographicDimExtraction()
{
TopNQuery query = new TopNQueryBuilder()
.dataSource(QueryRunnerTestHelper.dataSource)
.granularity(QueryRunnerTestHelper.allGran)
.dimension(
new ExtractionDimensionSpec(
providerDimension, providerDimension, new RegexDimExtractionFn("(.)")
)
)
.metric(new LexicographicTopNMetricSpec(null))
.threshold(4)
.intervals(QueryRunnerTestHelper.firstToThird)
.aggregators(QueryRunnerTestHelper.commonAggregators)
.postAggregators(Arrays.<PostAggregator>asList(QueryRunnerTestHelper.addRowsIndexConstant))
.build();
List<Result<TopNResultValue>> expectedResults = Arrays.asList(
new Result<TopNResultValue>(
new DateTime("2011-04-01T00:00:00.000Z"),
new TopNResultValue(
Arrays.<Map<String, Object>>asList(
ImmutableMap.<String, Object>of(
providerDimension, "s",
"rows", 18L,
"index", 2231.8768157958984D,
"addRowsIndexConstant", 2250.8768157958984D,
"uniques", QueryRunnerTestHelper.UNIQUES_9
),
ImmutableMap.<String, Object>of(
providerDimension, "t",
"rows", 4L,
"index", 5351.814697265625D,
"addRowsIndexConstant", 5356.814697265625D,
"uniques", QueryRunnerTestHelper.UNIQUES_2
),
ImmutableMap.<String, Object>of(
providerDimension, "u",
"rows", 4L,
"index", 4875.669677734375D,
"addRowsIndexConstant", 4880.669677734375D,
"uniques", QueryRunnerTestHelper.UNIQUES_2
)
)
)
)
);
TestHelper.assertExpectedResults(expectedResults, runner.run(query));
}
@Test
public void testTopNLexicographicDimExtractionWithPreviousStop()
{
TopNQuery query = new TopNQueryBuilder()
.dataSource(QueryRunnerTestHelper.dataSource)
.granularity(QueryRunnerTestHelper.allGran)
.dimension(
new ExtractionDimensionSpec(
providerDimension, providerDimension, new RegexDimExtractionFn("(.)")
)
)
.metric(new LexicographicTopNMetricSpec("spot"))
.threshold(4)
.intervals(QueryRunnerTestHelper.firstToThird)
.aggregators(QueryRunnerTestHelper.commonAggregators)
.postAggregators(Arrays.<PostAggregator>asList(QueryRunnerTestHelper.addRowsIndexConstant))
.build();
List<Result<TopNResultValue>> expectedResults = Arrays.asList(
new Result<TopNResultValue>(
new DateTime("2011-04-01T00:00:00.000Z"),
new TopNResultValue(
Arrays.<Map<String, Object>>asList(
ImmutableMap.<String, Object>of(
providerDimension, "t",
"rows", 4L,
"index", 5351.814697265625D,
"addRowsIndexConstant", 5356.814697265625D,
"uniques", QueryRunnerTestHelper.UNIQUES_2
),
ImmutableMap.<String, Object>of(
providerDimension, "u",
"rows", 4L,
"index", 4875.669677734375D,
"addRowsIndexConstant", 4880.669677734375D,
"uniques", QueryRunnerTestHelper.UNIQUES_2
)
)
)
)
);
TestHelper.assertExpectedResults(expectedResults, runner.run(query));
}
@Test
public void testInvertedTopNLexicographicDimExtractionWithPreviousStop()
{
TopNQuery query = new TopNQueryBuilder()
.dataSource(QueryRunnerTestHelper.dataSource)
.granularity(QueryRunnerTestHelper.allGran)
.dimension(
new ExtractionDimensionSpec(
providerDimension, providerDimension, new RegexDimExtractionFn("(.)")
)
)
.metric(new InvertedTopNMetricSpec(new LexicographicTopNMetricSpec("u")))
.threshold(4)
.intervals(QueryRunnerTestHelper.firstToThird)
.aggregators(QueryRunnerTestHelper.commonAggregators)
.postAggregators(Arrays.<PostAggregator>asList(QueryRunnerTestHelper.addRowsIndexConstant))
.build();
List<Result<TopNResultValue>> expectedResults = Arrays.asList(
new Result<TopNResultValue>(
new DateTime("2011-04-01T00:00:00.000Z"),
new TopNResultValue(
Arrays.<Map<String, Object>>asList(
ImmutableMap.<String, Object>of(
providerDimension, "t",
"rows", 4L,
"index", 5351.814697265625D,
"addRowsIndexConstant", 5356.814697265625D,
"uniques", QueryRunnerTestHelper.UNIQUES_2
),
ImmutableMap.<String, Object>of(
providerDimension, "s",
"rows", 18L,
"index", 2231.8768157958984D,
"addRowsIndexConstant", 2250.8768157958984D,
"uniques", QueryRunnerTestHelper.UNIQUES_9
)
)
)
)
);
TestHelper.assertExpectedResults(expectedResults, runner.run(query));
}
@Test
public void testInvertedTopNQuery()
{