Class IndexAggregateFunctionCall
- java.lang.Object
-
- com.apple.foundationdb.record.metadata.IndexAggregateFunctionCall
-
@API(INTERNAL) public class IndexAggregateFunctionCall extends Object
Class to represent a constructAGG by Set.of(col1, col2, ...)
. This is the unbound equivalent of anIndexAggregateFunction
which itself is bound to an index and represents its group-by columns as a list ofKeyExpression
that match the order imposed by bound index rather than a set. There are two use cases for this class:- regular aggregation functions that need the enumeration of permutation of the grouping expressions in order to
bind the call to a
IndexAggregateFunction
. The logic implementing this use case callsenumerateIndexAggregateFunctionCandidates(String)
at some point. - aggregation-oriented operators that function more like closures over a group (see
ComposedBitmapIndexAggregate
for such an example) in which cases it may be needed to propagate the originalGroupingKeyExpression
to the binding phase thus eliminating the possibility of an enumeration of permutations of grouping columns altogether. In those cases it may be simply impossible to compute an equivalent list of such grouping columns from the original grouping key expression without losing some of the nesting/repeating information.
enumerateIndexAggregateFunctionCandidates(String)
, the following must hold in order to yield meaningful results:groupingKeyExpression = concat(groupingExpressions, groupedExpression).group(groupedExpression.getColumnSize())
- regular aggregation functions that need the enumeration of permutation of the grouping expressions in order to
bind the call to a
-
-
Constructor Summary
Constructors Modifier Constructor Description IndexAggregateFunctionCall(String functionName, GroupingKeyExpression groupingKeyExpression)
Overloaded constructor using aGroupingKeyExpression
that represents both the grouping expressions and the grouped expression.protected
IndexAggregateFunctionCall(String functionName, GroupingKeyExpression groupingKeyExpression, Iterable<KeyExpression> groupingExpressions, KeyExpression groupedExpression)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description QueryComponent
applyCondition(QueryComponent filterCondition)
Stream<IndexAggregateFunction>
enumerateIndexAggregateFunctionCandidates(String indexName)
Method to create a stream of enumeratedIndexAggregateFunction
s that represent the bound versions of this function call.boolean
equals(Object o)
static Set<KeyExpression>
extractEqualityBoundFields(QueryComponent queryComponent)
Helper method to extract a set of key expressions that are bound through an equality comparison in the query component passed in.static Set<KeyExpression>
extractFieldPaths(QueryComponent queryComponent, Predicate<FieldWithComparison> predicate)
Helper method to extract a set of key expressions that are bound through some comparison in the query component passed in.String
getFunctionName()
KeyExpression
getGroupedExpression()
Set<KeyExpression>
getGroupingExpressions()
GroupingKeyExpression
getGroupingKeyExpression()
int
hashCode()
boolean
isGroupingPermutable()
protected GroupingKeyExpression
toGroupingKeyExpression(List<KeyExpression> groupingKeysPermutation)
static GroupingKeyExpression
toGroupingKeyExpression(List<KeyExpression> groupingKeysPermutation, KeyExpression groupedExpression)
IndexAggregateFunction
toIndexAggregateFunction(String indexName)
Method to create aIndexAggregateFunction
that represents the bound version of this function call.protected IndexAggregateFunction
toIndexAggregateFunction(String indexName, GroupingKeyExpression groupingKeyExpression)
Method to create aIndexAggregateFunction
that represents the bound version of this function call.protected IndexAggregateFunction
toIndexAggregateFunction(String indexName, List<KeyExpression> groupingKeysPermutation)
Method to create aIndexAggregateFunction
that represents the bound version of this function call.IndexAggregateFunctionCall
withNewExpressions(List<KeyExpression> groupingKeysPermutation, KeyExpression groupedExpression)
IndexAggregateFunctionCall
withNewGroupingKeyExpression(GroupingKeyExpression groupingKeyExpression)
-
-
-
Constructor Detail
-
IndexAggregateFunctionCall
public IndexAggregateFunctionCall(@Nonnull String functionName, @Nonnull GroupingKeyExpression groupingKeyExpression)
Overloaded constructor using aGroupingKeyExpression
that represents both the grouping expressions and the grouped expression. The constructor is necessary to allow function calls that can use nested repeated structures to adequately represent function calls over those structures.- Parameters:
functionName
- function name of the callgroupingKeyExpression
- the grouping key expression
-
IndexAggregateFunctionCall
protected IndexAggregateFunctionCall(@Nonnull String functionName, @Nonnull GroupingKeyExpression groupingKeyExpression, @Nonnull Iterable<KeyExpression> groupingExpressions, @Nonnull KeyExpression groupedExpression)
-
-
Method Detail
-
getGroupingKeyExpression
@Nonnull public GroupingKeyExpression getGroupingKeyExpression()
-
getGroupingExpressions
@Nonnull public Set<KeyExpression> getGroupingExpressions()
-
getGroupedExpression
@Nonnull public KeyExpression getGroupedExpression()
-
isGroupingPermutable
public boolean isGroupingPermutable()
-
withNewGroupingKeyExpression
@Nonnull public IndexAggregateFunctionCall withNewGroupingKeyExpression(@Nonnull GroupingKeyExpression groupingKeyExpression)
-
withNewExpressions
@Nonnull public IndexAggregateFunctionCall withNewExpressions(@Nonnull List<KeyExpression> groupingKeysPermutation, @Nonnull KeyExpression groupedExpression)
-
applyCondition
@Nonnull public QueryComponent applyCondition(@Nonnull QueryComponent filterCondition)
-
enumerateIndexAggregateFunctionCandidates
public Stream<IndexAggregateFunction> enumerateIndexAggregateFunctionCandidates(@Nonnull String indexName)
Method to create a stream of enumeratedIndexAggregateFunction
s that represent the bound versions of this function call. In order to bind the function call, we need to associate the aggregate function call with an index and also pin the order of grouping key expressions in a way that is compatible with that index. Note that the returned index aggregate functions are merely candidates for actual index-compatible ones as we don't check here the conditions that constitute a compatible index. On the contrary, this method is intended to be used by the logic that builds the actual function call for later consumption.- Parameters:
indexName
- indexName to use- Returns:
- a
Stream
ofIndexAggregateFunction
s
-
toIndexAggregateFunction
@Nonnull protected IndexAggregateFunction toIndexAggregateFunction(@Nonnull String indexName, @Nonnull List<KeyExpression> groupingKeysPermutation)
Method to create aIndexAggregateFunction
that represents the bound version of this function call. In order to bind the function call, we need to associate the aggregate function call with an index and also pin the order of grouping key expressions in a way that is compatible with that index.- Parameters:
indexName
- index to usegroupingKeysPermutation
- permutation of key expressions to use that is compatible with the aggregate index- Returns:
- a new
IndexAggregateFunction
-
toIndexAggregateFunction
@Nonnull public IndexAggregateFunction toIndexAggregateFunction(@Nullable String indexName)
Method to create aIndexAggregateFunction
that represents the bound version of this function call. In order to bind the function call, we need to associate the aggregate function call with an index and also pin the order of grouping key expressions in a way that is compatible with that index. The order of the grouping key expressions is implicitly given by the structure of thegroupingKeyExpression
.- Parameters:
indexName
- index to use, index is allowed to benull
as some aggregate functions scan more than one index- Returns:
- a new
IndexAggregateFunction
-
toIndexAggregateFunction
@Nonnull protected IndexAggregateFunction toIndexAggregateFunction(@Nullable String indexName, @Nonnull GroupingKeyExpression groupingKeyExpression)
Method to create aIndexAggregateFunction
that represents the bound version of this function call. In order to bind the function call, we need to associate the aggregate function call with an index and also pin the order of grouping key expressions in a way that is compatible with that index. The order of the grouping key expressions is implicitly given by the structure of thegroupingKeyExpression
.- Parameters:
indexName
- index to use, index is allowed to benull
as some aggregate functions scan more than one indexgroupingKeyExpression
- the grouping key expression to use- Returns:
- a new
IndexAggregateFunction
-
toGroupingKeyExpression
@Nonnull protected GroupingKeyExpression toGroupingKeyExpression(@Nonnull List<KeyExpression> groupingKeysPermutation)
-
toGroupingKeyExpression
@Nonnull public static GroupingKeyExpression toGroupingKeyExpression(@Nonnull List<KeyExpression> groupingKeysPermutation, @Nonnull KeyExpression groupedExpression)
-
extractEqualityBoundFields
@Nonnull public static Set<KeyExpression> extractEqualityBoundFields(@Nonnull QueryComponent queryComponent)
Helper method to extract a set of key expressions that are bound through an equality comparison in the query component passed in.- Parameters:
queryComponent
- the query component- Returns:
- a set of
KeyExpression
s where each element is a key expression of a field (i.e. aFieldKeyExpression
) or a simple nesting field (i.e. aNestingKeyExpression
) that is bound through an equality comparison.
-
extractFieldPaths
@Nonnull public static Set<KeyExpression> extractFieldPaths(@Nonnull QueryComponent queryComponent, @Nonnull Predicate<FieldWithComparison> predicate)
Helper method to extract a set of key expressions that are bound through some comparison in the query component passed in.- Parameters:
queryComponent
- the query componentpredicate
- a predicate used for filtering each encounteredFieldWithComparison
- Returns:
- a set of
KeyExpression
s where each element is a key expression of a field (i.e. aFieldKeyExpression
) or a simple nesting field (i.e. aNestingKeyExpression
) that is bound through some comparison
-
-