public Boolean isLeftJoinOrJoinAtom(Function atom) { Predicate predicate = atom.getFunctionSymbol(); return predicate.equals(datalogFactory.getSparqlLeftJoinPredicate()) || predicate.equals(datalogFactory.getSparqlJoinPredicate()); }
} else { dataAtoms.add(atom); if (atom.getFunctionSymbol().equals(datalogFactory.getSparqlLeftJoinPredicate())) foldJoinTrees(atom.getTerms(), false); if (atom.getFunctionSymbol().equals(datalogFactory.getSparqlJoinPredicate()))
/** * 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)); } } }
/** * Returns the table definition for the given atom. If the atom is a simple * table or view, then it returns the value as defined by the * AliasIndex. If the atom is a Join or Left Join, it will call * getTableDefinitions on the nested term list. */ private String getTableDefinition(Function atom, AliasIndex index, String indent) { if (atom.isAlgebraFunction()) { Predicate functionSymbol = atom.getFunctionSymbol(); ImmutableList<Function> joinAtoms = convert(atom.getTerms()); if (functionSymbol.equals(datalogFactory.getSparqlJoinPredicate())) { // nested joins we need to add parenthesis later boolean parenthesis = joinAtoms.get(0).isAlgebraFunction() || joinAtoms.get(1).isAlgebraFunction(); return getTableDefinitions(joinAtoms, index, "JOIN", parenthesis, indent + INDENT); } else if (functionSymbol.equals(datalogFactory.getSparqlLeftJoinPredicate())) { // in case of left join we want to add the parenthesis only for the right tables // we ignore nested joins from the left tables boolean parenthesis = joinAtoms.get(1).isAlgebraFunction(); return getTableDefinitions(joinAtoms, index, "LEFT OUTER JOIN", parenthesis, indent + INDENT); } } else if (!atom.isOperation() && !atom.isDataTypeFunction()) { return index.getViewDefinition(atom); // a database atom } return null; }
return convertAtoms(subAtoms, tablePredicates, iqFactory); else if(atomPredicate.equals(datalogFactory.getSparqlLeftJoinPredicate())) { return convertLeftJoinAtom(subAtoms, tablePredicates, iqFactory);