private Optional<DatabaseRelationDefinition> getDatabaseRelationByName(DBMetadata dbMetadata, AtomPredicate predicate) { RelationID relationId = Relation2Predicate.createRelationFromPredicateName(dbMetadata.getQuotedIDFactory(), predicate); return Optional.ofNullable(dbMetadata.getRelation(relationId)) /** * Here we only consider DB relations */ .filter(r -> r instanceof DatabaseRelationDefinition) .map(r -> (DatabaseRelationDefinition) r); } }
@Override protected Optional<PredicateLevelProposal> proposePerPredicate(InnerJoinNode joinNode, ImmutableCollection<DataNode> initialNodes, AtomPredicate predicate, DBMetadata dbMetadata, ImmutableList<Variable> priorityVariables, IntermediateQuery query) throws AtomUnificationException { if (initialNodes.size() < 2) return Optional.empty(); RelationID relationId = Relation2Predicate.createRelationFromPredicateName( dbMetadata.getQuotedIDFactory(), predicate); DatabaseRelationDefinition databaseRelation = dbMetadata.getDatabaseRelation(relationId); /* * Does nothing */ if (databaseRelation == null) return Optional.empty(); ImmutableMap<FunctionalDependency, ImmutableCollection<Collection<DataNode>>> constraintNodeMap = databaseRelation.getOtherFunctionalDependencies().stream() .collect(ImmutableCollectors.toMap( c -> c, c -> groupDataNodesPerConstraint(c, initialNodes))); ImmutableSet<Variable> requiredAndCooccuringVariables = extractRequiredAndCooccuringVariables(query, joinNode); ImmutableSet<DataNode> nodesToRemove = selectNodesToRemove(requiredAndCooccuringVariables, constraintNodeMap, predicate); ImmutableList<ImmutableSubstitution<VariableOrGroundTerm>> dependentUnifiers = extractDependentUnifiers( databaseRelation, constraintNodeMap, nodesToRemove); return (dependentUnifiers.isEmpty() && nodesToRemove.isEmpty()) ? Optional.empty() : Optional.of(new PredicateLevelProposal(dependentUnifiers, nodesToRemove)); }
public SelectQueryAttributeExtractor2(DBMetadata metadata, TermFactory termFactory) { this.metadata = metadata; this.idfac = metadata.getQuotedIDFactory(); this.termFactory = termFactory; }
RelationID tableId = Relation2Predicate.createRelationFromPredicateName(metadata.getQuotedIDFactory(), ip.atom .getFunctionSymbol()); RelationDefinition td = metadata.getRelation(tableId); colType = metadata.getColType(attribute);
DatabaseRelationDefinition ref = metadata.getDatabaseRelation(refId);
@Override public Mapping saturate(Mapping mapping, DBMetadata dbMetadata, ClassifiedTBox saturatedTBox) { ImmutableList<CQIE> initialMappingRules = mapping2DatalogConverter.convert(mapping) .collect(ImmutableCollectors.toList()); LinearInclusionDependencies foreignKeyRules = new LinearInclusionDependencies(dbMetadata.generateFKRules()); CQContainmentCheckUnderLIDs foreignKeyCQC = new CQContainmentCheckUnderLIDs(foreignKeyRules); ImmutableSet<CQIE> saturatedMappingRules = TMappingProcessor.getTMappings(initialMappingRules, saturatedTBox, foreignKeyCQC, tMappingExclusionConfig).stream() .collect(ImmutableCollectors.toSet()); List<CQIE> allMappingRules = new ArrayList<>(saturatedMappingRules); allMappingRules.addAll(generateTripleMappings(saturatedMappingRules)); return datalog2MappingConverter.convertMappingRules(ImmutableList.copyOf(allMappingRules), dbMetadata, mapping.getExecutorRegistry(), mapping.getMetadata()); }
QuotedIDFactory idfac = md.getQuotedIDFactory(); int counter = 0; // id of the generated constraint DatabaseRelationDefinition td = md.getDatabaseRelation(tableId);
public SelectQueryParser(DBMetadata metadata, TermFactory termFactory, TypeFactory typeFactory) { this.metadata = metadata; this.idfac = metadata.getQuotedIDFactory(); this.termFactory = termFactory; this.typeFactory = typeFactory; }
DatabaseRelationDefinition relation = metadata.getDatabaseRelation(id); if (relation == null) throw new InvalidSelectQueryRuntimeException("Table " + id + " not found in metadata", tableName); if ((tableName.getAlias() == null) && relation.getID().getSchemaName() != null && metadata.getDatabaseRelation(relation.getID().getSchemalessID()).equals(relation)) attrs = RAExpressionAttributes.create(attributes.build(), alias, relation.getID().getSchemalessID()); else
@Override public boolean isVariableNullable(IntermediateQuery query, Variable variable) { if (!getVariables().contains(variable)) throw new IllegalArgumentException("The variable " + variable + " is not projected by " + this); DBMetadata metadata = query.getDBMetadata(); DataAtom atom = getProjectionAtom(); RelationID relationId = Relation2Predicate.createRelationFromPredicateName( metadata.getQuotedIDFactory(), atom.getPredicate()); RelationDefinition relation = metadata.getRelation(relationId); if (relation == null) throw new MissingRelationForExtensionalDataNodeException("Bug: required relation for " + this + " not found"); ImmutableList<? extends VariableOrGroundTerm> arguments = atom.getArguments(); // NB: DB column indexes start at 1. return IntStream.range(1, arguments.size() + 1) .filter(i -> arguments.get(i - 1).equals(variable)) .mapToObj(relation::getAttribute) .allMatch(Attribute::canNull); }
QuotedIDFactory idfac = md.getQuotedIDFactory(); int counter = 0; // id of the generated constraint DatabaseRelationDefinition pkTable = md.getDatabaseRelation(pkTableId); if (pkTable == null) { log.warn("Error in user-supplied foreign key: table " + pkTableId + " not found."); DatabaseRelationDefinition fkTable = md.getDatabaseRelation(fkTableId); if (fkTable == null) { log.warn("Error in user-supplied foreign key: table " + fkTableId + " not found.");
public SelectQueryAttributeExtractor2(DBMetadata metadata) { this.metadata = metadata; this.idfac = metadata.getQuotedIDFactory(); }
DatabaseRelationDefinition relation = metadata.getDatabaseRelation(id); if (relation == null) throw new InvalidSelectQueryRuntimeException("Table " + id + " not found in metadata", tableName); if ((tableName.getAlias() == null) && relation.getID().getSchemaName() != null && metadata.getDatabaseRelation(relation.getID().getSchemalessID()).equals(relation)) attrs = RAExpressionAttributes.create(attributes.build(), alias, relation.getID().getSchemalessID()); else
RelationID tableId = relation2Predicate.createRelationFromPredicateName(metadata.getQuotedIDFactory(), predicate); Optional<RelationDefinition> td = Optional.ofNullable(metadata.getRelation(tableId));
QuotedIDFactory idfac = md.getQuotedIDFactory(); int counter = 0; // id of the generated constraint DatabaseRelationDefinition td = md.getDatabaseRelation(tableId);
public SelectQueryParser(DBMetadata metadata) { this.metadata = metadata; this.idfac = metadata.getQuotedIDFactory(); }
@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); }
RelationID tableId = relation2Predicate.createRelationFromPredicateName(metadata.getQuotedIDFactory(), ip.atom .getFunctionSymbol()); RelationDefinition td = metadata.getRelation(tableId);
QuotedIDFactory idfac = md.getQuotedIDFactory(); int counter = 0; // id of the generated constraint DatabaseRelationDefinition pkTable = md.getDatabaseRelation(pkTableId); if (pkTable == null) { log.warn("Error in user-supplied foreign key: table " + pkTableId + " not found."); DatabaseRelationDefinition fkTable = md.getDatabaseRelation(fkTableId); if (fkTable == null) { log.warn("Error in user-supplied foreign key: table " + fkTableId + " not found.");
public SelectQueryAttributeExtractor(DBMetadata metadata, TermFactory termFactory) { this.idfac = metadata.getQuotedIDFactory(); sqae = new SelectQueryAttributeExtractor2(metadata, termFactory); }