Пример #1
0
 public static String generateProjectionForTgd(
     ComplexQueryWithNegations query,
     List<VariableCorrespondence> correspondences,
     int chainingStep) {
   String fromClause = GenerateSQL.generateFromClause(query.getVariables(), chainingStep);
   String whereClause = GenerateSQL.generateWhereClause(query.getComplexQuery());
   return projectionOnTargetValuesFromCorrespondences(correspondences, fromClause, whereClause);
 }
Пример #2
0
 public void visitComplexQueryWithNegation(ComplexQueryWithNegations query) {
   stack.add(0, query);
   //        List<FormulaVariable> universalVariables =
   // variableFinder.getUniversalVariables(variableMaps, stack);
   //        variables.add(0, universalVariables);
   ComplexConjunctiveQuery positiveQuery = query.getComplexQuery();
   positiveQuery.accept(this);
   List<NegatedComplexQuery> sortedQueries =
       new ArrayList<NegatedComplexQuery>(query.getNegatedComplexQueries());
   Collections.sort(sortedQueries);
   for (NegatedComplexQuery negatedQuery : sortedQueries) {
     negatedQuery.accept(this);
   }
   //        variables.remove(0);
   stack.remove(0);
 }
Пример #3
0
 private static String findViewName(NegatedComplexQuery negation) {
   String fromViewName;
   ComplexQueryWithNegations negatedQuery = negation.getComplexQuery();
   if (materializedViews.containsKey(negatedQuery.getId())) {
     return materializedViews.get(negatedQuery.getId());
   }
   //        if (materializedViews.containsKey(negatedQuery.toString())) {
   //            return materializedViews.get(negatedQuery.toString());
   //        }
   if (negatedQuery
       .getNegatedComplexQueries()
       .isEmpty()) { // || isRewiQueryWithOnlySubsumeNegations(negatedQuery)) {
     fromViewName = sqlNameForPositiveView(negation.getComplexQuery());
   } else {
     fromViewName = sqlNameForViewWithIntersection(negation.getComplexQuery());
   }
   return fromViewName;
 }
Пример #4
0
 private NegatedComplexQuery generateNegatedQueryForCoverage(Coverage coverage) {
   if (logger.isDebugEnabled())
     logger.debug("************ Generating query for coverage:\n" + coverage);
   ComplexConjunctiveQuery complexQuery = new ComplexConjunctiveQuery();
   List<VariableCorrespondence> matchingCorrespondences = new ArrayList<VariableCorrespondence>();
   for (CoverageAtom coverageAtom : coverage.getCoveringAtoms()) {
     SimpleConjunctiveQuery simpleQuery =
         coverageAtom.getFirstCoveringAtom().getTgd().getSimpleSourceView();
     List<VariableCorrespondence> matchingCorrespondencesForConjunction =
         coverageAtom.getMatchingCorrespondences();
     List<VariableCorrespondence> targetCorrespondencesForConjunction =
         getTargetCorrespondences(coverageAtom);
     if (containsSameAliases(complexQuery, simpleQuery)) {
       QueryRenaming queryRenaming =
           aliasRenamer.renameAliasesInSimpleConjunctiveQuery(simpleQuery);
       simpleQuery = (SimpleConjunctiveQuery) queryRenaming.getRenamedView();
       targetCorrespondencesForConjunction =
           renamerUtility.renameSourceSetAliasesInCorrespondences(
               targetCorrespondencesForConjunction, queryRenaming.getRenamings());
       matchingCorrespondencesForConjunction =
           renamerUtility.renameSourceSetAliasesInCorrespondences(
               matchingCorrespondencesForConjunction, queryRenaming.getRenamings());
     }
     complexQuery.addConjunction(simpleQuery);
     complexQuery.addCorrespondencesForConjuntion(targetCorrespondencesForConjunction);
     matchingCorrespondences.addAll(matchingCorrespondencesForConjunction);
   }
   complexQuery.setJoinConditions(coverage.getTargetJoinConditions());
   complexQuery.setCyclicJoinConditions(coverage.getTargetCyclicJoinConditions());
   ComplexQueryWithNegations coverageView = new ComplexQueryWithNegations(complexQuery);
   coverageView.setProvenance(coverage.toShortString());
   TargetEqualities equalities =
       new TargetEqualities(getOriginalCorrespondences(coverage), matchingCorrespondences);
   NegatedComplexQuery negatedQuery = new NegatedComplexQuery(coverageView, equalities);
   if (logger.isDebugEnabled()) logger.debug("************ Final result:\n" + negatedQuery);
   return negatedQuery;
 }
Пример #5
0
 public void visitNegatedComplexQuery(NegatedComplexQuery negatedQuery) {
   stack.add(0, negatedQuery);
   List<FormulaVariable> existentialVariables =
       variableFinder.getExistentialVariables(variableMaps, stack);
   variables.add(0, existentialVariables);
   result
       .append("\n")
       .append(generateIndent())
       .append(utility.SECONDARY_INDENT)
       .append("and not ");
   if (useSaveFormat) {
     result.append("exists ");
   } else {
     if (!existentialVariables.isEmpty()) {
       result.append("exist ");
       result.append(utility.printVariables(existentialVariables));
     }
   }
   ComplexQueryWithNegations childQuery = negatedQuery.getComplexQuery();
   result.append(" (");
   if (!useSaveFormat) {
     result
         .append("//")
         .append(negatedQuery.getProvenance())
         .append(" - ")
         .append(childQuery.getId());
   }
   result.append("\n");
   childQuery.accept(this);
   List<Expression> equalities = variableFinder.getEqualities(variableMaps, stack);
   if (!equalities.isEmpty()) {
     result.append(generateEqualityString(equalities, variables, true));
   }
   result.append("\n").append(generateIndent()).append(utility.SECONDARY_INDENT).append(")");
   variables.remove(0);
   stack.remove(0);
 }
Пример #6
0
 public static String sqlNameForPositiveView(ComplexQueryWithNegations query) {
   return WORK_SCHEMA_NAME + "." + POSITIVE_QUERY + query.getId();
 }
Пример #7
0
 public static String sqlNameForViewWithIntersection(ComplexQueryWithNegations query) {
   return WORK_SCHEMA_NAME + "." + query.getId();
 }