Class AbstractLocalSearchResultProvider

    • Method Detail

      • prepare

        public void prepare()
        Prepare this result provider. This phase is separated from the constructor to allow the backend to cache its instance before requesting preparation for its dependencies.
        Since:
        1.5
      • preparePlansForExpectedAdornments

        protected void preparePlansForExpectedAdornments()
      • prepareDirectDependencies

        protected void prepareDirectDependencies()
      • indexInitializationBeforePlanning

        protected void indexInitializationBeforePlanning()
        This method is called before planning start to allow indexing. It is important to note that this method is called inside a coalesceTraversals block, meaning (1) it is safe to add multiple registration requests as necessary, but (2) no value or statistics is available from the index.
        Throws:
        ViatraQueryRuntimeException
      • indexReferredTypesOfQuery

        protected void indexReferredTypesOfQuery​(PQuery query,
                                                 IndexingService requiredIndexingServices)
        Collects and indexes all types _directly_ referred by the PQuery query. Types indirect
        Parameters:
        requiredIndexingServices -
      • hasMatch

        public boolean hasMatch​(java.lang.Object[] parameters)
        Description copied from interface: IQueryResultProvider
        Decides whether there are any matches of the pattern that conform to the given fixed values of some parameters.
        Specified by:
        hasMatch in interface IQueryResultProvider
        Parameters:
        parameters - array where each non-null element binds the corresponding pattern parameter to a fixed value.
      • hasMatch

        public boolean hasMatch​(TupleMask parameterSeedMask,
                                ITuple parameters)
        Description copied from interface: IQueryResultProvider
        Decides whether there are any matches of the pattern that conform to the given fixed values of some parameters.
        Specified by:
        hasMatch in interface IQueryResultProvider
        Parameters:
        parameterSeedMask - a mask that extracts those parameters of the query (from the entire parameter list) that should be bound to a fixed value
      • getOneArbitraryMatch

        public java.util.Optional<Tuple> getOneArbitraryMatch​(java.lang.Object[] parameters)
        Description copied from interface: IQueryResultProvider
        Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. Neither determinism nor randomness of selection is guaranteed.
        Specified by:
        getOneArbitraryMatch in interface IQueryResultProvider
        Parameters:
        parameters - array where each non-null element binds the corresponding pattern parameter to a fixed value.
        Returns:
        a match represented in the internal Tuple representation.
      • getOneArbitraryMatch

        public java.util.Optional<Tuple> getOneArbitraryMatch​(TupleMask parameterSeedMask,
                                                              ITuple parameters)
        Description copied from interface: IQueryResultProvider
        Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. Neither determinism nor randomness of selection is guaranteed.
        Specified by:
        getOneArbitraryMatch in interface IQueryResultProvider
        Parameters:
        parameterSeedMask - a mask that extracts those parameters of the query (from the entire parameter list) that should be bound to a fixed value
        parameters - the tuple of fixed values restricting the match set to be considered, in the same order as given in parameterSeedMask, so that for each considered match tuple, projectedParameterSeed.equals(parameterSeedMask.transform(match)) should hold
        Returns:
        a match represented in the internal Tuple representation.
      • countMatches

        public int countMatches​(java.lang.Object[] parameters)
        Description copied from interface: IQueryResultProvider
        Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
        Specified by:
        countMatches in interface IQueryResultProvider
        Parameters:
        parameters - array where each non-null element binds the corresponding pattern parameter to a fixed value.
        Returns:
        the number of pattern matches found.
      • countMatches

        public int countMatches​(TupleMask parameterSeedMask,
                                ITuple parameters)
        Description copied from interface: IQueryResultProvider
        Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
        Specified by:
        countMatches in interface IQueryResultProvider
        Parameters:
        parameterSeedMask - a mask that extracts those parameters of the query (from the entire parameter list) that should be bound to a fixed value
        Returns:
        the number of pattern matches found.
      • estimateCardinality

        public java.util.Optional<java.lang.Long> estimateCardinality​(TupleMask groupMask,
                                                                      Accuracy requiredAccuracy)
        Description copied from interface: IQueryResultProvider
        Gives an estimate of the number of different groups the matches are projected into by the given mask (e.g. for an identity mask, this means the full match set size). The estimate must meet the required accuracy.

        If there is insufficient information to provide an answer up to the required precision, Optional.empty() may be returned. In other words, query backends may deny an answer, or do their best to give an estimate without actually determining the match set of the query. However, caching backends are expected to simply return the indexed (projection) size, initialized on-demand if necessary.

        PRE: TupleMask.isNonrepeating() must hold for the group mask.

        Specified by:
        estimateCardinality in interface IQueryResultProvider
        Returns:
        if available, an estimate of the cardinality of the projection of the match set, with the desired accuracy.
      • estimateAverageBucketSize

        public java.util.Optional<java.lang.Double> estimateAverageBucketSize​(TupleMask groupMask,
                                                                              Accuracy requiredAccuracy)
        Description copied from interface: IQueryResultProvider
        Gives an estimate of the average size of different groups the matches are projected into by the given mask (e.g. for an identity mask, this means 1, while for an empty mask, the result is match set size). The estimate must meet the required accuracy.

        If there is insufficient information to provide an answer up to the required precision, Optional.empty() may be returned. In other words, query backends may deny an answer, or do their best to give an estimate without actually determining the match set of the query. However, caching backends are expected to simply return the exact value from the index, initialized on-demand if necessary.

        For an empty match set, zero is acceptable as an exact answer.

        PRE: TupleMask.isNonrepeating() must hold for the group mask.

        Specified by:
        estimateAverageBucketSize in interface IQueryResultProvider
        Returns:
        if available, an estimate of the average size of each projection group of the match set, with the desired accuracy.
      • estimateCost

        public double estimateCost​(TupleMask inputBindingMask)
        Since:
        2.1
        No Reference:
        This method is not intended to be referenced by clients.
      • getAllMatches

        public java.util.stream.Stream<Tuple> getAllMatches​(java.lang.Object[] parameters)
        Description copied from interface: IQueryResultProvider
        Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
        Specified by:
        getAllMatches in interface IQueryResultProvider
        Parameters:
        parameters - array where each non-null element binds the corresponding pattern parameter to a fixed value.
        Returns:
        matches represented in the internal Tuple representation.
      • getAllMatches

        public java.util.stream.Stream<Tuple> getAllMatches​(TupleMask parameterSeedMask,
                                                            ITuple parameters)
        Description copied from interface: IQueryResultProvider
        Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
        Specified by:
        getAllMatches in interface IQueryResultProvider
        Parameters:
        parameterSeedMask - a mask that extracts those parameters of the query (from the entire parameter list) that should be bound to a fixed value
        parameters - the tuple of fixed values restricting the match set to be considered, in the same order as given in parameterSeedMask, so that for each considered match tuple, projectedParameterSeed.equals(parameterSeedMask.transform(match)) should hold
        Returns:
        matches represented in the internal Tuple representation.
      • addUpdateListener

        public void addUpdateListener​(IUpdateable listener,
                                      java.lang.Object listenerTag,
                                      boolean fireNow)
        Description copied from interface: IQueryResultProvider
        Internal method that registers low-level callbacks for match appearance and disappearance.

        Caution: This is a low-level callback that is invoked when the pattern matcher is not necessarily in a consistent state yet. Importantly, no model modification permitted during the callback.

        The callback can be unregistered via invoking IQueryResultProvider.removeUpdateListener(Object) with the same tag.

        Specified by:
        addUpdateListener in interface IQueryResultProvider
        Parameters:
        listener - the listener that will be notified of each new match that appears or disappears, starting from now.
        listenerTag - a tag by which to identify the listener for later removal by IQueryResultProvider.removeUpdateListener(Object).
        fireNow - if true, the insertion update allback will be immediately invoked on all current matches as a one-time effect.
      • forgetAllPlans

        public void forgetAllPlans()
        Forgets all stored plans in this result provider. If no plans are stored, nothing happens.
        Since:
        2.0
        No Reference:
        This method is not intended to be referenced by clients; it should only used by LocalSearchBackend.
      • getSearchPlan

        public IPlanDescriptor getSearchPlan​(java.util.Set<PParameter> adornment)
        Returns a search plan for a given adornment if exists
        Returns:
        a search plan for the pattern with the given adornment, or null if none exists
        Since:
        2.0
        No Reference:
        This method is not intended to be referenced by clients; it should only used by LocalSearchBackend.