fix brokeness with dim extraction dim specs

This commit is contained in:
fjy 2014-05-27 17:25:00 -07:00
parent b27d9af0ef
commit b9015cee34
13 changed files with 82 additions and 7 deletions

View File

@ -76,6 +76,12 @@ public class DefaultDimensionSpec implements DimensionSpec
.array(); .array();
} }
@Override
public boolean canTransformValues()
{
return false;
}
@Override @Override
public String toString() public String toString()
{ {

View File

@ -33,7 +33,12 @@ import io.druid.query.extraction.DimExtractionFn;
public interface DimensionSpec public interface DimensionSpec
{ {
public String getDimension(); public String getDimension();
public String getOutputName(); public String getOutputName();
public DimExtractionFn getDimExtractionFn(); public DimExtractionFn getDimExtractionFn();
public byte[] getCacheKey(); public byte[] getCacheKey();
public boolean canTransformValues();
} }

View File

@ -83,6 +83,12 @@ public class ExtractionDimensionSpec implements DimensionSpec
.array(); .array();
} }
@Override
public boolean canTransformValues()
{
return dimExtractionFn.canTransformValues();
}
@Override @Override
public String toString() public String toString()
{ {

View File

@ -24,7 +24,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
/** /**
*/ */
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property="type") @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonSubTypes(value = { @JsonSubTypes(value = {
@JsonSubTypes.Type(name = "time", value = TimeDimExtractionFn.class), @JsonSubTypes.Type(name = "time", value = TimeDimExtractionFn.class),
@JsonSubTypes.Type(name = "regex", value = RegexDimExtractionFn.class), @JsonSubTypes.Type(name = "regex", value = RegexDimExtractionFn.class),
@ -35,5 +35,8 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
public interface DimExtractionFn public interface DimExtractionFn
{ {
public byte[] getCacheKey(); public byte[] getCacheKey();
public String apply(String dimValue); public String apply(String dimValue);
public boolean canTransformValues();
} }

View File

@ -92,4 +92,10 @@ public class JavascriptDimExtractionFn implements DimExtractionFn
{ {
return fn.apply(dimValue); return fn.apply(dimValue);
} }
@Override
public boolean canTransformValues()
{
return true;
}
} }

View File

@ -67,6 +67,12 @@ public class PartialDimExtractionFn implements DimExtractionFn
return expr; return expr;
} }
@Override
public boolean canTransformValues()
{
return false;
}
@Override @Override
public String toString() public String toString()
{ {

View File

@ -67,6 +67,12 @@ public class RegexDimExtractionFn implements DimExtractionFn
return expr; return expr;
} }
@Override
public boolean canTransformValues()
{
return true;
}
@Override @Override
public String toString() public String toString()
{ {

View File

@ -63,6 +63,12 @@ public class SearchQuerySpecDimExtractionFn implements DimExtractionFn
return searchQuerySpec.accept(dimValue) ? dimValue : null; return searchQuerySpec.accept(dimValue) ? dimValue : null;
} }
@Override
public boolean canTransformValues()
{
return false;
}
@Override @Override
public String toString() public String toString()
{ {

View File

@ -87,6 +87,12 @@ public class TimeDimExtractionFn implements DimExtractionFn
return resultFormat; return resultFormat;
} }
@Override
public boolean canTransformValues()
{
return true;
}
@Override @Override
public String toString() public String toString()
{ {

View File

@ -62,7 +62,12 @@ public class AggregateTopNMetricFirstAlgorithm implements TopNAlgorithm<int[], T
DimensionSelector dimSelector, Cursor cursor DimensionSelector dimSelector, Cursor cursor
) )
{ {
return new TopNParams(dimSelector, cursor, dimSelector.getValueCardinality(), Integer.MAX_VALUE); return new TopNParams(
dimSelector,
cursor,
dimSelector.getValueCardinality(),
Integer.MAX_VALUE
);
} }
@Override @Override

View File

@ -49,15 +49,26 @@ public class DimExtractionTopNAlgorithm extends BaseTopNAlgorithm<Aggregator[][]
final DimensionSelector dimSelector, final Cursor cursor final DimensionSelector dimSelector, final Cursor cursor
) )
{ {
return new TopNParams(dimSelector, cursor, dimSelector.getValueCardinality(), Integer.MAX_VALUE); return new TopNParams(
dimSelector,
cursor,
dimSelector.getValueCardinality(),
Integer.MAX_VALUE
);
} }
@Override @Override
protected Aggregator[][] makeDimValSelector(TopNParams params, int numProcessed, int numToProcess) protected Aggregator[][] makeDimValSelector(TopNParams params, int numProcessed, int numToProcess)
{ {
return query.getTopNMetricSpec().configureOptimizer( final AggregatorArrayProvider provider = new AggregatorArrayProvider(
new AggregatorArrayProvider(params.getDimSelector(), query, params.getCardinality()) params.getDimSelector(),
).build(); query,
params.getCardinality()
);
if (query.getDimensionSpec().canTransformValues()) {
return provider.build();
}
return query.getTopNMetricSpec().configureOptimizer(provider).build();
} }
@Override @Override

View File

@ -116,6 +116,10 @@ public class PooledTopNAlgorithm
{ {
final TopNMetricSpecBuilder<int[]> arrayProvider = params.getArrayProvider(); final TopNMetricSpecBuilder<int[]> arrayProvider = params.getArrayProvider();
if (query.getDimensionSpec().canTransformValues()) {
return arrayProvider.build();
}
arrayProvider.ignoreFirstN(numProcessed); arrayProvider.ignoreFirstN(numProcessed);
arrayProvider.keepOnlyN(numToProcess); arrayProvider.keepOnlyN(numToProcess);
return query.getTopNMetricSpec().configureOptimizer(arrayProvider).build(); return query.getTopNMetricSpec().configureOptimizer(arrayProvider).build();

View File

@ -31,7 +31,12 @@ public class TopNParams
private final int cardinality; private final int cardinality;
private final int numValuesPerPass; private final int numValuesPerPass;
protected TopNParams(DimensionSelector dimSelector, Cursor cursor, int cardinality, int numValuesPerPass) protected TopNParams(
DimensionSelector dimSelector,
Cursor cursor,
int cardinality,
int numValuesPerPass
)
{ {
this.dimSelector = dimSelector; this.dimSelector = dimSelector;
this.cursor = cursor; this.cursor = cursor;