public Boolean isDataOrLeftJoinOrJoinAtom(Function atom) { return atom.isDataFunction() || isLeftJoinOrJoinAtom(atom); }
public static Boolean isDataOrLeftJoinOrJoinAtom(Function atom) { return atom.isDataFunction() || isLeftJoinOrJoinAtom(atom); }
/*** * Computes a query in which all terms have been replaced by * ValueConstants that have the no type and have the same 'name' as the * original variable. * * This new query can be used for query containment checking. * */ public IndexedCQ(Function head, Collection<Function> body) { this.head = head; this.factMap = new HashMap<>(body.size() * 2); for (Function atom : body) // not boolean, not algebra, not arithmetic, not datatype if (atom != null && atom.isDataFunction()) { Predicate pred = atom.getFunctionSymbol(); List<Function> facts = factMap.get(pred); if (facts == null) { facts = new LinkedList<Function>(); factMap.put(pred, facts); } facts.add(atom); } }
/*** * Computes a query in which all terms have been replaced by * ValueConstants that have the no type and have the same 'name' as the * original variable. * * This new query can be used for query containment checking. * */ public IndexedCQ(Function head, Collection<Function> body) { this.head = head; this.factMap = new HashMap<>(body.size() * 2); for (Function atom : body) // not boolean, not algebra, not arithmetic, not datatype if (atom != null && atom.isDataFunction()) { Predicate pred = atom.getFunctionSymbol(); List<Function> facts = factMap.get(pred); if (facts == null) { facts = new LinkedList<Function>(); factMap.put(pred, facts); } facts.add(atom); } }
/** * Extracts all the data atoms (without preserving the algebraic structure) */ private static Stream<Function> extractDataAtoms(Collection<? extends Term> atoms) { return atoms.stream() .filter(t -> t instanceof Function) .map(f -> (Function) f) .flatMap(a -> { if (a.isDataFunction()) { return Stream.of(a); } else if (a.isAlgebraFunction()) { return extractDataAtoms(a.getTerms()); } else { return Stream.empty(); } }); }
/** * Extracts all the data atoms (without preserving the algebraic structure) */ private static Stream<Function> extractDataAtoms(Collection<? extends Term> atoms) { return atoms.stream() .filter(t -> t instanceof Function) .map(f -> (Function) f) .flatMap(a -> { if (a.isDataFunction()) { return Stream.of(a); } else if (a.isAlgebraFunction()) { return extractDataAtoms(a.getTerms()); } else { return Stream.empty(); } }); }
/** * Extracts all the data atoms (without preserving the algebraic structure) */ private static Stream<Function> extractDataAtoms(Collection<? extends Term> atoms) { return atoms.stream() .filter(t -> t instanceof Function) .map(f -> (Function) f) .flatMap(a -> { if (a.isDataFunction()) { return Stream.of(a); } else if (a.isAlgebraFunction()) { return extractDataAtoms(a.getTerms()); } else { return Stream.empty(); } }); }
private Set<String> getEqConditionsForConstants(List<Function> atoms, AliasIndex index) { Set<String> equalities = new LinkedHashSet<>(); for (Function atom : atoms) { if (atom.isDataFunction()) { for (int i = 0; i < atom.getArity(); i++) { Term t = atom.getTerm(i); if (t instanceof Constant) { String value = getSQLString(t, index, false); QualifiedAttributeID column = index.getColumn(atom, i); equalities.add(String.format("(%s = %s)", column.getSQLRendering(), value)); } } } } return equalities; }
private Set<String> getEqConditionsForConstants(List<Function> atoms, AliasIndex index) { Set<String> equalities = new LinkedHashSet<>(); for (Function atom : atoms) { if (atom.isDataFunction()) { for (int i = 0; i < atom.getArity(); i++) { Term t = atom.getTerm(i); if (t instanceof Constant) { String value = getSQLString(t, index, false); QualifiedAttributeID column = index.getColumn(atom, i); equalities.add(String.format("(%s = %s)", column.getSQLRendering(), value)); } } } } return equalities; }
queueInAtom.add(term); } else if (funcRoot.isDataFunction()) { dependentList.add(funcRoot.getFunctionSymbol());
continue; Function atom = (Function) atoms.get(i); if (atom.isDataFunction()) { TermUtils.addReferencedVariablesTo(currentLevelVariables, atom); } else if (atom.isAlgebraFunction()) {
queueInAtom.add(term); } else if (funcRoot.isDataFunction()) { dependentList.add(funcRoot.getFunctionSymbol());
queueInAtom.add(term); } else if (funcRoot.isDataFunction()) { if (!ruleIndexByBodyPredicate.containsEntry(funcRoot.getFunctionSymbol(), rule)){ ruleIndexByBodyPredicate.put(funcRoot.getFunctionSymbol(), rule);
/** * updates * * @param rule */ public void updateRuleIndexByBodyPredicate(CQIE rule) { for (Function bodyAtom : rule.getBody()) { if (bodyAtom.isDataFunction()) { Predicate functionSymbol = bodyAtom.getFunctionSymbol(); if (!ruleIndexByBodyPredicate.containsEntry(functionSymbol, rule)){ ruleIndexByBodyPredicate.put(functionSymbol, rule); } } else if (bodyAtom.isAlgebraFunction() || bodyAtom.isOperation()) { updateRuleIndexByBodyPredicate_traverseBodyAtom(rule, bodyAtom); // BC: should we reintroduce arithmetic functions? //} else if (bodyAtom.isArithmeticFunction() || bodyAtom.isDataTypeFunction()){ } else if (bodyAtom.isDataTypeFunction()){ continue; } else { throw new IllegalStateException("Unknown Function"); } } }
/** * Collects (recursively) the set of variables that participate in data atoms * (either in this atom directly or in nested ones, excluding those on the * right-hand side of left joins. * * @param vars * @param atom * @return */ private void collectVariableReferencesWithLeftJoin(Set<Variable> vars, Function atom) { if (atom.isDataFunction()) { TermUtils.addReferencedVariablesTo(vars, atom); } else if (atom.isAlgebraFunction()) { Predicate functionSymbol = atom.getFunctionSymbol(); if (functionSymbol.equals(datalogFactory.getSparqlJoinPredicate())) { // if it's a join, we need to collect all the variables of each nested atom convert(atom.getTerms()).stream() .filter(f -> !f.isOperation()) .forEach(f -> collectVariableReferencesWithLeftJoin(vars, f)); } else if (functionSymbol.equals(datalogFactory.getSparqlLeftJoinPredicate())) { // if it's a left join, only of the first data/algebra atom (the left atom) collectVariableReferencesWithLeftJoin(vars, (Function) atom.getTerm(0)); } } }
/** * updates * * @param rule */ public void updateRuleIndexByBodyPredicate(CQIE rule) { for (Function bodyAtom : rule.getBody()) { if (bodyAtom.isDataFunction()) { Predicate functionSymbol = bodyAtom.getFunctionSymbol(); if (!ruleIndexByBodyPredicate.containsEntry(functionSymbol, rule)){ ruleIndexByBodyPredicate.put(functionSymbol, rule); } } else if (bodyAtom.isAlgebraFunction() || bodyAtom.isOperation()) { updateRuleIndexByBodyPredicate_traverseBodyAtom(rule, bodyAtom); // BC: should we reintroduce arithmetic functions? //} else if (bodyAtom.isArithmeticFunction() || bodyAtom.isDataTypeFunction()){ } else if (bodyAtom.isDataTypeFunction()){ continue; } else { throw new IllegalStateException("Unknown Function"); } } }
/** * Removes the old indexes given by a rule. * * @param rule */ public void removeOldRuleIndexByBodyPredicate(CQIE rule) { for (Function bodyAtom : rule.getBody()) { if (bodyAtom.isDataFunction()) { Predicate functionSymbol = bodyAtom.getFunctionSymbol(); if (ruleIndexByBodyPredicate.containsEntry(functionSymbol, rule)){ ruleIndexByBodyPredicate.remove(functionSymbol, rule); } } else if (bodyAtom.isAlgebraFunction() || bodyAtom.isOperation()) { removeRuleIndexByBodyPredicate_traverseBodyAtom(rule, bodyAtom); // BC: should we reintroduce arithmetic functions?//} // else if (bodyAtom.isArithmeticFunction() || bodyAtom.isDataTypeFunction()){ } else if (bodyAtom.isDataTypeFunction()){ continue; } else { throw new IllegalStateException("Unknown Function"); } } }
/** * Collects (recursively) the set of variables that participate in data atoms * (either in this atom directly or in nested ones, excluding those on the * right-hand side of left joins. * * @param vars * @param atom * @return */ private void collectVariableReferencesWithLeftJoin(Set<Variable> vars, Function atom) { if (atom.isDataFunction()) { TermUtils.addReferencedVariablesTo(vars, atom); } else if (atom.isAlgebraFunction()) { Predicate functionSymbol = atom.getFunctionSymbol(); if (functionSymbol == DatalogAlgebraOperatorPredicates.SPARQL_JOIN) { // if it's a join, we need to collect all the variables of each nested atom convert(atom.getTerms()).stream() .filter(f -> !f.isOperation()) .forEach(f -> collectVariableReferencesWithLeftJoin(vars, f)); } else if (functionSymbol == DatalogAlgebraOperatorPredicates.SPARQL_LEFTJOIN) { // if it's a left join, only of the first data/algebra atom (the left atom) collectVariableReferencesWithLeftJoin(vars, (Function) atom.getTerm(0)); } } }
if (bodyAtom.isDataFunction()) { dependencyList.add(bodyAtom.getFunctionSymbol()); } else if (bodyAtom.isAlgebraFunction() || bodyAtom.isOperation()) {
if (bodyAtom.isDataFunction()) { dependencyList.add(bodyAtom.getFunctionSymbol()); } else if (bodyAtom.isAlgebraFunction() || bodyAtom.isOperation()) {