示例#1
0
 private boolean containsUpToClone(List<SetAlias> variables, SetAlias targetVariable) {
   for (SetAlias variable : variables) {
     if (variable.equalsOrIsClone(targetVariable)) {
       return true;
     }
   }
   return false;
 }
示例#2
0
 private SetAlias findVariable(SetAlias joinVariable, SimpleConjunctiveQuery view) {
   for (SetAlias viewVariable : view.getVariables()) {
     if (viewVariable.getGenerators().contains(joinVariable)) {
       return viewVariable;
     }
   }
   throw new IllegalArgumentException(
       "Unable to find variable " + joinVariable + " in view " + view);
 }
示例#3
0
 public static String targetRelationName(
     SetAlias variable, MappingTask mappingTask, int chainingStep) {
   SetNode bindingNode =
       variable.getBindingNode(mappingTask.getTargetProxy().getIntermediateSchema());
   String result = variable.getBindingPathExpression().getLastStep();
   if (bindingNode instanceof SetCloneNode) {
     result = ((SetCloneNode) bindingNode).getOriginalNodePath().getLastStep();
   }
   return getTargetSchemaName(chainingStep) + "." + result;
 }
示例#4
0
 ///////////////////////////    SKOLEMS   ///////////////////////////////
 private String printSkolems(FORule rule, MappingTask mappingTask) {
   StringBuilder result = new StringBuilder();
   List<FormulaVariable> existentialVariables = rule.getExistentialFormulaVariables(mappingTask);
   for (FormulaVariable variable : existentialVariables) {
     String generatorString = findGeneratorForVariable(variable, rule, mappingTask);
     result.append(variable.toShortString()).append(": ").append(generatorString).append("\n");
   }
   if (mappingTask.getTargetProxy().isNested()) {
     for (SetAlias alias : rule.getTargetView().getGenerators()) {
       VariablePathExpression bindingPath = alias.getBindingPathExpression();
       String generatorString = findGeneratorForPath(bindingPath, rule, mappingTask);
       result.append(alias.toShortString()).append(": ").append(generatorString).append("\n");
     }
   }
   return result.toString();
 }
示例#5
0
 ////////////////    JOIN GRAPH VISIT    ////////////////////
 private boolean visitGraph(
     VariableJoinCondition newJoinCondition, JoinGraph joinGraph, SimpleConjunctiveQuery view) {
   SetAlias fromVariable = findVariable(newJoinCondition.getFromVariable(), view);
   SetAlias toVariable = findVariable(newJoinCondition.getToVariable(), view);
   if (fromVariable.equals(toVariable)) {
     return true;
   }
   if (logger.isDebugEnabled())
     logger.debug(
         "Starting join graph visit to find path between: " + fromVariable + " and " + toVariable);
   if (searchPathBetweenVariables(fromVariable, toVariable, joinGraph)
       || searchPathBetweenVariables(toVariable, fromVariable, joinGraph)) {
     return true;
   }
   return false;
 }
示例#6
0
 //    private static List<SetAlias> extractDifferentVariables(List<SetAlias> variables) {
 //        List<SetAlias> result = new ArrayList<SetAlias>();
 //        for (SetAlias variable : variables) {
 //            if (!containsVariableWithSameName(variable, result)) {
 //                result.add(variable);
 //            }
 //        }
 //        return result;
 //    }
 //    private static boolean containsVariableWithSameName(SetAlias variable, List<SetAlias>
 // variables) {
 //        for (SetAlias setAlias : variables) {
 //            if (setAlias.hasSameId(variable)) {
 //                return true;
 //            }
 //        }
 //        return false;
 //    }
 private static String generateProjectionOnAllAttributes(
     List<SetAlias> variables, MappingTask mappingTask) {
   StringBuilder result = new StringBuilder();
   for (int i = 0; i < variables.size(); i++) {
     SetAlias variable = variables.get(i);
     List<VariablePathExpression> attributes =
         variable.getAttributes(mappingTask.getSourceProxy().getIntermediateSchema());
     for (int j = 0; j < attributes.size(); j++) {
       VariablePathExpression attribute = attributes.get(j);
       result.append(DOUBLE_INDENT).append(GenerateSQL.attributeNameWithVariable(attribute));
       result.append(" AS ").append(attributeNameInVariable(attribute));
       if (j != attributes.size() - 1) result.append(",\n");
     }
     if (i != variables.size() - 1) result.append(",\n");
   }
   result.append("\n");
   return result.toString();
 }
示例#7
0
 ////////////////////////////////////////////// (
 public static String generateFromClause(List<SetAlias> variables, int chainingStep) {
   StringBuilder result = new StringBuilder();
   result.append("from ");
   List<String> addedVariables = new ArrayList<String>();
   for (int i = 0; i < variables.size(); i++) {
     SetAlias variable = variables.get(i);
     String relationName = GenerateSQL.sourceRelationName(variable, chainingStep);
     String aliasRelationName = GenerateSQL.RELATION_ALIAS_PREFIX + variable.toShortString();
     // NOTE: we are preventing to reuse the same variable twice in the from clause
     // this might not be correct in all cases
     if (!addedVariables.contains(aliasRelationName)) {
       addedVariables.add(aliasRelationName);
       result.append(relationName).append(" AS ").append(aliasRelationName);
       //                if (i != variables.size() - 1) result.append(", ");
       result.append(", ");
     }
   }
   result.delete(result.length() - ", ".length(), result.length() - 1);
   result.append("\n");
   return result.toString();
 }
示例#8
0
 private String generateConjunctionString(
     List<SetAlias> setVariables, List<List<FormulaVariable>> variables, INode schema) {
   StringBuilder localResult = new StringBuilder();
   List<SetAlias> sortedAliases = new ArrayList<SetAlias>(setVariables);
   Collections.sort(sortedAliases);
   for (int i = 0; i < sortedAliases.size(); i++) {
     SetAlias sourceVariable = sortedAliases.get(i);
     localResult.append(generateIndent());
     if (!useSaveFormat) {
       localResult.append(
           utility.printAtomName(sourceVariable, mappingTask.getSourceProxy().isNested()));
     } else {
       localResult.append(
           utility.printAtomNameForSaveFormat(
               sourceVariable, mappingTask.getSourceProxy().isNested()));
     }
     List<VariablePathExpression> attributePaths = sourceVariable.getFirstLevelAttributes(schema);
     for (int j = 0; j < attributePaths.size(); j++) {
       VariablePathExpression attributePath = attributePaths.get(j);
       FormulaVariable attributeVariable = findVariableForPath(attributePath, variables);
       localResult.append(attributePath.getLastStep()).append(": ");
       if (useSaveFormat) {
         localResult.append("$");
       }
       localResult.append(attributeVariable.toShortString());
       if (j != attributePaths.size() - 1) {
         localResult.append(", ");
       }
     }
     localResult.append(")");
     if (i != sortedAliases.size() - 1) {
       localResult.append(", \n");
     }
   }
   return localResult.toString();
 }
示例#9
0
 private static String sourceRelationName(SetAlias variable, int chainingStep) {
   return getSourceSchemaName(chainingStep)
       + "."
       + variable.getBindingPathExpression().getLastStep();
 }
示例#10
0
 public static String finalSqlNameAfterExchange(SetAlias variable) {
   return WORK_SCHEMA_NAME
       + "."
       + "EXCHANGE_RESULT_FOR_"
       + variable.getBindingPathExpression().getLastStep();
 }
示例#11
0
  ////////////////////////////////   CONCLUSION   ////////////////////////////////////////////////
  public String conclusionString(FORule tgd, MappingTask mappingTask, String indent) {
    // giannisk
    // find target paths that have a constant value correspondence
    List<VariablePathExpression> constantTargetPaths = new ArrayList<VariablePathExpression>();
    HashMap<VariablePathExpression, ISourceValue> constantValueMap =
        new HashMap<VariablePathExpression, ISourceValue>();
    for (VariableCorrespondence varCor : tgd.getCoveredCorrespondences()) {
      if (varCor.isConstant()) {
        constantTargetPaths.add(varCor.getTargetPath());
        constantValueMap.put(varCor.getTargetPath(), varCor.getSourceValue());
      }
    }

    StringBuilder result = new StringBuilder();
    List<FormulaVariable> universalVariables = tgd.getUniversalFormulaVariables(mappingTask);
    List<FormulaVariable> existentialVariables = tgd.getExistentialFormulaVariables(mappingTask);
    if (!useSaveFormat
        && (!existentialVariables.isEmpty() || mappingTask.getTargetProxy().isNested())) {
      result.append("exist ");
      if (mappingTask.getTargetProxy().isNested()) {
        utility.printOIDVariables(tgd.getTargetView());
      }
      if (!existentialVariables.isEmpty()) {
        result.append(utility.printVariables(existentialVariables));
      }
    }
    result.append("\n");
    for (int i = 0; i < tgd.getTargetView().getGenerators().size(); i++) {
      SetAlias targetVariable = tgd.getTargetView().getGenerators().get(i);
      result.append(indent).append(utility.INDENT);
      if (!useSaveFormat) {
        result.append(
            utility.printAtomName(targetVariable, mappingTask.getTargetProxy().isNested()));
      } else {
        result.append(
            utility.printAtomNameForSaveFormat(
                targetVariable, mappingTask.getTargetProxy().isNested()));
      }
      List<VariablePathExpression> attributePaths =
          targetVariable.getFirstLevelAttributes(
              mappingTask.getTargetProxy().getIntermediateSchema());
      for (int j = 0; j < attributePaths.size(); j++) {
        VariablePathExpression attributePath = attributePaths.get(j);
        result.append(attributePath.getLastStep()).append(": ");
        FormulaVariable attributeVariable =
            findUniversalVariableForTargetPath(attributePath, universalVariables);
        Expression transformation = null;
        if (!constantTargetPaths.contains(attributePath)) {
          if (attributeVariable == null) {
            attributeVariable =
                findExistentialVariable(
                    attributePath, tgd.getExistentialFormulaVariables(mappingTask));
          }
          transformation = attributeVariable.getTransformationFunction(attributePath);
        }
        if (transformation == null) {
          if (!constantTargetPaths.contains(attributePath)) {
            if (useSaveFormat) {
              result.append("$");
            }
            result.append(attributeVariable.toShortString());
          } else { // constant
            result.append(constantValueMap.get(attributePath));
          }
        } else { // function
          List<List<FormulaVariable>> variables = new ArrayList<List<FormulaVariable>>();
          variables.add(tgd.getUniversalFormulaVariables(mappingTask));
          utility.setVariableDescriptions(transformation, variables);
          result.append(transformation);
        }
        if (j != attributePaths.size() - 1) {
          result.append(", ");
        }
      }
      result.append(")");
      if (i != tgd.getTargetView().getGenerators().size() - 1) {
        result.append(", \n");
      }
    }
    return result.toString();
  }