public class GroupByState extends Object implements IGroupByState, Serializable
Note: As part of decoupling the SPARQL parser from the database in BLZG-1176,
a copy of this logic is now maintained in
VerifyAggregates
.
https://jira.blazegraph.com/browse/BLZG-1176
,
Serialized FormConstructor and Description |
---|
GroupByState(IValueExpression<?>[] select,
IValueExpression<?>[] groupBy,
IConstraint[] having) |
Modifier and Type | Method and Description |
---|---|
LinkedHashSet<IVariable<?>> |
getColumnVars()
Variables for which we will need column projections.
|
IValueExpression<?>[] |
getGroupByClause()
The ordered array of value expressions which define the basis for
aggregating solutions into groups.
|
LinkedHashSet<IVariable<?>> |
getGroupByVars()
Top-level variables in the GROUP_BY clause in the order in which they
were declared.
|
IConstraint[] |
getHavingClause()
Optional constraints applied to the aggregated solutions.
|
IValueExpression<?>[] |
getSelectClause()
The value expressions to be projected out of the SELECT clause.
|
LinkedHashSet<IVariable<?>> |
getSelectVars()
Top-level variables in the SELECT clause in the order in which they were
declared.
|
protected boolean |
isAggregate(BOp op,
boolean isSelectClause,
AtomicBoolean isSelectDependency,
AtomicBoolean isNestedAggregates,
AtomicBoolean isAnyDistinct)
Return
true iff the expression is an aggregate. |
boolean |
isAnyDistinct()
true iff any aggregate functions will be applied to the
DISTINCT values arising from their inner value expression in either the
SELECT or HAVING clause. |
boolean |
isNestedAggregates()
true if any aggregate expression nests another aggregate
expression. |
boolean |
isSelectDependency()
true iff any aggregate expression uses a reference to
another aggregate expression in the select clause. |
boolean |
isSimpleHaving()
true if none of the value expressions in the optional HAVING
clause use IAggregate functions. |
String |
toString() |
public GroupByState(IValueExpression<?>[] select, IValueExpression<?>[] groupBy, IConstraint[] having)
public IValueExpression<?>[] getGroupByClause()
IGroupByState
getGroupByClause
in interface IGroupByState
public LinkedHashSet<IVariable<?>> getGroupByVars()
IGroupByState
getGroupByVars
in interface IGroupByState
public IValueExpression<?>[] getSelectClause()
IGroupByState
getSelectClause
in interface IGroupByState
public LinkedHashSet<IVariable<?>> getSelectVars()
IGroupByState
getSelectVars
in interface IGroupByState
public IConstraint[] getHavingClause()
IGroupByState
getHavingClause
in interface IGroupByState
public LinkedHashSet<IVariable<?>> getColumnVars()
IGroupByState
SELECT SUM(DISTINCT ?x), SUM(?y)
, this would report
{?x,?y}
. The variables will be reported in the order they
were encountered during a left-to-right scan of the SELECT expressions
followed by a left-to-right scan of the HAVING constraints.getColumnVars
in interface IGroupByState
public boolean isAnyDistinct()
IGroupByState
true
iff any aggregate functions will be applied to the
DISTINCT values arising from their inner value expression in either the
SELECT or HAVING clause. When false
certain optimizations
are possible.isAnyDistinct
in interface IGroupByState
public boolean isSelectDependency()
IGroupByState
true
iff any aggregate expression uses a reference to
another aggregate expression in the select clause. When
false
certain optimizations are possible (parallel
evaluation of the aggregates across the column projections).isSelectDependency
in interface IGroupByState
public boolean isNestedAggregates()
IGroupByState
true
if any aggregate expression nests another aggregate
expression. For example:
SUM(?x+AVG(?x))is a nested aggregation expression but:
SUM(?x+1)and
1+SUM(?x)+AVG(?x)are not nested aggregation expressions. When
false
certain
optimizations may be possible.isNestedAggregates
in interface IGroupByState
public boolean isSimpleHaving()
IGroupByState
true
if none of the value expressions in the optional HAVING
clause use IAggregate
functions. When true
certain
optimizations are possible.
For example, the following query does not use an IAggregate
function in the HAVING clause. Instead, it references an aggregate
defined in the SELECT clause.
SELECT SUM(?y) as ?x GROUP BY ?z HAVING ?x > 10As a degenerate case, this is also
true
when there is no
HAVING clause.isSimpleHaving
in interface IGroupByState
protected boolean isAggregate(BOp op, boolean isSelectClause, AtomicBoolean isSelectDependency, AtomicBoolean isNestedAggregates, AtomicBoolean isAnyDistinct)
true
iff the expression is an aggregate.
Aggregates may be built out of constants, references to IVariable
s which are already defined and which are themselves aggregates, and
IAggregate
functions. An IVariable
will be an aggregate
if it appears as a bare variable in a GROUP_BY clause or if it declared
by a prior value expression in a GROUP_BY or SELECT clause. Testing
whether or not an IValueExpression
is an aggregate therefore
depends on access to the set of known aggregates. The value expressions
in the GROUP_BY clause must be processed first (in order) followed by the
value expressions in the SELECT clause (in order).
An aggregate may use a non-aggregate variable only allowed within an
IAggregate
function. For example, given:
SUM(?x) as ?y
, ?x
must be a non-aggregate
variable and ?y
will be an aggregate variable.
Aggregate variables may be used both inside and outside of an
IAggregate
function as long as the variable was declared before
it was used. For example, the following are legal:
SELECT SUM(?x) as ?y, SUM(?x + ?y) as ?z, SUM(?x)+AVG(?x) as ?z2 SELECT SUM(?x) as ?y, SUM(?x + COUNT(?y)) as ?zPatterns where an aggregate depends on a prior aggregate prevent certain optimizations, notably you have to evaluate each aggregate in turn rather than evaluating them in parallel over the solutions is a group. If any such patterns are observed in the SELECT clause then this method will set
isSelectDependency := true
as a side-effect.op
- An IValueExpression
or IConstraint
.isSelectClause
- true
if the op appears a SELECT clause.isSelectDependency
- Set as a side-effect when an IValueExpression
appearing in a SELECT clause has a dependency on an
IVariable
declared in the GROUP_BY clause or earlier
in the SELECT clause. This argument is optional unless
isSelectClause is true
.isNestedAggregates
- Set as a side-effect when an IValueExpression
containing an IAggregate
nests another
IAggregate
within it.isAnyDistinct
- Set as a side-effect if an IAggregate
function is
encountered which reports true
for
IAggregate.isDistinct()
.true
iff the operator is an aggregate.Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.