public AliasIndex(CQIE query, ImmutableMap<Predicate, FromItem> subQueryDefinitions) { for (Function atom : query.getBody()) { // This will be called recursively if necessary generateViewsIndexVariables(atom, subQueryDefinitions); } }
/** * Check if query cq1 is contained in cq2, syntactically. That is, if the * head of cq1 and cq2 are equal according to toString().equals and each * atom in cq2 is also in the body of cq1 (also by means of toString().equals(). */ private static boolean isContainedIn(CQIE cq1, CQIE cq2) { if (!cq2.getHead().equals(cq1.getHead())) return false; for (Function atom : cq2.getBody()) if (!cq1.getBody().contains(atom)) return false; return true; }
AliasIndex(CQIE query, ImmutableMap<Predicate, FromItem> subQueryDefinitions, AtomicInteger viewCounter) { this.viewCounter = viewCounter; for (Function atom : query.getBody()) { // This will be called recursively if necessary generateViewsIndexVariables(atom, subQueryDefinitions); } }
public QueryAliasIndex(CQIE query, Map<Predicate, ParserViewDefinition> subQueryDefinitions) { List<Function> body = query.getBody(); generateViews(body, subQueryDefinitions); }
/*** * This expands all Join that can be directly added as conjuncts to a * query's body. Nested Join trees inside left joins are not touched. * * @param query * @return */ public static void unfoldJoinTrees(CQIE query) { unfoldJoinTrees(query.getBody(), true); }
public static void pullOutLeftJoinConditions(CQIE query) { Set<Function> booleanAtoms = new HashSet<>(); Set<Function> tempBooleans = new HashSet<>(); List<Function> body = query.getBody(); pullOutLJCond(body, booleanAtoms, false, tempBooleans, false); body.addAll(booleanAtoms); }
public void foldJoinTrees(CQIE query) { foldJoinTrees(query.getBody(), false); }
public static void addMinimalEqualityToLeftJoin(CQIE query) { for (Function f : query.getBody()) { if (f.isAlgebraFunction()) { addMinimalEqualityToLeftJoin(f); } } }
/*** * Adds a trivial equality to a LeftJoin in case the left join doesn't have * at least one boolean condition. This is necessary to have syntactically * correct LeftJoins in SQL. */ public void addMinimalEqualityToLeftOrNestedInnerJoin(CQIE query) { for (Function f : query.getBody()) { if (f.isAlgebraFunction()) { addMinimalEqualityToLeftOrNestedInnerJoin(f); } } }
private Substitution computeHomomorphism(CQIE query) { SubstitutionBuilder sb = new SubstitutionBuilder(termFactory); // get the substitution for the head first // it will ensure that all answer variables are mapped either to constants or // to answer variables in the base (but not to the labelled nulls generated by the chase) boolean headResult = extendHomomorphism(sb, query.getHead(), head); if (!headResult) return null; Substitution sub = computeSomeHomomorphism(sb, query.getBody(), factMap); return sub; } }
@Override public MappingWithProvenance convertMappingRules(ImmutableMap<CQIE, PPMappingAssertionProvenance> datalogMap, MappingMetadata mappingMetadata) { ImmutableSet<Predicate> extensionalPredicates = datalogMap.keySet().stream() .flatMap(r -> r.getBody().stream()) .flatMap(Datalog2QueryTools::extractPredicates) .collect(ImmutableCollectors.toSet()); ImmutableMap<IQ, PPMappingAssertionProvenance> iqMap = datalogMap.entrySet().stream() .collect(ImmutableCollectors.toMap( e -> convertDatalogRule(e.getKey(), extensionalPredicates), Map.Entry::getValue)); return provMappingFactory.create(iqMap, mappingMetadata); }
public int getMaxQuerySizeAfterRewriting() { int toReturn = Integer.MIN_VALUE; if( sizesCollected() ){ List<CQIE> rules = programAfterRewriting.getRules(); for (CQIE rule : rules) { int querySize = getBodySize(rule.getBody()); if (querySize > toReturn) { toReturn = querySize; } } } return toReturn; }
public int getMinQuerySizeAfterUnfolding() { int toReturn = Integer.MAX_VALUE; if( sizesCollected() ){ List<CQIE> rules = programAfterUnfolding.getRules(); for (CQIE rule : rules) { int querySize = getBodySize(rule.getBody()); if (querySize < toReturn) { toReturn = querySize; } } } return (toReturn == Integer.MAX_VALUE) ? 0 : toReturn; }
public int getMinQuerySizeAfterRewriting() { int toReturn = Integer.MAX_VALUE; if( sizesCollected() ){ List<CQIE> rules = programAfterRewriting.getRules(); for (CQIE rule : rules) { int querySize = getBodySize(rule.getBody()); if (querySize < toReturn) { toReturn = querySize; } } } return toReturn; }
public int getMaxQuerySizeAfterUnfolding() { int toReturn = Integer.MIN_VALUE; if( sizesCollected() ){ List<CQIE> rules = programAfterUnfolding.getRules(); for (CQIE rule : rules) { int querySize = getBodySize(rule.getBody()); if (querySize > toReturn) { toReturn = querySize; } } } return (toReturn == Integer.MIN_VALUE) ? 0 : toReturn; }
private Substitution computeHomomorphism(CQIE query) { SubstitutionBuilder sb = new SubstitutionBuilder(); // get the substitution for the head first // it will ensure that all answer variables are mapped either to constants or // to answer variables in the base (but not to the labelled nulls generated by the chase) boolean headResult = HomomorphismUtilities.extendHomomorphism(sb, query.getHead(), head); if (!headResult) return null; Substitution sub = HomomorphismUtilities.computeHomomorphism(sb, query.getBody(), factMap); return sub; } }
public void insertDataTyping(CQIE rule) throws UnknownDatatypeException { Function atom = rule.getHead(); //case of data and object property if(!Datalog2QueryTools.isURIRDFType(atom.getTerm(1))){ Term object = atom.getTerm(2); // the object, third argument only Map<String, List<IndexedPosition>> termOccurenceIndex = createIndex(rule.getBody()); // Infer variable datatypes insertVariableDataTyping(object, atom, 2, termOccurenceIndex); // Infer operation datatypes from variable datatypes insertOperationDatatyping(object, atom, 2); } }
public void insertDataTyping(CQIE rule) throws UnknownDatatypeException { Function atom = rule.getHead(); Predicate predicate = atom.getFunctionSymbol(); if (predicate.getArity() == 2) { // we check both for data and object property Term term = atom.getTerm(1); // the second argument only Map<String, List<IndexedPosition>> termOccurenceIndex = createIndex(rule.getBody()); // Infer variable datatypes insertVariableDataTyping(term, atom, 1, termOccurenceIndex); // Infer operation datatypes from variable datatypes insertOperationDatatyping(term, atom, 1); } }