private String generateId(VariableFunctionalDependency dependency) {
   StringBuilder result = new StringBuilder();
   for (VariablePathExpression leftPath : dependency.getLeftPaths()) {
     result.append(leftPath.getAbsolutePath());
   }
   result.append(" => ");
   for (VariablePathExpression rightPath : dependency.getRightPaths()) {
     result.append(rightPath.getAbsolutePath());
   }
   return "" + compactHashCode(result.toString().hashCode());
 }
 private ISkolemPart generatePartForPaths(List<VariablePathExpression> paths) {
   ISkolemPart append = new AppendSkolemPart(false, "", "", "-", "-");
   List<String> pathStrings = new ArrayList<String>();
   for (VariablePathExpression path : paths) {
     pathStrings.add(SpicyEngineUtility.removeRootLabel(path.getAbsolutePath()).toString());
   }
   Collections.sort(pathStrings);
   for (String pathString : pathStrings) {
     append.addChild(new StringSkolemPart(pathString));
   }
   return append;
 }
Esempio n. 3
0
 public static String generateCasting(
     VariablePathExpression attributePath, String columnName, MappingTask mappingTask) {
   INode attributeNode =
       new FindNode()
           .findNodeInSchema(attributePath.getAbsolutePath(), mappingTask.getTargetProxy());
   String value = attributeNode.getChild(0).getLabel();
   String castedColumnName = mappingTask.getDBMSHandler().forceCast(columnName, value);
   return castedColumnName;
 }
 private ISkolemPart generateAppendsForSubGenerator(
     SkolemFunctionGenerator generator, MappingTask mappingTask) {
   ISkolemPart append =
       new AppendSkolemPart(mappingTask.getConfig().useSortInSkolems(), "(", ")", ", ");
   for (GeneratorWithPath subGeneratorWithPath : generator.getSubGenerators()) {
     VariablePathExpression subGeneratorPath = subGeneratorWithPath.getTargetPath();
     IValueGenerator subGenerator = subGeneratorWithPath.getGenerator();
     ISkolemPart appendForGenerator = new AppendSkolemPart(false, "", "", ": ");
     StringSkolemPart stringPart =
         new StringSkolemPart(
             SpicyEngineUtility.removeRootLabel(subGeneratorPath.getAbsolutePath()));
     SubGeneratorSkolemPart generatorPart = new SubGeneratorSkolemPart(subGenerator);
     appendForGenerator.addChild(stringPart);
     appendForGenerator.addChild(generatorPart);
     append.addChild(appendForGenerator);
   }
   return append;
 }
Esempio n. 5
0
 private static String sqlString(Expression expression) {
   String result = "";
   List<VariablePathExpression> attributePaths = expression.getAttributePaths();
   if (expression.toString().startsWith("isNull(")) {
     String attributeName = extractAttributeNameFromExpression(attributePaths.get(0));
     return attributeName + " IS NULL";
   }
   if (expression.toString().startsWith("isNotNull(")) {
     String attributeName = extractAttributeNameFromExpression(attributePaths.get(0));
     return attributeName + " IS NOT NULL";
   }
   for (VariablePathExpression attributePath : attributePaths) {
     String attributeName = extractAttributeNameFromExpression(attributePaths.get(0));
     result = expression.toString().replaceAll(attributePath.toString(), attributeName);
   }
   result = result.replaceAll("==", "=");
   result = result.replaceAll("\"", "\'");
   return result.replaceAll("&&", "AND");
 }
Esempio n. 6
0
 private String findGeneratorForPath(
     VariablePathExpression setPath, FORule rule, MappingTask mappingTask) {
   List<FormulaVariable> universalVariables = rule.getUniversalFormulaVariables(mappingTask);
   TGDGeneratorsMap generatorsMap = rule.getGenerators(mappingTask);
   IValueGenerator generator = generatorsMap.getGeneratorForSetPath(setPath);
   if (generator == null) {
     return "SK_" + setPath.toString() + "()";
   }
   if (generator instanceof NullValueGenerator) {
     return NullValueGenerator.getInstance().toString();
   }
   SkolemFunctionGenerator skolemGenerator = (SkolemFunctionGenerator) generator;
   return skolemGenerator.toStringWithVariableArguments(universalVariables);
 }
Esempio n. 7
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();
 }
  public String convertToPostgres(Expression transformationFunctionExpression, boolean withRel) {

    String functionExpression =
        transformationFunctionExpression.getJepExpression().toStringForSql();
    // first fix attribute names
    for (VariablePathExpression vpe : transformationFunctionExpression.getAttributePaths()) {
      if (functionExpression.contains(vpe.toString())) {
        String expressionToCheckForSigns =
            transformationFunctionExpression.getJepExpression().toString();
        int startIndex = expressionToCheckForSigns.indexOf(vpe.toString());
        int endIndex = startIndex + vpe.toString().length();
        boolean castToFloat = false;
        // check so that the String index will not get out of bounds
        if (startIndex - 2 >= 0) {
          if (math_sign.contains(expressionToCheckForSigns.charAt(startIndex - 2))) {
            castToFloat = true;
          }
          // to catch the '>=' or '<=' case
          else if (expressionToCheckForSigns.charAt(startIndex - 2) == '=' && startIndex - 3 >= 0) {
            if (expressionToCheckForSigns.charAt(startIndex - 3) == '<'
                || expressionToCheckForSigns.charAt(startIndex - 3) == '>') {
              castToFloat = true;
            }
          }
        }
        if (endIndex + 2 <= expressionToCheckForSigns.length()) {
          if (math_sign.contains(expressionToCheckForSigns.charAt(endIndex + 1))) {
            castToFloat = true;
          }
        }
        String newAttrName;
        // replace them with the corresponding attribute name
        if (withRel) {
          newAttrName = GenerateSQL.attributeNameWithVariable(vpe);
        } else {
          newAttrName = GenerateSQL.attributeNameInVariable(vpe);
        }
        // if previous or next character is one of {+,-,*,/,<,>} cast it to float
        if (castToFloat) {
          functionExpression =
              functionExpression.replaceAll(vpe.toString(), "cast(" + newAttrName + " as float)");
        } else {
          functionExpression = functionExpression.replaceAll(vpe.toString(), newAttrName);
        }
      }
    }
    return replaceExpression(functionExpression);
  }
Esempio n. 9
0
 private static String extractAttributeNameFromExpression(VariablePathExpression attributePath) {
   String variableName = attributePath.getStartingVariable().toShortString();
   String lastStep = attributePath.getLastStep();
   return GenerateSQL.RELATION_ALIAS_PREFIX + variableName + "." + lastStep;
 }
Esempio n. 10
0
 public static String attributeNameWithVariable(VariablePathExpression attributePath) {
   return RELATION_ALIAS_PREFIX
       + attributePath.getStartingVariable().toShortString()
       + "."
       + attributePath.getLastStep();
 }
Esempio n. 11
0
 public static String attributeNameInVariable(VariablePathExpression attributePath) {
   return attributePath.getStartingVariable().toShortString() + attributePath.getLastStep();
 }
Esempio n. 12
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();
  }