Class AbstractDataSource<NativeQueryType, NativeResultType>

java.lang.Object
fr.inria.rules.integraal.views.datasource.AbstractDataSource<NativeQueryType, NativeResultType>
Type Parameters:
NativeQueryType - the type used to represent the native query
NativeResultType - the type used to represent the results as the native format
All Implemented Interfaces:
QueryableData, DataSource<NativeQueryType, NativeResultType>
Direct Known Subclasses:
MongoDBDataSource, SPARQLDataSource, SQLDataSource, WebAPIDataSource

public abstract class AbstractDataSource<NativeQueryType, NativeResultType> extends Object implements DataSource<NativeQueryType, NativeResultType>
This wrapper represents data-sources accessed using mappings. These sources are queried by user-given queries with read-only rights
A data-source can define several relational views, which associate a Predicate (of the relational view) to a specification of this view
  • Constructor Details

    • AbstractDataSource

      protected AbstractDataSource(Specializer<NativeQueryType> specializer, NativeQueryEvaluator<NativeQueryType, NativeResultType> evaluator, fr.inria.rules.integraal.views.transformer.Transformer<NativeResultType> transformer)
      Create a new wrapper over a data-source with a relational view
      Parameters:
      specializer - to specialize the native query
      evaluator - to evaluate the native query
      transformer - to transform the native result into atoms
    • AbstractDataSource

      protected AbstractDataSource(String name, Specializer<NativeQueryType> specializer, NativeQueryEvaluator<NativeQueryType, NativeResultType> evaluator, fr.inria.rules.integraal.views.transformer.Transformer<NativeResultType> transformer)
      Create a new wrapper over a data-source with a relational view
      Parameters:
      name - to identify the datasource
      specializer - to specialize the native query
      evaluator - to evaluate the native query
      transformer - to transform the native result into atoms
  • Method Details

    • registerView

      public void registerView(Predicate p, ViewParameters<NativeQueryType> viewParameters)
      Register the given view and configuration Replaces existing mapping associated to the given predicate if any exists
      Parameters:
      p - view predicate associated to this mapping
      viewParameters - associated to this view predicate
    • getViewParameters

      public ViewParameters<NativeQueryType> getViewParameters(Predicate p)
      Description copied from interface: DataSource
      Returns the parameters used to query the supplied predicate from this source.
      Specified by:
      getViewParameters in interface DataSource<NativeQueryType, NativeResultType>
      Parameters:
      p - the predicate representing the relational view
      Returns:
      the native query associated to the view predicate p
    • getPredicates

      public Stream<Predicate> getPredicates()
      Description copied from interface: QueryableData
      Returns a collection of all predicates in this Readable.
      Specified by:
      getPredicates in interface QueryableData
      Returns:
      the predicates corresponding to the relational views of the datasource
    • hasPredicate

      public boolean hasPredicate(Predicate p)
      Description copied from interface: QueryableData
      Allows checking if this QueryableData provides the predicate p
      Specified by:
      hasPredicate in interface QueryableData
      Parameters:
      p - the predicate to look up
      Returns:
      boolean that is true iff the QueryableData provides this predicate
    • evaluate

      public Stream<List<Term>> evaluate(BasicQuery query) throws EvaluationException
      Description copied from interface: QueryableData
      Try to evaluate a basic query
      Specified by:
      evaluate in interface QueryableData
      Parameters:
      query - the query to evaluate
      Returns:
      Empty if the query is not evaluable, otherwise a stream containing substitutions that are the answers to the query
      Throws:
      EvaluationException - if query evaluation fails
    • evaluate

      public Stream<List<Term>> evaluate(BasicQuery query, List<Integer> sequenceOfAnswerVariables) throws EvaluationException
      Description copied from interface: QueryableData
      Try to evaluate a basic query
      Specified by:
      evaluate in interface QueryableData
      Parameters:
      query - the query to evaluate
      sequenceOfAnswerVariables - the sequence of answer variables that define the signature of the resulting tuple
      Returns:
      Empty if the query is not evaluable, otherwise a stream containing lists of term ; each list corresponds to the substitution of the answer variables with the corresponding terms
      Throws:
      EvaluationException - if query evaluation fails
    • estimateBound

      public Optional<Long> estimateBound(BasicQuery query)
      Description copied from interface: QueryableData
      Estimate the number of answers to a query The estimation is the upper bound, meaning the actual number of answers will not exceed this number. Implementations may return an empty Optional if they cannot provide an estimation.
      Specified by:
      estimateBound in interface QueryableData
      Parameters:
      query - the query for which we want to know the upper bound
      Returns:
      an Optional containing the estimated upper bound of answers, or an empty Optional if estimation is not possible
    • getAtomicPattern

      public AtomicPattern getAtomicPattern(Predicate predicate)
      Description copied from interface: QueryableData
      Get the basic pattern for a given predicate
      Specified by:
      getAtomicPattern in interface QueryableData
      Parameters:
      predicate - the predicate for which we want to know the basic pattern
      Returns:
      a basic pattern for predicate
    • getName

      public Optional<String> getName()
      Description copied from interface: DataSource
      Returns the optional user-facing name of this data source.
      Specified by:
      getName in interface DataSource<NativeQueryType, NativeResultType>
      Returns:
      an optional that contains the datasource name if there is one
    • setName

      public void setName(String name)
      Description copied from interface: DataSource
      Sets the user-facing name of this data source.
      Specified by:
      setName in interface DataSource<NativeQueryType, NativeResultType>
      Parameters:
      name - the new datasource name