Merge pull request #50 from metamx/postagg-dependencies

postAggregators now return field dependencies
This commit is contained in:
cheddar 2013-01-03 10:05:14 -08:00
commit 6318abb0bd
5 changed files with 18 additions and 12 deletions

View File

@ -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;
@ -58,9 +59,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(),
"Missing fields [%s] for postAggregator [%s]", missing, postAgg.getName()
);
combinedAggNames.add(postAgg.getName());
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -37,7 +37,7 @@ import java.util.Set;
})
public interface PostAggregator
{
public boolean verifyFields(Set<String> fieldNames);
public Set<String> getDependentFields();
public Comparator getComparator();