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 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); } } }
public static AttributeRef findFirstOccurrenceInFormula( IFormula formula, List<FormulaVariableOccurrence> occurrences) { List<TableAlias> aliasesInFormula = AlgebraUtility.findAliasesForFormula(formula.getPositiveFormula()); for (FormulaVariableOccurrence occurrence : occurrences) { AttributeRef attribute = occurrence.getAttributeRef(); if (aliasesInFormula.contains(attribute.getTableAlias())) { return attribute; } } return null; }
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; }