Class CandidateViewSelectorBase<T extends IViewDef,C>

java.lang.Object
org.aksw.jena_sparql_api.views.CandidateViewSelectorBase<T,C>
Type Parameters:
T - The ViewDefinition type. Must inherit from IViewDef
I - Type for result items - i.e. when the recursion reaches its end, it gives the list of found view candidates to a function that can transform it into an object of type I
C - Context type used during recursion when looking for view candidates for quad patterns. Intended to track custom information for unsatisfiability determination.
All Implemented Interfaces:
CandidateViewSelector<T>
Direct Known Subclasses:
CandidateViewSelectorSparqlView

public abstract class CandidateViewSelectorBase<T extends IViewDef,C> extends Object implements CandidateViewSelector<T>
Author:
raven
  • Field Details

    • filterPlacementOptimizer

      protected BiFunction<org.apache.jena.sparql.algebra.Op,RestrictionManagerImpl,org.apache.jena.sparql.algebra.Op> filterPlacementOptimizer
  • Constructor Details

    • CandidateViewSelectorBase

      public CandidateViewSelectorBase(BiFunction<org.apache.jena.sparql.algebra.Op,RestrictionManagerImpl,org.apache.jena.sparql.algebra.Op> filterPlacementOptimizer)
      Parameters:
      opMappingRewriter - May be null. If given, we can do rewrites during the SQL generation to prune empty result mappings early.
  • Method Details

    • createOp

      public abstract org.apache.jena.sparql.algebra.Op createOp(org.apache.jena.sparql.algebra.op.OpQuadBlock opQuadBlock, List<RecursionResult<T,C>> viewInstances)
    • createContext

      public C createContext(C baseContext, ViewInstance<T> viewInstance) throws UnsatisfiabilityException
      Optionally override this method to track custom information during the recursion of candidate selection of quad patterns
      Parameters:
      baseContext -
      viewInstance -
      Returns:
      Throws:
      UnsatisfiabilityException
    • addView

      public void addView(T viewDef)
      Specified by:
      addView in interface CandidateViewSelector<T extends IViewDef>
    • deriveConstraint

      public static Constraint deriveConstraint(org.apache.jena.sparql.expr.Expr expr)
    • deriveConstraint

      public static StartsWithConstraint deriveConstraint(org.apache.jena.sparql.expr.E_StrConcat expr)
    • deriveConstraint

      public static StartsWithConstraint deriveConstraint(E_StrConcatPermissive expr)
    • getType

      public static RdfTermType getType(org.apache.jena.graph.Node node, RestrictionManagerImpl restrictions)
    • normalizeView

      public T normalizeView(T view)
      Override this function to transform the view before actually indexing it
      Parameters:
      view -
      Returns:
    • getApplicableViews

      public org.apache.jena.sparql.algebra.Op getApplicableViews(org.apache.jena.query.Query query)
      Specified by:
      getApplicableViews in interface CandidateViewSelector<T extends IViewDef>
    • deriveIsPrefixOfConstraint

      public static VariableConstraint deriveIsPrefixOfConstraint(org.apache.jena.sparql.expr.Expr a, org.apache.jena.sparql.expr.Expr b)
      If a variable equals a (uri or string) constant, it means that the view must provide a prefix for that value.
      Parameters:
      a -
      b -
      Returns:
    • deriveViewLookupConstraint

      public static VariableConstraint deriveViewLookupConstraint(org.apache.jena.sparql.expr.Expr expr)
      Returns IsPrefixOf Constraints for equality expressions between variables and constants. Used for looking up view candidates. Not used for satisfiability checks.
      Parameters:
      expr -
      Returns:
    • getApplicableViewsBase

      public List<RecursionResult<T,C>> getApplicableViewsBase(org.apache.jena.sparql.algebra.op.OpQuadBlock op, RestrictionManagerImpl restrictions)
      Order the quads of the quadPattern by selectivity. Iterate the quads in order, and for each quad, do a lookup of the views that may yield answers to it. So for each quad we get a set of candidate bindings to the views. Binding is a mapping from query-var to a set of view variables/constant The view varibale may have constraints on it, which carry over to the query variable. So given Create View x ... {?x a Class . } With ?x.value prefix "foo" a query Select {?s ?p ?o } and a binding(?s = ?x), then we can infer the constraint on ?x.value prefix "foo" So if there is a second pattern { ?x a Class. ?x label ?z } Then we can use this constraint on the lookup at the second pattern. Note that the selectivity of query quad pattern change with the bindings, so we should be able to quickly update the selectivity of the quads in the presence of bindings. Another note: Maybe we could treat constants as specially delimited prefixes, such as 'aaaa' = prefix 'aaaaa$' = constant
    • inferColumnConstraints

      public Map<String,Constraint> inferColumnConstraints(org.apache.jena.sparql.core.Quad quad, RestrictionImpl[] termRestriction, Clause clause)
    • findCandidates

      public Set<ViewQuad<T>> findCandidates(org.apache.jena.sparql.core.Quad quad, RestrictionManagerImpl restrictions)
      TODO: This method is far from optimal performance right now: We need to consider prefix-set-restrictions of the variables during the lookup in order to rule out returning to many view-quad candidates.
      Parameters:
      quad -
      restrictions -
      Returns:
    • findQuadWithFewestViewCandidates

      public org.aksw.commons.util.Pair<NavigableMap<Integer,Set<org.apache.jena.sparql.core.Quad>>,Map<org.apache.jena.sparql.core.Quad,Set<ViewQuad<T>>>> findQuadWithFewestViewCandidates(org.apache.jena.sparql.core.QuadPattern queryQuads, RestrictionManagerImpl restrictions)
    • getCandidateNames

      public static <T extends IViewDef> List<String> getCandidateNames(org.aksw.commons.collections.stacks.NestedStack<ViewInstance<T>> instances)
    • createViewInstance

      public static <T extends IViewDef> ViewInstance<T> createViewInstance(RestrictionManagerImpl subRestrictions, org.apache.jena.sparql.core.Quad queryQuad, ViewQuad<T> viewQuad)
      Checks whether the view quad is consistent with the current constraints
      Parameters:
      restrictions -
      queryQuad -
      viewQuad -
      Returns:
    • getApplicableViewsRec2

      public void getApplicableViewsRec2(int index, List<org.apache.jena.sparql.core.Quad> quadOrder, Set<ViewQuad<T>> viewQuads, Map<org.apache.jena.sparql.core.Quad,Set<ViewQuad<T>>> candidates, RestrictionManagerImpl restrictions, org.aksw.commons.collections.stacks.NestedStack<ViewInstance<T>> instances, List<RecursionResult<T,C>> result, C baseContext)
      Parameters:
      index -
      quadOrder -
      viewQuads - The viewQuads provided by the parent invocation - with any restrictions encountered during the rewrite taken into account
      candidates - The viewQuads here are the ones from only analyzing the query filter In some cases (small candidate sets) it might be faster filtering this set of view candidates, rather than doing a new lookup.
      restrictions -
      result -
    • getApplicableViews

      public org.apache.jena.sparql.algebra.Op getApplicableViews(org.apache.jena.sparql.algebra.op.OpQuadBlock op, RestrictionManagerImpl restrictions)
    • isSatisfiable

      public static <T extends IViewDef> boolean isSatisfiable(List<ViewInstance<T>> list)
      TODO FIX THIS
      Parameters:
      list -
      Returns:
    • _getApplicableViews

      public org.apache.jena.sparql.algebra.Op _getApplicableViews(org.apache.jena.sparql.algebra.Op op)
      Given a sparql query in quad form, this method replaces (sub sets of) quad patterns with view instances (view patterns) The method also passes the filter conditions that an op must satisfy.
      Parameters:
      op -
      Returns:
    • _getApplicableViews

      public org.apache.jena.sparql.algebra.Op _getApplicableViews(org.apache.jena.sparql.algebra.Op op, RestrictionManagerImpl restrictions)
    • getApplicableViews

      public org.apache.jena.sparql.algebra.Op getApplicableViews(org.apache.jena.sparql.algebra.op.OpSequence op, RestrictionManagerImpl restrictions)
    • getApplicableViews

      public org.apache.jena.sparql.algebra.Op getApplicableViews(org.apache.jena.sparql.algebra.op.OpTopN op, RestrictionManagerImpl restrictions)
    • getApplicableViews

      public org.apache.jena.sparql.algebra.Op getApplicableViews(org.apache.jena.sparql.algebra.op.OpDisjunction op, RestrictionManagerImpl restrictions)
    • getApplicableViews

      public org.apache.jena.sparql.algebra.Op getApplicableViews(org.apache.jena.sparql.algebra.op.OpProject op, RestrictionManagerImpl restrictions)
    • getApplicableViews

      public org.apache.jena.sparql.algebra.Op getApplicableViews(org.apache.jena.sparql.algebra.op.OpOrder op, RestrictionManagerImpl restrictions)
    • getApplicableViews

      public org.apache.jena.sparql.algebra.Op getApplicableViews(org.apache.jena.sparql.algebra.op.OpGroup op, RestrictionManagerImpl restrictions)
    • getApplicableViews

      public org.apache.jena.sparql.algebra.Op getApplicableViews(org.apache.jena.sparql.algebra.op.OpExtend op, RestrictionManagerImpl _restrictions)
      Extend defines now variables and is therefore similar to a VarDefinition. Below is outdated. We treat OpExtend as a filter for now TODO This breaks for instance Count(*) as Jena also does renaming with extend: Jena generates Project(?c, Extend(?c, ?x, Group(Count(*) As ?x))) So in this case, extend creates a new alias for a variable
    • getApplicableViews

      public org.apache.jena.sparql.algebra.Op getApplicableViews(org.apache.jena.sparql.algebra.op.OpAssign op, RestrictionManagerImpl _restrictions)
    • processOpExtend

      public org.apache.jena.sparql.algebra.Op processOpExtend(org.apache.jena.sparql.algebra.Op subOp, org.apache.jena.sparql.core.VarExprList varExprs, RestrictionManagerImpl _restrictions)
    • getApplicableViews

      public org.apache.jena.sparql.algebra.Op getApplicableViews(org.apache.jena.sparql.algebra.op.OpFilter op, RestrictionManagerImpl restrictions)
    • getApplicableViews

      public org.apache.jena.sparql.algebra.Op getApplicableViews(org.apache.jena.sparql.algebra.op.OpUnion op, RestrictionManagerImpl restrictions)
    • getApplicableViews

      public org.apache.jena.sparql.algebra.Op getApplicableViews(org.apache.jena.sparql.algebra.op.OpJoin op, RestrictionManagerImpl restrictions)
    • filterRestrictionsBound

      public static RestrictionManagerImpl filterRestrictionsBound(RestrictionManagerImpl restrictions)
      Create a new retrictions manager, where "bound" retrictions are removed
      Parameters:
      restrictions -
      Returns:
    • getApplicableViews

      public org.apache.jena.sparql.algebra.Op getApplicableViews(org.apache.jena.sparql.algebra.op.OpLeftJoin op, RestrictionManagerImpl restrictions)
    • getApplicableViews

      public org.apache.jena.sparql.algebra.Op getApplicableViews(org.apache.jena.sparql.algebra.op.OpConditional op, RestrictionManagerImpl restrictions)
    • processLeftJoin

      public org.apache.jena.sparql.algebra.Op processLeftJoin(org.apache.jena.sparql.algebra.Op left, org.apache.jena.sparql.algebra.Op right, Iterable<org.apache.jena.sparql.expr.Expr> exprs, RestrictionManagerImpl restrictions)
    • processJoinSplitLhs

      public org.apache.jena.sparql.algebra.Op processJoinSplitLhs(org.apache.jena.sparql.algebra.Op left, org.apache.jena.sparql.algebra.Op right, Iterable<org.apache.jena.sparql.expr.Expr> exprs, RestrictionManagerImpl restrictions, boolean isLeftJoin)
    • processLeftJoinDirect

      public org.apache.jena.sparql.algebra.op.OpLeftJoin processLeftJoinDirect(org.apache.jena.sparql.algebra.Op left, org.apache.jena.sparql.algebra.Op right, Iterable<org.apache.jena.sparql.expr.Expr> exprs, RestrictionManagerImpl restrictions)
    • getApplicableViews

      public org.apache.jena.sparql.algebra.Op getApplicableViews(org.apache.jena.sparql.algebra.op.OpSlice op, RestrictionManagerImpl restrictions)
    • getApplicableViews

      public org.apache.jena.sparql.algebra.Op getApplicableViews(org.apache.jena.sparql.algebra.op.OpDistinct op, RestrictionManagerImpl restrictions)
    • getRestrictions2

      public RestrictionManagerImpl getRestrictions2(org.apache.jena.sparql.algebra.Op op)
    • getRestrictions

      public List<RestrictionManagerImpl> getRestrictions(org.apache.jena.sparql.algebra.Op op)
    • getRestrictions

      public void getRestrictions(org.apache.jena.sparql.algebra.Op op, Collection<RestrictionManagerImpl> result)
      Returns a disjunction (list) of restrictions that apply for a given node
    • getViews

      public Collection<T> getViews()
      Specified by:
      getViews in interface CandidateViewSelector<T extends IViewDef>