@Override public ImmutableSet<Attribute> getDependents() { return getRelation().getAttributes().stream() .filter(a -> !attributes.contains(a)) .collect(ImmutableCollectors.toSet()); }
@Override public ImmutableSet<Attribute> getDependents() { return getRelation().getAttributes().stream() .filter(a -> !attributes.contains(a)) .collect(ImmutableCollectors.toSet()); }
/** * TODO: explain * * @throws AtomUnificationException */ private ImmutableList<ImmutableSubstitution<VariableOrGroundTerm>> extractDependentUnifiers( DatabaseRelationDefinition databaseRelation, ImmutableMap<FunctionalDependency, ImmutableCollection<Collection<DataNode>>> constraintNodeMap, ImmutableSet<DataNode> nodesToRemove) throws AtomUnificationException { ImmutableSet<Integer> nullableIndexes = databaseRelation.getAttributes().stream() .filter(Attribute::canNull) .map(a -> a.getIndex() - 1) .collect(ImmutableCollectors.toSet()); ImmutableList.Builder<ImmutableSubstitution<VariableOrGroundTerm>> dependentUnifierBuilder = ImmutableList.builder(); for (Map.Entry<FunctionalDependency, ImmutableCollection<Collection<DataNode>>> constraintEntry : constraintNodeMap.entrySet()) { dependentUnifierBuilder.addAll(extractDependentUnifiers(constraintEntry.getKey(), constraintEntry.getValue(), nodesToRemove, nullableIndexes)); } return dependentUnifierBuilder.build(); }
private static List<Attribute> getIdentifyingAttributes(DatabaseRelationDefinition table) { UniqueConstraint pk = table.getPrimaryKey(); if (pk != null) return pk.getAttributes(); else return table.getAttributes(); }
private static List<Attribute> getIdentifyingAttributes(DatabaseRelationDefinition table) { UniqueConstraint pk = table.getPrimaryKey(); if (pk != null) return pk.getAttributes(); else return table.getAttributes(); }
private LinearInclusionDependency getLinearInclusionDependency(ForeignKeyConstraint fk) { DatabaseRelationDefinition def = fk.getRelation(); DatabaseRelationDefinition def2 = fk.getReferencedRelation(); // create variables for the current table int len1 = def.getAttributes().size(); List<Term> terms1 = new ArrayList<>(len1); for (int i = 1; i <= len1; i++) terms1.add(termFactory.getVariable("t" + i)); // create variables for the referenced table int len2 = def2.getAttributes().size(); List<Term> terms2 = new ArrayList<>(len2); for (int i = 1; i <= len2; i++) terms2.add(termFactory.getVariable("p" + i)); for (ForeignKeyConstraint.Component comp : fk.getComponents()) { // indexes start at 1 int pos1 = comp.getAttribute().getIndex() - 1; // current column (1) int pos2 = comp.getReference().getIndex() - 1; // referenced column (2) terms1.set(pos1, terms2.get(pos2)); } Function head = termFactory.getFunction(def2.getAtomPredicate(), terms2); Function body = termFactory.getFunction(def.getAtomPredicate(), terms1); return new LinearInclusionDependency(head, body); }
int len1 = def.getAttributes().size(); List<Term> terms1 = new ArrayList<>(len1); for (int i = 1; i <= len1; i++) int len2 = def2.getAttributes().size(); List<Term> terms2 = new ArrayList<>(len2); for (int i = 1; i <= len2; i++)
List<ImmutableTerm> vars = new ArrayList<>(td.getAttributes().size()); for (Attribute att : td.getAttributes()) vars.add(termFactory.getVariable(varNamePrefix + att.getID().getName()));
List<ImmutableTerm> vars = new ArrayList<>(td.getAttributes().size()); for (Attribute att : td.getAttributes()) vars.add(df.getVariable(varNamePrefix + att.getID().getName()));
/** * Definition row graph: an RDF graph consisting of the following triples: * <p/> * - the row type triple. * - a literal triple for each column in a table where the column value is non-NULL. * */ public ImmutableList<TargetAtom> getCQ(DatabaseRelationDefinition table) { ImmutableList.Builder<TargetAtom> atoms = ImmutableList.builder(); //Class Atom ImmutableTerm sub = generateSubject(table, false); atoms.add(getAtom(getTableIRI(table.getID()), sub)); //DataType Atoms for (Attribute att : table.getAttributes()) { // TODO: revisit this RDFDatatype type = (RDFDatatype) att.getTermType(); Variable objV = termFactory.getVariable(att.getID().getName()); ImmutableTerm obj = termFactory.getImmutableTypedTerm(objV, type); atoms.add(getAtom(getLiteralPropertyIRI(att), sub, obj)); } return atoms.build(); }
: relation.getID(); List<Term> terms = new ArrayList<>(relation.getAttributes().size()); ImmutableMap.Builder attributes = ImmutableMap.<QuotedID, Variable>builder(); relation.getAttributes().forEach(attribute -> { QuotedID attributeId = attribute.getID(); Variable var = TERM_FACTORY.getVariable(attributeId.getName() + relationIndex);
: relation.getID(); List<Term> terms = new ArrayList<>(relation.getAttributes().size()); ImmutableMap.Builder attributes = ImmutableMap.<QuotedID, Variable>builder(); relation.getAttributes().forEach(attribute -> { QuotedID attributeId = attribute.getID(); Variable var = termFactory.getVariable(attributeId.getName() + relationIndex);
/** * Definition row graph: an RDF graph consisting of the following triples: * <p/> * - the row type triple. * - a literal triple for each column in a table where the column value is non-NULL. * */ public ImmutableList<ImmutableFunctionalTerm> getCQ(DatabaseRelationDefinition table) { ImmutableList.Builder<ImmutableFunctionalTerm> atoms = ImmutableList.builder(); //Class Atom ImmutableTerm sub = generateSubject(table, false); atoms.add(df.getImmutableFunctionalTerm(df.getClassPredicate(getTableIRI(table.getID())), sub)); //DataType Atoms for (Attribute att : table.getAttributes()) { Predicate.COL_TYPE type = typeMapper.getPredicate(att.getType()); Variable objV = df.getVariable(att.getID().getName()); ImmutableTerm obj = df.getImmutableTypedTerm(objV, type); atoms.add(df.getImmutableFunctionalTerm(df.getDataPropertyPredicate(getLiteralPropertyIRI(att)), sub, obj)); } return atoms.build(); }
for (DatabaseRelationDefinition tabledef : tables) { if (tabledef.getID().getTableName().equals(table)) { List<Attribute> attr = tabledef.getAttributes(); for (Attribute a : attr) { if (a.getID().equals(colId)) {
@Override public void visit(Table tableName) { RelationID id = idfac.createRelationID(tableName.getSchemaName(), tableName.getName()); // construct the predicate using the table name DatabaseRelationDefinition relation = metadata.getDatabaseRelation(id); if (relation == null) throw new InvalidSelectQueryRuntimeException("Table " + id + " not found in metadata", tableName); relationIndex++; RelationID alias = (tableName.getAlias() != null) ? idfac.createRelationID(null, tableName.getAlias().getName()) : relation.getID(); ImmutableMap<QuotedID, Term> attributes = relation.getAttributes().stream() .collect(ImmutableCollectors.toMap(Attribute::getID, attribute -> createVariable(attribute.getID()))); // DEFAULT SCHEMA // TODO: to be improved if ((tableName.getAlias() == null) && relation.getID().getSchemaName() != null && metadata.getDatabaseRelation(relation.getID().getSchemalessID()).equals(relation)) result = RAExpressionAttributes.create(attributes, alias, relation.getID().getSchemalessID()); else result = RAExpressionAttributes.create(attributes, alias); }
@Override public void visit(Table tableName) { RelationID id = idfac.createRelationID(tableName.getSchemaName(), tableName.getName()); // construct the predicate using the table name DatabaseRelationDefinition relation = metadata.getDatabaseRelation(id); if (relation == null) throw new InvalidSelectQueryRuntimeException("Table " + id + " not found in metadata", tableName); relationIndex++; RelationID alias = (tableName.getAlias() != null) ? idfac.createRelationID(null, tableName.getAlias().getName()) : relation.getID(); ImmutableMap<QuotedID, Term> attributes = relation.getAttributes().stream() .collect(ImmutableCollectors.toMap(Attribute::getID, attribute -> createVariable(attribute.getID()))); // DEFAULT SCHEMA // TODO: to be improved if ((tableName.getAlias() == null) && relation.getID().getSchemaName() != null && metadata.getDatabaseRelation(relation.getID().getSchemalessID()).equals(relation)) result = RAExpressionAttributes.create(attributes, alias, relation.getID().getSchemalessID()); else result = RAExpressionAttributes.create(attributes, alias); }