mirror of https://github.com/apache/druid.git
postAggregators now return field dependencies
This commit is contained in:
parent
2a188996cd
commit
6525d818ad
|
@ -20,6 +20,7 @@
|
|||
package com.metamx.druid.query;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
@ -27,6 +28,7 @@ import com.metamx.druid.aggregation.AggregatorFactory;
|
|||
import com.metamx.druid.aggregation.post.PostAggregator;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -58,9 +60,12 @@ public class Queries
|
|||
);
|
||||
|
||||
for (PostAggregator postAgg : postAggs) {
|
||||
Set<String> dependencies = postAgg.getDependentFields();
|
||||
Set<String> missing = Sets.difference(dependencies, combinedAggNames);
|
||||
|
||||
Preconditions.checkArgument(
|
||||
postAgg.verifyFields(combinedAggNames),
|
||||
String.format("Missing field[%s]", postAgg.getName())
|
||||
missing.isEmpty(),
|
||||
String.format("Missing fields [%s] for postAggregator [%s]", Joiner.on(",").join(missing), postAgg.getName())
|
||||
);
|
||||
combinedAggNames.add(postAgg.getName());
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package com.metamx.druid.aggregation.post;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.metamx.common.IAE;
|
||||
import org.codehaus.jackson.annotate.JsonCreator;
|
||||
import org.codehaus.jackson.annotate.JsonProperty;
|
||||
|
@ -69,14 +70,13 @@ public class ArithmeticPostAggregator implements PostAggregator
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean verifyFields(Set<String> fieldNames)
|
||||
public Set<String> getDependentFields()
|
||||
{
|
||||
Set<String> dependentFields = Sets.newHashSet();
|
||||
for (PostAggregator field : fields) {
|
||||
if (!field.verifyFields(fieldNames)) {
|
||||
return false;
|
||||
}
|
||||
dependentFields.addAll(field.getDependentFields());
|
||||
}
|
||||
return true;
|
||||
return dependentFields;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package com.metamx.druid.aggregation.post;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.codehaus.jackson.annotate.JsonCreator;
|
||||
import org.codehaus.jackson.annotate.JsonProperty;
|
||||
|
||||
|
@ -44,9 +45,9 @@ public class ConstantPostAggregator implements PostAggregator
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean verifyFields(Set<String> fields)
|
||||
public Set<String> getDependentFields()
|
||||
{
|
||||
return true;
|
||||
return Sets.newHashSet();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package com.metamx.druid.aggregation.post;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.metamx.common.ISE;
|
||||
import org.codehaus.jackson.annotate.JsonCreator;
|
||||
import org.codehaus.jackson.annotate.JsonProperty;
|
||||
|
@ -45,9 +46,9 @@ public class FieldAccessPostAggregator implements PostAggregator
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean verifyFields(Set<String> fieldNames)
|
||||
public Set<String> getDependentFields()
|
||||
{
|
||||
return fieldNames.contains(fieldName);
|
||||
return Sets.newHashSet(fieldName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -37,7 +37,7 @@ import java.util.Set;
|
|||
})
|
||||
public interface PostAggregator
|
||||
{
|
||||
public boolean verifyFields(Set<String> fieldNames);
|
||||
public Set<String> getDependentFields();
|
||||
|
||||
public Comparator getComparator();
|
||||
|
||||
|
|
Loading…
Reference in New Issue