Class RDBMSStore
java.lang.Object
fr.inria.rules.dlgpemodel.HasItemInfoImpl
fr.inria.rules.dlgpemodel.SentenceImpl
fr.inria.rules.integraal.storage.external.rdbms.RDBMSStore
- All Implemented Interfaces:
fr.inria.rules.dlgpemodel.api.sentences.HasItemInfo, fr.inria.rules.dlgpemodel.api.sentences.IFact, fr.inria.rules.dlgpemodel.api.sentences.IPrintable, fr.inria.rules.dlgpemodel.api.sentences.ISentence, Labeled, Printable, Sentence, DatalogDelegable, MaterializedData, QueryableData, QueryDelegatableData, Writable, CSVCopyable, FactBase, TermCompound, Iterable<Atom>
public class RDBMSStore
extends fr.inria.rules.dlgpemodel.SentenceImpl
implements FactBase, QueryDelegatableData, DatalogDelegable, CSVCopyable
This wrapper represents RDBMS handled by InteGraal. They are accessed by
translating atoms, queries and even some rules into SQL queries following the
given storage strategy.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringName of the column used when SQL delegation returns only the answer count.Fields inherited from interface fr.inria.rules.dlgpemodel.api.sentences.HasItemInfo
IDENTFields inherited from interface fr.inria.rules.dlgpemodel.api.sentences.IPrintable
WRITER -
Constructor Summary
ConstructorsConstructorDescriptionRDBMSStore(RDBMSDriver driver, RDBMSStorageLayout strategy, TermFactory termFactory, PredicateFactory predicateFactory) Creates a new wrapper over a RDBMS using user-given parameters -
Method Summary
Modifier and TypeMethodDescriptionbooleanStores the given atomsbooleanStores the given atombooleanaddAll(Collection<Atom> atoms) Stores the given atomsbooleanStores the given atomsvoidclear()Removes all atoms from the fact base.booleanTests whether a given atom is present in this data source.booleanCopy the content of the given CSV file into the storage system The exact layout of the resulting storage is dependent on the implementationEvaluate the given (conjunctive) querybooleandelegate(Collection<FORule> rules) Apply all the given (datalog) rules.Returns a textual dump of the dictionary table.longReturns the number of entries stored in the dictionary table.estimateBound(BasicQuery query) //////////////////////////////////////////////evaluate(BasicQuery query) Try to evaluate a basic queryTry to evaluate a basic querygetAtomicPattern(Predicate predicate) Get the basic pattern for a given predicate//////////////////////////////////////////////getDescription(Predicate viewPredicate) Returns the storage description associated with a predicate.Returns the RDBMS driver backing this store.Returns the SQL evaluator used by this store.Returns a collection of all predicates in this Readable.Returns the storage layout used by this store.getTerms()Streams the first-level terms contained in this object.getTermsByPredicatePosition(Predicate p, int position) Returns a stream over terms which are in a specific position in at least one atom with the given predicate.Returns the storage type associated with a predicate.booleanAllows checking if this QueryableData provides the predicate pbooleanisEvaluable(Query query) Checks if a query can be evaluatedbooleanRemoves the given atomsbooleanRemoves the given atombooleanremoveAll(Collection<Atom> atoms) Removes the given atomslongsize()Counts the atoms contained in this data source.toDLGP()Renders this object in DLGP form.Preconditions : - the given rule have a body that can be translated by this.translate(FOQuery) - the head have no existential variablesMethods inherited from class fr.inria.rules.dlgpemodel.SentenceImpl
getPatterns, setPatternsMethods inherited from class fr.inria.rules.dlgpemodel.HasItemInfoImpl
getItemInfo, setItemInfoMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DatalogDelegable
delegateMethods inherited from interface FactBase
getColumnsType, getHeadMethods inherited from interface fr.inria.rules.dlgpemodel.api.sentences.HasItemInfo
getIdentifier, getInfo, getItemInfo, setIdentifier, setInfo, setItemInfoMethods inherited from interface fr.inria.rules.dlgpemodel.api.sentences.IPrintable
toDLGPEMethods inherited from interface fr.inria.rules.dlgpemodel.api.sentences.ISentence
setPatternsMethods inherited from interface Iterable
forEach, spliteratorMethods inherited from interface MaterializedData
getAtomsByPredicate, getAtomSet, isEmpty, iterator, streamMethods inherited from interface QueryableData
estimateBound, evaluateMethods inherited from interface QueryDelegatableData
evaluateMethods inherited from interface Sentence
getLabel, getPatterns, setLabelMethods inherited from interface TermCompound
getAllNestedTerms, getConstants, getLiterals, getNestedTerms, getVariables
-
Field Details
-
COUNT_VARIABLE_NAME
Name of the column used when SQL delegation returns only the answer count.- See Also:
-
-
Constructor Details
-
RDBMSStore
public RDBMSStore(RDBMSDriver driver, RDBMSStorageLayout strategy, TermFactory termFactory, PredicateFactory predicateFactory) throws SQLException Creates a new wrapper over a RDBMS using user-given parameters- Parameters:
driver- the driver to use to connect to the databasestrategy- the strategy for representing atomstermFactory- the term factorypredicateFactory- the predicate factory- Throws:
SQLException- if an error occurs during connection or initialization
-
-
Method Details
-
estimateBound
//////////////////////////////////////////////- Specified by:
estimateBoundin interfaceQueryableData- 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
Description copied from interface:QueryableDataGet the basic pattern for a given predicate- Specified by:
getAtomicPatternin interfaceQueryableData- Parameters:
predicate- the predicate for which we want to know the basic pattern- Returns:
- a basic pattern for predicate
-
getTerms
Description copied from interface:TermCompoundStreams the first-level terms contained in this object.- Specified by:
getTermsin interfaceTermCompound- Returns:
- a stream over all the non-nested terms (i.e., all terms that are not themselves in a compound term) For instance, for p(a,g(b)), it returns a and g(b) but not b.
-
isEvaluable
Description copied from interface:QueryDelegatableDataChecks if a query can be evaluated- Specified by:
isEvaluablein interfaceQueryDelegatableData- Parameters:
query- the query to check- Returns:
- true iff tryEvaluate returns a non-empty optional
-
evaluate
Description copied from interface:QueryDelegatableDataTry to evaluate a basic query- Specified by:
evaluatein interfaceQueryDelegatableData- Parameters:
query- the query to evaluatedistinct- whether duplicate substitutions should be filtered out- Returns:
- Empty if the query is not evaluable, otherwise a stream containing substitutions that are the answers to the query
- Throws:
EvaluationException- if delegated evaluation fails
-
evaluate
Description copied from interface:QueryableDataTry to evaluate a basic query- Specified by:
evaluatein interfaceQueryableData- 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
-
add
-
addAll
-
addAll
Description copied from interface:WritableStores the given atoms -
add
-
remove
-
remove
-
removeAll
Description copied from interface:WritableRemoves the given atoms -
getPredicates
Description copied from interface:QueryableDataReturns a collection of all predicates in this Readable.- Specified by:
getPredicatesin interfaceQueryableData- Returns:
- a collection of all predicates.
-
hasPredicate
Description copied from interface:QueryableDataAllows checking if this QueryableData provides the predicate p- Specified by:
hasPredicatein interfaceQueryableData- Parameters:
p- the predicate to look up- Returns:
- boolean that is true iff the QueryableData provides this predicate
-
getTermsByPredicatePosition
Description copied from interface:MaterializedDataReturns a stream over terms which are in a specific position in at least one atom with the given predicate.- Specified by:
getTermsByPredicatePositionin interfaceMaterializedData- Parameters:
p- predicateposition- the position of the term in atoms, positions starts from 0.- Returns:
- a stream over terms which appear in the specified position of the specified predicate.
-
getEvaluator
Returns the SQL evaluator used by this store.- Returns:
- the evaluator
-
getDriver
-
getStrategy
Returns the storage layout used by this store.- Returns:
- the storage layout
-
delegate
Description copied from interface:DatalogDelegableApply all the given (datalog) rules.- Specified by:
delegatein interfaceDatalogDelegable- Parameters:
rules- the rules to apply- Returns:
- true iff at least one atom have been produced by the application of the rules
- Throws:
Exception- if a given rule is not datalog. The exact type is depending on the implementation
-
delegate
Description copied from interface:DatalogDelegableEvaluate the given (conjunctive) query- Specified by:
delegatein interfaceDatalogDelegable- Parameters:
query- the query to evaluateonlyCountAnswers- true iff the query has to return only the number of answers- Returns:
- an
IteratorofSubstitutionover all the answers of the given query with respect to the query answer variables. - Throws:
Exception- if the given query is not conjunctive. The exact type is depending on the implementation
-
copy
public boolean copy(String csvFilePath, char separator, int headerSize, Atom witness) throws SQLException Description copied from interface:CSVCopyableCopy the content of the given CSV file into the storage system The exact layout of the resulting storage is dependent on the implementation- Specified by:
copyin interfaceCSVCopyable- Parameters:
csvFilePath- the csv file to copyseparator- separator char of the CSVheaderSize- size of the CSV headerwitness- atom used to pre-create the storing schema- Returns:
- true iff at least one atom have been added by the copy
- Throws:
SQLException
-
getAtomsByTerm
//////////////////////////////////////////////- Specified by:
getAtomsByTermin interfaceMaterializedData- Parameters:
t- to search- Returns:
- a stream over all atoms with the specified term
-
contains
Description copied from interface:MaterializedDataTests whether a given atom is present in this data source.- Specified by:
containsin interfaceMaterializedData- Parameters:
a- the atom to find- Returns:
- true iff this storage contains the given atom
-
size
public long size()Description copied from interface:MaterializedDataCounts the atoms contained in this data source.- Specified by:
sizein interfaceMaterializedData- Returns:
- the number of atoms
-
dictionarySize
public long dictionarySize()Returns the number of entries stored in the dictionary table.- Returns:
- the dictionary size, or
-1when it cannot be determined
-
dictionaryList
Returns a textual dump of the dictionary table.- Returns:
- the formatted dictionary content
-
getType
Description copied from interface:FactBaseReturns the storage type associated with a predicate. -
getDescription
Description copied from interface:FactBaseReturns the storage description associated with a predicate.- Specified by:
getDescriptionin interfaceFactBase- Parameters:
viewPredicate- a predicate- Returns:
- the description of the storage
-
translate
Preconditions : - the given rule have a body that can be translated by this.translate(FOQuery) - the head have no existential variables- Parameters:
rule- the rule to translate- Returns:
- all the queries and there arguments that should be executed to apply the given rule on the database
- Throws:
SQLException- if an error occur during translation
-
clear
-
toDLGP
-
getSupportedOperations
- Specified by:
getSupportedOperationsin interfaceQueryableData- Returns:
- the set of operations and optimizations that are supported by the datasource
-