Ejemplo n.º 1
0
 public static List<AttributeRef> findTargetQueriedAttributesForExtTGD(Dependency dependency) {
   List<AttributeRef> queriedAttributes = new ArrayList<AttributeRef>();
   LunaticUtility.addAllIfNotContained(
       queriedAttributes, findTargetQueriedAttributesInPremise(dependency));
   for (FormulaVariable formulaVariable : dependency.getPremise().getLocalVariables()) {
     if (formulaVariable.getConclusionRelationalOccurrences().isEmpty()) {
       continue;
     }
     AttributeRef firstPremiseOccurrenceInTarget =
         getFirstPremiseOccurrenceInTarget(formulaVariable.getPremiseRelationalOccurrences());
     if (firstPremiseOccurrenceInTarget != null) {
       AttributeRef unaliasedPremiseAttribute =
           ChaseUtility.unAlias(firstPremiseOccurrenceInTarget);
       LunaticUtility.addIfNotContained(queriedAttributes, unaliasedPremiseAttribute);
     }
     for (FormulaVariableOccurrence conclusionOccurrence :
         formulaVariable.getConclusionRelationalOccurrences()) {
       AttributeRef attribute = conclusionOccurrence.getAttributeRef();
       if (attribute.getTableAlias().isSource()) {
         continue;
       }
       AttributeRef unaliasedConclusionAttribute =
           ChaseUtility.unAlias(conclusionOccurrence.getAttributeRef());
       LunaticUtility.addIfNotContained(queriedAttributes, unaliasedConclusionAttribute);
     }
   }
   return queriedAttributes;
 }
 private void addTuple(
     Tuple tuple,
     EquivalenceClassForSymmetricEGD equivalenceClass,
     CostManagerConfiguration costManagerConfiguration,
     IDatabase deltaDB,
     String stepId,
     Scenario scenario) {
   if (logger.isDebugEnabled())
     logger.trace("Adding tuple " + tuple + " to equivalence class: " + equivalenceClass);
   AttributeRef conclusionAttribute = equivalenceClass.getConclusionAttribute();
   Cell cellToChangeForForwardChasing = tuple.getCell(conclusionAttribute);
   if (logger.isDebugEnabled())
     logger.trace(
         "Attribute: " + conclusionAttribute + " - Cell: " + cellToChangeForForwardChasing);
   IValue conclusionValue = cellToChangeForForwardChasing.getValue();
   TupleOID originalOid = new TupleOID(ChaseUtility.getOriginalOid(tuple, conclusionAttribute));
   CellRef cellRef = new CellRef(originalOid, ChaseUtility.unAlias(conclusionAttribute));
   CellGroupCell targetCell =
       new CellGroupCell(cellRef, conclusionValue, null, LunaticConstants.TYPE_OCCURRENCE, null);
   CellGroup forwardCellGroup = new CellGroup(conclusionValue, true);
   forwardCellGroup.addOccurrenceCell(targetCell);
   addAdditionalAttributes(forwardCellGroup, originalOid, tuple, equivalenceClass.getEGD());
   CellGroup enrichedCellGroup =
       this.occurrenceHandler.enrichCellGroups(forwardCellGroup, deltaDB, stepId, scenario);
   EGDEquivalenceClassTuple tupleCells = new EGDEquivalenceClassTuple(enrichedCellGroup);
   for (BackwardAttribute backwardAttribute :
       equivalenceClass.getAttributesToChangeForBackwardChasing()) {
     AttributeRef attributeForBackwardChasing = backwardAttribute.getAttributeRef();
     Cell cellForBackward = tuple.getCell(attributeForBackwardChasing);
     TupleOID tupleOid =
         new TupleOID(ChaseUtility.getOriginalOid(tuple, attributeForBackwardChasing));
     Cell backwardCell =
         new Cell(
             tupleOid,
             ChaseUtility.unAlias(attributeForBackwardChasing),
             cellForBackward.getValue());
     IValue value = backwardCell.getValue();
     CellGroup backwardCellGroup = new CellGroup(value, true);
     backwardCellGroup.addOccurrenceCell(
         new CellGroupCell(backwardCell, null, LunaticConstants.TYPE_OCCURRENCE, null));
     CellGroup enrichedBackwardCellGroup =
         this.occurrenceHandler.enrichCellGroups(backwardCellGroup, deltaDB, stepId, scenario);
     tupleCells.setCellGroupForBackwardAttribute(backwardAttribute, enrichedBackwardCellGroup);
   }
   equivalenceClass.addTupleCells(tupleCells);
   equivalenceClass.addTupleCellsForValue(conclusionValue, tupleCells);
   if (costManagerConfiguration.isDoBackwardOnDependency(equivalenceClass.getEGD())) {
     indexCells(tupleCells, equivalenceClass);
   }
   if (logger.isDebugEnabled()) logger.trace("Equivalence class: " + equivalenceClass);
 }
 private void addAdditionalAttributes(
     CellGroup cellGroup, TupleOID originalOIDForConclusionValue, Tuple tuple, Dependency egd) {
   for (AttributeRef additionalAttribute : egd.getAdditionalAttributes()) {
     for (Cell additionalCell : tuple.getCells()) {
       AttributeRef unaliasedAttribute = ChaseUtility.unAlias(additionalCell.getAttributeRef());
       if (!unaliasedAttribute.equals(additionalAttribute)) {
         continue;
       }
       TupleOID originalOIDForCell =
           new TupleOID(ChaseUtility.getOriginalOid(tuple, additionalCell.getAttributeRef()));
       if (!originalOIDForCell.equals(originalOIDForConclusionValue)) {
         continue;
       }
       CellGroupCell additionalCellGroupCell =
           new CellGroupCell(
               originalOIDForCell,
               unaliasedAttribute,
               additionalCell.getValue(),
               null,
               LunaticConstants.TYPE_ADDITIONAL,
               null);
       cellGroup.addAdditionalCell(additionalAttribute, additionalCellGroupCell);
     }
   }
 }
Ejemplo n.º 4
0
 public static List<AttributeRef> findTargetQueriedAttributesInPremise(Dependency dependency) {
   if (logger.isTraceEnabled())
     logger.trace("Searching query attributes for dependency: \n" + dependency);
   List<AttributeRef> queriedAttributes = new ArrayList<AttributeRef>();
   for (FormulaVariable variable : dependency.getPremise().getLocalVariables()) {
     if (logger.isTraceEnabled()) logger.trace("Inspecting variable: " + variable);
     if (hasSingleOccurrenceInPremise(variable)) {
       continue;
     }
     for (FormulaVariableOccurrence occurrence : variable.getPremiseRelationalOccurrences()) {
       if (logger.isTraceEnabled()) logger.trace("Inspecting occurrence: " + occurrence);
       AttributeRef attribute = occurrence.getAttributeRef();
       if (attribute.getTableAlias().isSource()) {
         continue;
       }
       AttributeRef unaliasedAttribute = ChaseUtility.unAlias(attribute);
       LunaticUtility.addIfNotContained(queriedAttributes, unaliasedAttribute);
     }
   }
   if (logger.isTraceEnabled()) logger.trace("Result: " + queriedAttributes);
   return queriedAttributes;
 }
Ejemplo n.º 5
0
 public static List<AttributeRef> extractRequestedAttributesWithExistential(
     Dependency dependency) {
   List<AttributeRef> result = new ArrayList<AttributeRef>();
   result.addAll(dependency.getQueriedAttributes());
   for (FormulaVariable variable : dependency.getConclusion().getLocalVariables()) {
     if (variable.getConclusionRelationalOccurrences().size() == 1) {
       continue;
     }
     for (FormulaVariableOccurrence occurrence : variable.getConclusionRelationalOccurrences()) {
       if (logger.isTraceEnabled()) logger.trace("Inspecting occurrence: " + occurrence);
       AttributeRef attribute = occurrence.getAttributeRef();
       AttributeRef unaliasedAttribute = ChaseUtility.unAlias(attribute);
       LunaticUtility.addIfNotContained(result, unaliasedAttribute);
     }
   }
   for (AttributeRef attributeRef : dependency.getAdditionalAttributes()) {
     if (!result.contains(attributeRef)) {
       result.add(attributeRef);
     }
   }
   return result;
 }