com.bigdata.rdf.sparql.ast
Class StaticAnalysisBase

java.lang.Object
  extended by com.bigdata.rdf.sparql.ast.StaticAnalysisBase
Direct Known Subclasses:
StaticAnalysis_CanJoin

public class StaticAnalysisBase
extends Object

Base class for static analysis.

Version:
$Id: StaticAnalysisBase.java 6294 2012-04-17 20:11:31Z thompsonbry $
Author:
Bryan Thompson

Field Summary
protected  IEvaluationContext evaluationContext
           
protected  QueryRoot queryRoot
           
 
Constructor Summary
protected StaticAnalysisBase(QueryRoot queryRoot, IEvaluationContext evaluationContext)
           
 
Method Summary
protected  void addAll(Set<IVariable<?>> bindings, IGroupMemberNode op)
          Add all variables spanned by the operator.
 NamedSubqueryRoot getNamedSubqueryRoot(String name)
          Return the corresponding NamedSubqueryRoot.
 QueryRoot getQueryRoot()
          Return the QueryRoot parameter given to the constructor.
protected  NamedSubqueryRoot getRequiredNamedSubqueryRoot(String name)
          Deprecated. Caller's MUST BE CHANGED to look for both a NamedSubqueryRoot and an ISolutionSetStats and then handle these as appropriate. In one case, that means static analysis of the NamedSubqueryRoot. In the other, the relevant information are present in pre-computed metadata on the ISolutionSetStats.
 ISolutionSetStats getSolutionSetStats(String name)
          Return the ISolutionSetStats for the named solution set.
 Set<IVariable<?>> getSpannedVariables(BOp op, boolean filters, Set<IVariable<?>> varSet)
          Return the distinct variables in the operator tree.
 Set<IVariable<?>> getSpannedVariables(BOp op, Set<IVariable<?>> varSet)
          Return the distinct variables in the operator tree, including on those on annotations attached to operators.
 boolean isFullyBound(FilterNode f, Set<IVariable<?>> vars)
          Return true if the FilterNode is fully bound for the given variables.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

queryRoot

protected final QueryRoot queryRoot

evaluationContext

protected final IEvaluationContext evaluationContext
Constructor Detail

StaticAnalysisBase

protected StaticAnalysisBase(QueryRoot queryRoot,
                             IEvaluationContext evaluationContext)
Parameters:
queryRoot - The root of the query. We need to have this on hand in order to resolve NamedSubqueryIncludes during static analysis.
evaluationContext - The evaluation context provides access to the ISolutionSetStats and the ISparqlCache for named solution sets.
Method Detail

getQueryRoot

public QueryRoot getQueryRoot()
Return the QueryRoot parameter given to the constructor.


getSpannedVariables

public Set<IVariable<?>> getSpannedVariables(BOp op,
                                             Set<IVariable<?>> varSet)
Return the distinct variables in the operator tree, including on those on annotations attached to operators. Variables projected by a subquery are included, but not variables within the WHERE clause of the subquery. Variables projected by a NamedSubqueryInclude are also reported, but not those used within the WHERE clause of the corresponding NamedSubqueryRoot.

Parameters:
op - An operator.
varSet - The variables are inserted into this Set.
Returns:
The caller's Set.

getSpannedVariables

public Set<IVariable<?>> getSpannedVariables(BOp op,
                                             boolean filters,
                                             Set<IVariable<?>> varSet)
Return the distinct variables in the operator tree. Variables projected by a subquery are included, but not variables within the WHERE clause of the subquery. Variables projected by a NamedSubqueryInclude are also reported, but not those used within the WHERE clause of the corresponding NamedSubqueryRoot.

Parameters:
op - An operator.
filters - When true, variables on FilterNodes are also reported.
varSet - The variables are inserted into this Set.
Returns:
The caller's Set. TODO Unit tests for different kinds of AST nodes to make sure that we always get/ignore the variables in filters as appropriate. For example, an optional StatementPatternNode can have filter nodes attached.

getRequiredNamedSubqueryRoot

protected NamedSubqueryRoot getRequiredNamedSubqueryRoot(String name)
Deprecated. Caller's MUST BE CHANGED to look for both a NamedSubqueryRoot and an ISolutionSetStats and then handle these as appropriate. In one case, that means static analysis of the NamedSubqueryRoot. In the other, the relevant information are present in pre-computed metadata on the ISolutionSetStats.

Return the corresponding NamedSubqueryRoot.

Parameters:
name - The name of the solution set.
Returns:
The NamedSubqueryRoot and never null.
Throws:
RuntimeException - if no NamedSubqueryRoot was found for the named set associated with this NamedSubqueryInclude.

getNamedSubqueryRoot

public NamedSubqueryRoot getNamedSubqueryRoot(String name)
Return the corresponding NamedSubqueryRoot.

Note: You can not resolve pre-existing named solution sets with this method, only those which are defined within the scope of a query by a NamedSubqueryRoot.

Note: Typically, callers MUST look for both a NamedSubqueryRoot and an ISolutionSetStats and then handle these as appropriate. In one case, that means static analysis of the NamedSubqueryRoot. In the other, the relevant information are present in pre-computed metadata on the ISolutionSetStats.

Parameters:
name - The name of the solution set.
Returns:
The NamedSubqueryRoot -or- null if none was found.
See Also:
getSolutionSetStats(String)

getSolutionSetStats

public ISolutionSetStats getSolutionSetStats(String name)
Return the ISolutionSetStats for the named solution set.

Note: This does NOT report on NamedSubqueryRoots for the query. It only checks the ISparqlCache.

Note: Typically, callers MUST look for both a NamedSubqueryRoot and an ISolutionSetStats and then handle these as appropriate. In one case, that means static analysis of the NamedSubqueryRoot. In the other, the relevant information are present in pre-computed metadata on the ISolutionSetStats.

Parameters:
name - The name of the solution set.
Returns:
The ISolutionSetStats -or- null if there is no such pre-existing named solution set.
See Also:
getNamedSubqueryRoot(String)

addAll

protected void addAll(Set<IVariable<?>> bindings,
                      IGroupMemberNode op)
Add all variables spanned by the operator.

WARNING: This method does not consider the variable scoping rules. It is safe to use with a FILTER as all variables will be in scope, but it is not safe to use with a SubqueryBase as only the projected variables will be in scope.

Parameters:
bindings - The set to which the variables will be added.
op - The operator.

isFullyBound

public boolean isFullyBound(FilterNode f,
                            Set<IVariable<?>> vars)
Return true if the FilterNode is fully bound for the given variables.

Parameters:
f - The FilterNode
vars - Some collection of variables which are known to be bound.
Returns:
true if all variables on which the filter depends are present in that collection.


Copyright © 2006-2012 SYSTAP, LLC. All Rights Reserved.