static List<RelationContext> computeProvenanceRelations(List<Mapping> mappings)
      throws IncompatibleTypesException, IncompatibleKeysException {

    List<RelationContext> mappingRels = new ArrayList<RelationContext>();

    for (int i = 0; i < mappings.size(); i++) {
      final Mapping mapping = mappings.get(i);

      final List<AtomVariable> allVars = mapping.getAllBodyVariables();
      final List<AtomArgument> allVarsCast = new ArrayList<AtomArgument>(allVars.size());
      for (final AtomVariable var : allVars) allVarsCast.add(var);

      if (mapping instanceof Rule) {
        mapping.setDescription("+");
      } else {
        mapping.setDescription(mapping.getId());
      }

      Relation rel = null;
      try {
        rel = CreateProvenanceStorage.computeProvenanceRelation(mapping, i);
      } catch (IncompatibleTypesException e) {
        Debug.println(
            "Creation of provenance relation for mapping:\n"
                + mapping.toString()
                + "\nfailed due to type error in the mapping");
        throw (e);
      } catch (IncompatibleKeysException ke) {
        Debug.println(
            "Creation of provenance relation for mapping:\n"
                + mapping.toString()
                + "\nfailed due to mismatch bw keys in the mapping");
        throw (ke);
      }

      Atom pickOne = mapping.getMappingHead().get(0);

      RelationContext relCtx =
          new RelationContext(rel, pickOne.getSchema(), pickOne.getPeer(), true);

      mapping.setProvenanceRelation(relCtx);
      mappingRels.add(relCtx);
    }

    return mappingRels;
  }
Ejemplo n.º 2
0
 /** @return String representation of the constant value */
 public synchronized String toString() {
   if (getValue() == null) return "-";
   else {
     // TODO remove, just to see if still used somewhere...
     if (getType() == null) {
       Debug.println("OptimizerType is null");
       return getValue().toString();
     } else return getType().getSQLLit(getValue());
   }
 }
  public List<Rule> computeTranslationRules() throws Exception {

    try {
      List<Mapping> mappings = OrchestraUtil.newArrayList(systemMappings);
      for (Mapping m : mappings) {
        m.renameExistentialVars();
      }
      List<RelationContext> relations = OrchestraUtil.newArrayList(userRelations);

      if (Config.getEdbbits()) MappingsTranslationMgt.addEdbBitsToMappings(mappings);

      state = new TranslationState(mappings, relations);

      Debug.println("Mappings: " + mappings.size());

      Calendar before = Calendar.getInstance();

      List<Rule> source2targetRules;
      List<Rule> local2peerRules = MappingsIOMgt.inOutTranslationL(builtInSchemas, relations);
      state.setLocal2PeerRules(local2peerRules);
      mappings.addAll(state.getLocal2PeerRules());

      // Make variables in each mapping different
      int i = 0;
      for (Mapping m : mappings) {
        m.renameVariables("_M" + i);
        i++;
      }
      state.setMappings(mappings);
      List<Mapping> skolMappings;
      List<RelationContext> allMappingRels;
      List<RelationContext> realMappingRels = new ArrayList<RelationContext>();

      skolMappings = MappingsInversionMgt.skolemizeMappings(mappings);
      MappingsCompositionMgt.composeMappings(skolMappings, builtInSchemas);

      allMappingRels = computeProvenanceRelations(skolMappings);

      // Need to change this - put it inside Provenance Relations
      // mappings = expandBidirectionalMappings(mappings);

      state.setMappingRels(allMappingRels);
      for (RelationContext relctx : allMappingRels) {
        ProvenanceRelation prvrel = (ProvenanceRelation) relctx.getRelation();

        if (!prvrel.getType().equals(ProvenanceRelation.ProvRelType.SINGLE)
            || !prvrel.getMappings().get(0).isFakeMapping()) {
          realMappingRels.add(relctx);
        }
      }
      state.setRealMappingRels(realMappingRels);

      List<Rule> source2provRules = new ArrayList<Rule>();
      List<Mapping> prov2targetMappings = new ArrayList<Mapping>();

      computeProvRules(source2provRules, prov2targetMappings);

      source2targetRules = MappingsInversionMgt.splitMappingsHeads(skolMappings, builtInSchemas);
      source2targetRules = MappingsIOMgt.inOutTranslationR(source2targetRules, true);

      state.setSource2TargetRules(source2targetRules);
      state.setSource2ProvRules(source2provRules);
      state.setProv2TargetMappings(prov2targetMappings);

      Calendar after = Calendar.getInstance();
      long time = after.getTimeInMillis() - before.getTimeInMillis();
      Debug.println("TOTAL RULE MANIPULATION TIME: " + time + "msec");
      return source2targetRules;
    } catch (Exception e) {
      e.printStackTrace();
      throw (e);
    }
  }