public class VerifyAggregates extends Object
Note: This is a port of GroupByState
that
does not depend on the blazegraph operator model. It was developed as part of
BLZG-1176 to decouple the SPARQL parser from the database.
https://jira.blazegraph.com/browse/BLZG-1176
Constructor and Description |
---|
VerifyAggregates(ProjectionNode projection,
GroupByNode groupBy,
HavingNode having) |
Modifier and Type | Method and Description |
---|---|
protected boolean |
isAggregate(BOp op,
boolean isSelectClause,
AtomicBoolean isSelectDependency,
AtomicBoolean isNestedAggregates,
AtomicBoolean isAnyDistinct)
Return
true iff the expression is an aggregate. |
String |
toString() |
static void |
verifyAggregate(QueryBase queryBase)
Verify the various conditions that must be met when a query uses GROUP BY
or when a query uses aggregates in a PROJECTION.
|
public VerifyAggregates(ProjectionNode projection, GroupByNode groupBy, HavingNode having)
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.public static void verifyAggregate(QueryBase queryBase) throws VisitorException
queryBase
- The query.VisitorException
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.