From a157c411e26a44563882281efb6bdd001db29e19 Mon Sep 17 00:00:00 2001 From: Benjamin Cogrel Date: Mon, 8 Feb 2021 15:45:15 +0100 Subject: [PATCH 1/9] DBFunctionSymbolFactory.getDBNullIf() added. --- .../term/functionsymbol/db/DBFunctionSymbolFactory.java | 2 ++ .../db/impl/MockupDBFunctionSymbolFactory.java | 5 +++++ .../db/impl/AbstractSQLDBFunctionSymbolFactory.java | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/core/model/src/main/java/it/unibz/inf/ontop/model/term/functionsymbol/db/DBFunctionSymbolFactory.java b/core/model/src/main/java/it/unibz/inf/ontop/model/term/functionsymbol/db/DBFunctionSymbolFactory.java index da375a6f3c4..d96c05eb1e5 100644 --- a/core/model/src/main/java/it/unibz/inf/ontop/model/term/functionsymbol/db/DBFunctionSymbolFactory.java +++ b/core/model/src/main/java/it/unibz/inf/ontop/model/term/functionsymbol/db/DBFunctionSymbolFactory.java @@ -94,6 +94,8 @@ public interface DBFunctionSymbolFactory { DBFunctionSymbol getDBIfThenElse(); + DBFunctionSymbol getDBNullIf(); + DBFunctionSymbol getDBUpper(); DBFunctionSymbol getDBLower(); diff --git a/core/model/src/main/java/it/unibz/inf/ontop/model/term/functionsymbol/db/impl/MockupDBFunctionSymbolFactory.java b/core/model/src/main/java/it/unibz/inf/ontop/model/term/functionsymbol/db/impl/MockupDBFunctionSymbolFactory.java index 80d7d510b63..20f4724e4cf 100644 --- a/core/model/src/main/java/it/unibz/inf/ontop/model/term/functionsymbol/db/impl/MockupDBFunctionSymbolFactory.java +++ b/core/model/src/main/java/it/unibz/inf/ontop/model/term/functionsymbol/db/impl/MockupDBFunctionSymbolFactory.java @@ -367,6 +367,11 @@ public DBFunctionSymbol getDBIfThenElse() { return new MockupDBIfElseNullFunctionSymbol(dbBooleanType, abstractRootDBType); } + @Override + public DBFunctionSymbol getDBNullIf() { + throw new UnsupportedOperationException("Operation not supported by the MockupDBFunctionSymbolFactory"); + } + @Override public DBFunctionSymbol getDBUpper() { return getRegularDBFunctionSymbol("UPPER", 1); diff --git a/db/rdb/src/main/java/it/unibz/inf/ontop/model/term/functionsymbol/db/impl/AbstractSQLDBFunctionSymbolFactory.java b/db/rdb/src/main/java/it/unibz/inf/ontop/model/term/functionsymbol/db/impl/AbstractSQLDBFunctionSymbolFactory.java index 0eec0c7345b..ee9f1ccad87 100644 --- a/db/rdb/src/main/java/it/unibz/inf/ontop/model/term/functionsymbol/db/impl/AbstractSQLDBFunctionSymbolFactory.java +++ b/db/rdb/src/main/java/it/unibz/inf/ontop/model/term/functionsymbol/db/impl/AbstractSQLDBFunctionSymbolFactory.java @@ -818,6 +818,11 @@ public DBFunctionSymbol getDBIfThenElse() { return ifThenElse; } + @Override + public DBFunctionSymbol getDBNullIf() { + return getRegularDBFunctionSymbol(NULLIF_STR, 2); + } + @Override public DBFunctionSymbol getDBUpper() { return getRegularDBFunctionSymbol(UPPER_STR, 1); From 558f362074ceabfeb4284b91834eb72e5d2d6bf6 Mon Sep 17 00:00:00 2001 From: Benjamin Cogrel Date: Mon, 8 Feb 2021 16:25:01 +0100 Subject: [PATCH 2/9] Allows preventing post-processing for var and constant definitions. --- .../iq/tools/impl/ProjectionDecomposerImpl.java | 15 +++++++++++++++ .../unibz/inf/ontop/utils/CoreUtilsFactory.java | 3 ++- .../PostProcessingProjectionSplitterImpl.java | 5 +++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/core/model/src/main/java/it/unibz/inf/ontop/iq/tools/impl/ProjectionDecomposerImpl.java b/core/model/src/main/java/it/unibz/inf/ontop/iq/tools/impl/ProjectionDecomposerImpl.java index 479cdc20f8e..09c224757d4 100644 --- a/core/model/src/main/java/it/unibz/inf/ontop/iq/tools/impl/ProjectionDecomposerImpl.java +++ b/core/model/src/main/java/it/unibz/inf/ontop/iq/tools/impl/ProjectionDecomposerImpl.java @@ -19,13 +19,16 @@ public class ProjectionDecomposerImpl implements ProjectionDecomposer { private final Predicate decompositionOracle; + private final boolean postprocessVariableAndConstantDefinitions; private final SubstitutionFactory substitutionFactory; private final TermFactory termFactory; @AssistedInject private ProjectionDecomposerImpl(@Assisted Predicate decompositionOracle, + @Assisted Boolean postprocessVariableAndConstantDefinitions, SubstitutionFactory substitutionFactory, TermFactory termFactory) { this.decompositionOracle = decompositionOracle; + this.postprocessVariableAndConstantDefinitions = postprocessVariableAndConstantDefinitions; this.substitutionFactory = substitutionFactory; this.termFactory = termFactory; } @@ -101,6 +104,18 @@ private DefinitionDecomposition decomposeDefinition(ImmutableTerm term, Variable substitutionFactory.getSubstitution(variable, functionalTerm)); } } + /* + * When the definition of the substitution (not a sub-term of a functional term) is a constant or a variable, + * we may decide not to post-process it. + * + * Useful for using Ontop for generating SQL queries with no post-processing + * (for other purposes than SPARQL query answering) + * + */ + else if (definedVariable.isPresent() && (!postprocessVariableAndConstantDefinitions)) { + Variable variable = definedVariable.get(); + return new DefinitionDecomposition(variable, substitutionFactory.getSubstitution(variable, term)); + } else return new DefinitionDecomposition(term); } diff --git a/core/model/src/main/java/it/unibz/inf/ontop/utils/CoreUtilsFactory.java b/core/model/src/main/java/it/unibz/inf/ontop/utils/CoreUtilsFactory.java index 1098c575223..d46ea46d829 100644 --- a/core/model/src/main/java/it/unibz/inf/ontop/utils/CoreUtilsFactory.java +++ b/core/model/src/main/java/it/unibz/inf/ontop/utils/CoreUtilsFactory.java @@ -33,5 +33,6 @@ VariableNullability createVariableNullability(@Assisted("nullableGroups") Immuta VariableNullability createEmptyVariableNullability(ImmutableSet scope); - ProjectionDecomposer createProjectionDecomposer(Predicate decompositionOracle); + ProjectionDecomposer createProjectionDecomposer(Predicate decompositionOracle, + Boolean postprocessVariableAndConstantDefinitions); } diff --git a/engine/reformulation/core/src/main/java/it/unibz/inf/ontop/answering/reformulation/generation/impl/PostProcessingProjectionSplitterImpl.java b/engine/reformulation/core/src/main/java/it/unibz/inf/ontop/answering/reformulation/generation/impl/PostProcessingProjectionSplitterImpl.java index bed4496fc16..53bc8dc0717 100644 --- a/engine/reformulation/core/src/main/java/it/unibz/inf/ontop/answering/reformulation/generation/impl/PostProcessingProjectionSplitterImpl.java +++ b/engine/reformulation/core/src/main/java/it/unibz/inf/ontop/answering/reformulation/generation/impl/PostProcessingProjectionSplitterImpl.java @@ -35,8 +35,9 @@ private PostProcessingProjectionSplitterImpl(IntermediateQueryFactory iqFactory, this.iqFactory = iqFactory; this.substitutionFactory = substitutionFactory; this.avoidPostProcessingDecomposer = coreUtilsFactory.createProjectionDecomposer( - PostProcessingProjectionSplitterImpl::hasFunctionalToBePostProcessed); - this.proPostProcessingDecomposer = coreUtilsFactory.createProjectionDecomposer(ImmutableFunctionalTerm::canBePostProcessed); + PostProcessingProjectionSplitterImpl::hasFunctionalToBePostProcessed, false); + this.proPostProcessingDecomposer = coreUtilsFactory.createProjectionDecomposer( + ImmutableFunctionalTerm::canBePostProcessed, true); this.distinctNormalizer = distinctNormalizer; } From 5f0031923647dd62318e1bbed983ad1c12104c5b Mon Sep 17 00:00:00 2001 From: Benjamin Cogrel Date: Mon, 8 Feb 2021 16:53:55 +0100 Subject: [PATCH 3/9] Bugfix: RDF constants need to be post-processed. --- .../iq/tools/impl/ProjectionDecomposerImpl.java | 13 +++++++------ .../it/unibz/inf/ontop/utils/CoreUtilsFactory.java | 3 ++- .../impl/PostProcessingProjectionSplitterImpl.java | 5 +++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/core/model/src/main/java/it/unibz/inf/ontop/iq/tools/impl/ProjectionDecomposerImpl.java b/core/model/src/main/java/it/unibz/inf/ontop/iq/tools/impl/ProjectionDecomposerImpl.java index 09c224757d4..9b70edf1841 100644 --- a/core/model/src/main/java/it/unibz/inf/ontop/iq/tools/impl/ProjectionDecomposerImpl.java +++ b/core/model/src/main/java/it/unibz/inf/ontop/iq/tools/impl/ProjectionDecomposerImpl.java @@ -19,16 +19,16 @@ public class ProjectionDecomposerImpl implements ProjectionDecomposer { private final Predicate decompositionOracle; - private final boolean postprocessVariableAndConstantDefinitions; + private final Predicate postprocessNonFunctionalDefinitionOracle; private final SubstitutionFactory substitutionFactory; private final TermFactory termFactory; @AssistedInject private ProjectionDecomposerImpl(@Assisted Predicate decompositionOracle, - @Assisted Boolean postprocessVariableAndConstantDefinitions, + @Assisted Predicate postprocessNonFunctionalDefinitionOracle, SubstitutionFactory substitutionFactory, TermFactory termFactory) { this.decompositionOracle = decompositionOracle; - this.postprocessVariableAndConstantDefinitions = postprocessVariableAndConstantDefinitions; + this.postprocessNonFunctionalDefinitionOracle = postprocessNonFunctionalDefinitionOracle; this.substitutionFactory = substitutionFactory; this.termFactory = termFactory; } @@ -105,14 +105,15 @@ private DefinitionDecomposition decomposeDefinition(ImmutableTerm term, Variable } } /* - * When the definition of the substitution (not a sub-term of a functional term) is a constant or a variable, - * we may decide not to post-process it. + * When the definition of the substitution (not a sub-term of a functional term) is not functional, + * we may also decide not to post-process it. * * Useful for using Ontop for generating SQL queries with no post-processing * (for other purposes than SPARQL query answering) * */ - else if (definedVariable.isPresent() && (!postprocessVariableAndConstantDefinitions)) { + else if (definedVariable.isPresent() + && (!postprocessNonFunctionalDefinitionOracle.test((NonFunctionalTerm) term))) { Variable variable = definedVariable.get(); return new DefinitionDecomposition(variable, substitutionFactory.getSubstitution(variable, term)); } diff --git a/core/model/src/main/java/it/unibz/inf/ontop/utils/CoreUtilsFactory.java b/core/model/src/main/java/it/unibz/inf/ontop/utils/CoreUtilsFactory.java index d46ea46d829..99c2be7c001 100644 --- a/core/model/src/main/java/it/unibz/inf/ontop/utils/CoreUtilsFactory.java +++ b/core/model/src/main/java/it/unibz/inf/ontop/utils/CoreUtilsFactory.java @@ -5,6 +5,7 @@ import it.unibz.inf.ontop.iq.node.VariableNullability; import it.unibz.inf.ontop.iq.tools.ProjectionDecomposer; import it.unibz.inf.ontop.model.term.ImmutableFunctionalTerm; +import it.unibz.inf.ontop.model.term.NonFunctionalTerm; import it.unibz.inf.ontop.model.term.Variable; import java.util.Collection; @@ -34,5 +35,5 @@ VariableNullability createVariableNullability(@Assisted("nullableGroups") Immuta VariableNullability createEmptyVariableNullability(ImmutableSet scope); ProjectionDecomposer createProjectionDecomposer(Predicate decompositionOracle, - Boolean postprocessVariableAndConstantDefinitions); + Predicate postprocessNonFunctionalDefinitionOracle); } diff --git a/engine/reformulation/core/src/main/java/it/unibz/inf/ontop/answering/reformulation/generation/impl/PostProcessingProjectionSplitterImpl.java b/engine/reformulation/core/src/main/java/it/unibz/inf/ontop/answering/reformulation/generation/impl/PostProcessingProjectionSplitterImpl.java index 53bc8dc0717..288d6510ecb 100644 --- a/engine/reformulation/core/src/main/java/it/unibz/inf/ontop/answering/reformulation/generation/impl/PostProcessingProjectionSplitterImpl.java +++ b/engine/reformulation/core/src/main/java/it/unibz/inf/ontop/answering/reformulation/generation/impl/PostProcessingProjectionSplitterImpl.java @@ -35,9 +35,10 @@ private PostProcessingProjectionSplitterImpl(IntermediateQueryFactory iqFactory, this.iqFactory = iqFactory; this.substitutionFactory = substitutionFactory; this.avoidPostProcessingDecomposer = coreUtilsFactory.createProjectionDecomposer( - PostProcessingProjectionSplitterImpl::hasFunctionalToBePostProcessed, false); + PostProcessingProjectionSplitterImpl::hasFunctionalToBePostProcessed, + t -> !(t.isNull() || (t instanceof Variable) || (t instanceof DBConstant))); this.proPostProcessingDecomposer = coreUtilsFactory.createProjectionDecomposer( - ImmutableFunctionalTerm::canBePostProcessed, true); + ImmutableFunctionalTerm::canBePostProcessed, t -> true); this.distinctNormalizer = distinctNormalizer; } From 8b2fd54d56c52aab11a943cdb7bffc714c378b29 Mon Sep 17 00:00:00 2001 From: Benjamin Cogrel Date: Mon, 8 Feb 2021 18:49:27 +0100 Subject: [PATCH 4/9] Two configuration interfaces had not been updated. Fixed. --- .../inf/ontop/injection/OntopSQLCredentialConfiguration.java | 2 +- .../it/unibz/inf/ontop/injection/OntopMappingConfiguration.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/db/rdb/src/main/java/it/unibz/inf/ontop/injection/OntopSQLCredentialConfiguration.java b/db/rdb/src/main/java/it/unibz/inf/ontop/injection/OntopSQLCredentialConfiguration.java index 34b88ad26e5..013f94da3c2 100644 --- a/db/rdb/src/main/java/it/unibz/inf/ontop/injection/OntopSQLCredentialConfiguration.java +++ b/db/rdb/src/main/java/it/unibz/inf/ontop/injection/OntopSQLCredentialConfiguration.java @@ -10,7 +10,7 @@ public interface OntopSQLCredentialConfiguration extends OntopSQLCoreConfigurati @Override OntopSQLCredentialSettings getSettings(); - static Builder defaultBuilder() { + static Builder> defaultBuilder() { return new OntopSQLCredentialConfigurationImpl.BuilderImpl<>(); } diff --git a/mapping/core/src/main/java/it/unibz/inf/ontop/injection/OntopMappingConfiguration.java b/mapping/core/src/main/java/it/unibz/inf/ontop/injection/OntopMappingConfiguration.java index 2b2a8cf896d..dae10cbf621 100644 --- a/mapping/core/src/main/java/it/unibz/inf/ontop/injection/OntopMappingConfiguration.java +++ b/mapping/core/src/main/java/it/unibz/inf/ontop/injection/OntopMappingConfiguration.java @@ -16,7 +16,7 @@ public interface OntopMappingConfiguration extends OntopOBDAConfiguration, Ontop - static Builder defaultBuilder() { + static Builder> defaultBuilder() { return new OntopMappingConfigurationImpl.BuilderImpl<>(); } From 6d64f1399136e08bd9ed92bc8ab13da9b319623d Mon Sep 17 00:00:00 2001 From: Benjamin Cogrel Date: Tue, 9 Feb 2021 12:23:04 +0100 Subject: [PATCH 5/9] JsonDatabaseTable: integrity cstr insertion made more robust. --- .../dbschema/impl/JsonSerializedMetadataProvider.java | 4 ++-- .../ontop/dbschema/impl/json/JsonDatabaseTable.java | 10 ++++------ .../inf/ontop/dbschema/impl/json/JsonForeignKey.java | 2 +- .../dbschema/impl/json/JsonFunctionalDependency.java | 4 ++-- .../ontop/dbschema/impl/json/JsonUniqueConstraint.java | 4 ++-- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/db/rdb/src/main/java/it/unibz/inf/ontop/dbschema/impl/JsonSerializedMetadataProvider.java b/db/rdb/src/main/java/it/unibz/inf/ontop/dbschema/impl/JsonSerializedMetadataProvider.java index ec49a7b2478..298ecbe7bee 100644 --- a/db/rdb/src/main/java/it/unibz/inf/ontop/dbschema/impl/JsonSerializedMetadataProvider.java +++ b/db/rdb/src/main/java/it/unibz/inf/ontop/dbschema/impl/JsonSerializedMetadataProvider.java @@ -87,13 +87,13 @@ public ImmutableList getRelationIDs() throws MetadataExtractionExcep } @Override - public void insertIntegrityConstraints(NamedRelationDefinition relation, MetadataLookup metadataLookup) throws MetadataExtractionException { + public void insertIntegrityConstraints(NamedRelationDefinition relation, MetadataLookup metadataLookupForFk) throws MetadataExtractionException { JsonDatabaseTable jsonTable = relationMap.get(relation.getID()); if (jsonTable == null) throw new IllegalArgumentException("The relation " + relation.getID().getSQLRendering() + " is unknown to the JsonSerializedMetadataProvider"); - jsonTable.insertIntegrityConstraints(metadataLookup); + jsonTable.insertIntegrityConstraints(relation, metadataLookupForFk); } @Override diff --git a/db/rdb/src/main/java/it/unibz/inf/ontop/dbschema/impl/json/JsonDatabaseTable.java b/db/rdb/src/main/java/it/unibz/inf/ontop/dbschema/impl/json/JsonDatabaseTable.java index 7c757d44c3f..a9634a1c29f 100644 --- a/db/rdb/src/main/java/it/unibz/inf/ontop/dbschema/impl/json/JsonDatabaseTable.java +++ b/db/rdb/src/main/java/it/unibz/inf/ontop/dbschema/impl/json/JsonDatabaseTable.java @@ -86,21 +86,19 @@ public DatabaseTableDefinition createDatabaseTableDefinition(DBParameters dbPara return new DatabaseTableDefinition(allIDs, attributeListBuilder); } - public void insertIntegrityConstraints(MetadataLookup lookup) throws MetadataExtractionException { - DatabaseTableDefinition relation = (DatabaseTableDefinition)lookup.getRelation( - JsonMetadata.deserializeRelationID(lookup.getQuotedIDFactory(), name)); + public void insertIntegrityConstraints(NamedRelationDefinition relation, MetadataLookup lookupForFk) throws MetadataExtractionException { for (JsonUniqueConstraint uc: uniqueConstraints) - uc.insert(relation, lookup.getQuotedIDFactory()); + uc.insert(relation, lookupForFk.getQuotedIDFactory()); for (JsonFunctionalDependency fd: otherFunctionalDependencies) - fd.insert(relation, lookup.getQuotedIDFactory()); + fd.insert(relation, lookupForFk.getQuotedIDFactory()); for (JsonForeignKey fk : foreignKeys) { if (!fk.from.relation.equals(this.name)) throw new MetadataExtractionException("Table names mismatch: " + name + " != " + fk.from.relation); - fk.insert(relation, lookup); + fk.insert(relation, lookupForFk); } } diff --git a/db/rdb/src/main/java/it/unibz/inf/ontop/dbschema/impl/json/JsonForeignKey.java b/db/rdb/src/main/java/it/unibz/inf/ontop/dbschema/impl/json/JsonForeignKey.java index 5bfce0f3461..a678d7fcdcf 100644 --- a/db/rdb/src/main/java/it/unibz/inf/ontop/dbschema/impl/json/JsonForeignKey.java +++ b/db/rdb/src/main/java/it/unibz/inf/ontop/dbschema/impl/json/JsonForeignKey.java @@ -35,7 +35,7 @@ public JsonForeignKey(ForeignKeyConstraint fk) { .map(ForeignKeyConstraint.Component::getReferencedAttribute)); } - public void insert(DatabaseTableDefinition relation, MetadataLookup lookup) throws MetadataExtractionException { + public void insert(NamedRelationDefinition relation, MetadataLookup lookup) throws MetadataExtractionException { ForeignKeyConstraint.Builder builder = ForeignKeyConstraint.builder(name, relation, lookup.getRelation(JsonMetadata.deserializeRelationID(lookup.getQuotedIDFactory(), to.relation))); diff --git a/db/rdb/src/main/java/it/unibz/inf/ontop/dbschema/impl/json/JsonFunctionalDependency.java b/db/rdb/src/main/java/it/unibz/inf/ontop/dbschema/impl/json/JsonFunctionalDependency.java index 8bc35f0fd18..b411ef5fa0c 100644 --- a/db/rdb/src/main/java/it/unibz/inf/ontop/dbschema/impl/json/JsonFunctionalDependency.java +++ b/db/rdb/src/main/java/it/unibz/inf/ontop/dbschema/impl/json/JsonFunctionalDependency.java @@ -2,8 +2,8 @@ import com.fasterxml.jackson.annotation.*; import it.unibz.inf.ontop.dbschema.FunctionalDependency; +import it.unibz.inf.ontop.dbschema.NamedRelationDefinition; import it.unibz.inf.ontop.dbschema.QuotedIDFactory; -import it.unibz.inf.ontop.dbschema.impl.DatabaseTableDefinition; import it.unibz.inf.ontop.exception.MetadataExtractionException; import java.util.List; @@ -28,7 +28,7 @@ public JsonFunctionalDependency(FunctionalDependency fd) { this.dependents = JsonMetadata.serializeAttributeList(fd.getDependents().stream()); } - public void insert(DatabaseTableDefinition relation, QuotedIDFactory idFactory) throws MetadataExtractionException { + public void insert(NamedRelationDefinition relation, QuotedIDFactory idFactory) throws MetadataExtractionException { FunctionalDependency.Builder builder = FunctionalDependency.defaultBuilder(relation); JsonMetadata.deserializeAttributeList(idFactory, determinants, builder::addDeterminant); JsonMetadata.deserializeAttributeList(idFactory, dependents, builder::addDependent); diff --git a/db/rdb/src/main/java/it/unibz/inf/ontop/dbschema/impl/json/JsonUniqueConstraint.java b/db/rdb/src/main/java/it/unibz/inf/ontop/dbschema/impl/json/JsonUniqueConstraint.java index 2b7e8b0dd2b..3cc22863516 100644 --- a/db/rdb/src/main/java/it/unibz/inf/ontop/dbschema/impl/json/JsonUniqueConstraint.java +++ b/db/rdb/src/main/java/it/unibz/inf/ontop/dbschema/impl/json/JsonUniqueConstraint.java @@ -2,9 +2,9 @@ import com.fasterxml.jackson.annotation.*; import it.unibz.inf.ontop.dbschema.FunctionalDependency; +import it.unibz.inf.ontop.dbschema.NamedRelationDefinition; import it.unibz.inf.ontop.dbschema.QuotedIDFactory; import it.unibz.inf.ontop.dbschema.UniqueConstraint; -import it.unibz.inf.ontop.dbschema.impl.DatabaseTableDefinition; import it.unibz.inf.ontop.exception.MetadataExtractionException; import java.util.List; @@ -35,7 +35,7 @@ public JsonUniqueConstraint(UniqueConstraint uc) { this.determinants = JsonMetadata.serializeAttributeList(uc.getAttributes().stream()); } - public void insert(DatabaseTableDefinition relation, QuotedIDFactory idFactory) throws MetadataExtractionException { + public void insert(NamedRelationDefinition relation, QuotedIDFactory idFactory) throws MetadataExtractionException { FunctionalDependency.Builder builder = isPrimaryKey ? UniqueConstraint.primaryKeyBuilder(relation, name) : UniqueConstraint.builder(relation, name); From ee7890b17fd37ce87bcdcef2799bf631b4af032f Mon Sep 17 00:00:00 2001 From: Albulen Pano Date: Tue, 9 Feb 2021 15:39:31 +0100 Subject: [PATCH 6/9] 1 unpassed test added for dbmetadata input --- .../rdf4j/repository/AbstractRDF4JTest.java | 9 ++++ .../BasicViewPersonDBMetadataTest.java | 41 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 binding/rdf4j/src/test/java/it/unibz/inf/ontop/rdf4j/repository/BasicViewPersonDBMetadataTest.java diff --git a/binding/rdf4j/src/test/java/it/unibz/inf/ontop/rdf4j/repository/AbstractRDF4JTest.java b/binding/rdf4j/src/test/java/it/unibz/inf/ontop/rdf4j/repository/AbstractRDF4JTest.java index 978fb008c4a..65e586ce878 100644 --- a/binding/rdf4j/src/test/java/it/unibz/inf/ontop/rdf4j/repository/AbstractRDF4JTest.java +++ b/binding/rdf4j/src/test/java/it/unibz/inf/ontop/rdf4j/repository/AbstractRDF4JTest.java @@ -49,6 +49,12 @@ protected static void initOBDA(String dbScriptRelativePath, String obdaRelativeP protected static void initOBDA(String dbScriptRelativePath, String obdaRelativePath, @Nullable String ontologyRelativePath, @Nullable String propertyFile, @Nullable String viewFile) throws SQLException, IOException { + initOBDA(dbScriptRelativePath, obdaRelativePath, ontologyRelativePath, propertyFile, null, null); + } + + protected static void initOBDA(String dbScriptRelativePath, String obdaRelativePath, + @Nullable String ontologyRelativePath, @Nullable String propertyFile, + @Nullable String viewFile, @Nullable String dbMetadataFile) throws SQLException, IOException { String jdbcUrl = URL_PREFIX + UUID.randomUUID().toString(); SQL_CONNECTION = DriverManager.getConnection(jdbcUrl, USER, PASSWORD); @@ -84,6 +90,9 @@ protected static void initOBDA(String dbScriptRelativePath, String obdaRelativeP if (viewFile != null) builder.ontopViewFile(AbstractRDF4JTest.class.getResource(viewFile).getPath()); + if (dbMetadataFile != null) + builder.dbMetadataFile(AbstractRDF4JTest.class.getResource(dbMetadataFile).getPath()); + OntopSQLOWLAPIConfiguration config = builder.build(); OntopRepository repo = OntopRepository.defaultRepository(config); diff --git a/binding/rdf4j/src/test/java/it/unibz/inf/ontop/rdf4j/repository/BasicViewPersonDBMetadataTest.java b/binding/rdf4j/src/test/java/it/unibz/inf/ontop/rdf4j/repository/BasicViewPersonDBMetadataTest.java new file mode 100644 index 00000000000..6da1b824ed8 --- /dev/null +++ b/binding/rdf4j/src/test/java/it/unibz/inf/ontop/rdf4j/repository/BasicViewPersonDBMetadataTest.java @@ -0,0 +1,41 @@ +package it.unibz.inf.ontop.rdf4j.repository; + +import com.google.common.collect.ImmutableList; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.IOException; +import java.sql.SQLException; + +public class BasicViewPersonDBMetadataTest extends AbstractRDF4JTest { + private static final String OBDA_FILE = "/person/person_basicviews.obda"; + private static final String SQL_SCRIPT = "/person/person.sql"; + private static final String VIEW_FILE = "/person/views/basic_views.json"; + private static final String DBMETADATA_FILE = "/person/person_with_constraints.db-extract.json"; + + @BeforeClass + public static void before() throws IOException, SQLException { + initOBDA(SQL_SCRIPT, OBDA_FILE, null, null, VIEW_FILE, DBMETADATA_FILE); + } + + @AfterClass + public static void after() throws SQLException { + release(); + } + + /** + * Concatenation and upper case + */ + @Test + public void testPersonConcat() throws Exception { + String query = "PREFIX : \n" + + "PREFIX xsd: \n" + + "SELECT ?v \n" + + "WHERE {\n" + + " ?x a :Person . \n" + + " ?x :fullNameAndLocality ?v . \n" + + "}"; + runQueryAndCompare(query, ImmutableList.of("ROGER SMITH Botzen")); + } +} From 9df5da5ad9f4960363a52b4d08ca63ba8a69984d Mon Sep 17 00:00:00 2001 From: Albulen Pano Date: Tue, 9 Feb 2021 15:43:09 +0100 Subject: [PATCH 7/9] Minor fix --- .../it/unibz/inf/ontop/rdf4j/repository/AbstractRDF4JTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binding/rdf4j/src/test/java/it/unibz/inf/ontop/rdf4j/repository/AbstractRDF4JTest.java b/binding/rdf4j/src/test/java/it/unibz/inf/ontop/rdf4j/repository/AbstractRDF4JTest.java index 65e586ce878..be021c63666 100644 --- a/binding/rdf4j/src/test/java/it/unibz/inf/ontop/rdf4j/repository/AbstractRDF4JTest.java +++ b/binding/rdf4j/src/test/java/it/unibz/inf/ontop/rdf4j/repository/AbstractRDF4JTest.java @@ -49,7 +49,7 @@ protected static void initOBDA(String dbScriptRelativePath, String obdaRelativeP protected static void initOBDA(String dbScriptRelativePath, String obdaRelativePath, @Nullable String ontologyRelativePath, @Nullable String propertyFile, @Nullable String viewFile) throws SQLException, IOException { - initOBDA(dbScriptRelativePath, obdaRelativePath, ontologyRelativePath, propertyFile, null, null); + initOBDA(dbScriptRelativePath, obdaRelativePath, ontologyRelativePath, propertyFile, viewFile, null); } protected static void initOBDA(String dbScriptRelativePath, String obdaRelativePath, From 88a3c49181a7dc071a1d6c955962978c2d418131 Mon Sep 17 00:00:00 2001 From: Benjamin Cogrel Date: Tue, 9 Feb 2021 19:31:59 +0100 Subject: [PATCH 8/9] FK to an unused table added in an example with views. Test failing. --- .../person_with_constraints.db-extract.json | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/binding/rdf4j/src/test/resources/person/person_with_constraints.db-extract.json b/binding/rdf4j/src/test/resources/person/person_with_constraints.db-extract.json index b25775dfa38..ee799dc37ae 100644 --- a/binding/rdf4j/src/test/resources/person/person_with_constraints.db-extract.json +++ b/binding/rdf4j/src/test/resources/person/person_with_constraints.db-extract.json @@ -6,7 +6,27 @@ "isPrimaryKey" : true } ], "otherFunctionalDependencies" : [ ], - "foreignKeys" : [ ], + "foreignKeys" : [ + { + "to": { + "columns": [ + "\"id\"" + ], + "relation": [ + "\"entity\"" + ] + }, + "from": { + "columns": [ + "\"id\"" + ], + "relation": [ + "\"person\"" + ] + }, + "name": "entity-fkey" + } + ], "columns" : [ { "name" : "\"id\"", "datatype" : "INTEGER", @@ -47,7 +67,23 @@ "isNullable" : false } ], "name" : ["\"statuses\""] - } ], + }, + { + "uniqueConstraints" : [ { + "name" : "CONSTRAINT_D", + "determinants" : [ "\"id\"" ], + "isPrimaryKey" : true + } ], + "otherFunctionalDependencies" : [ ], + "foreignKeys" : [ ], + "columns" : [ { + "name" : "\"id\"", + "datatype" : "INTEGER", + "isNullable" : false + }], + "name" : ["\"entity\""] + } + ], "metadata" : { "dbmsProductName" : "H2", "dbmsVersion" : "1.4.199 (2019-03-13)", From 4eac8631e53f496051ce58b8e244056d8774f6e8 Mon Sep 17 00:00:00 2001 From: Benjamin Cogrel Date: Tue, 9 Feb 2021 19:33:27 +0100 Subject: [PATCH 9/9] JsonForeignKey: stop throwing an exception when target rel not reachable. --- .../ontop/dbschema/impl/json/JsonForeignKey.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/db/rdb/src/main/java/it/unibz/inf/ontop/dbschema/impl/json/JsonForeignKey.java b/db/rdb/src/main/java/it/unibz/inf/ontop/dbschema/impl/json/JsonForeignKey.java index a678d7fcdcf..3d3a7a061e3 100644 --- a/db/rdb/src/main/java/it/unibz/inf/ontop/dbschema/impl/json/JsonForeignKey.java +++ b/db/rdb/src/main/java/it/unibz/inf/ontop/dbschema/impl/json/JsonForeignKey.java @@ -2,8 +2,9 @@ import com.fasterxml.jackson.annotation.*; import it.unibz.inf.ontop.dbschema.*; -import it.unibz.inf.ontop.dbschema.impl.DatabaseTableDefinition; import it.unibz.inf.ontop.exception.MetadataExtractionException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.List; import java.util.stream.Stream; @@ -18,6 +19,8 @@ public class JsonForeignKey extends JsonOpenObject { public final String name; public final Part from, to; + private static final Logger LOGGER = LoggerFactory.getLogger(JsonForeignKey.class); + @JsonCreator public JsonForeignKey(@JsonProperty("name") String name, @JsonProperty("from") Part from, @@ -37,8 +40,15 @@ public JsonForeignKey(ForeignKeyConstraint fk) { public void insert(NamedRelationDefinition relation, MetadataLookup lookup) throws MetadataExtractionException { - ForeignKeyConstraint.Builder builder = ForeignKeyConstraint.builder(name, relation, - lookup.getRelation(JsonMetadata.deserializeRelationID(lookup.getQuotedIDFactory(), to.relation))); + ForeignKeyConstraint.Builder builder; + try { + builder = ForeignKeyConstraint.builder(name, relation, + lookup.getRelation(JsonMetadata.deserializeRelationID(lookup.getQuotedIDFactory(), to.relation))); + } + catch (MetadataExtractionException e) { + LOGGER.warn("Cannot find table {} for FK {}", to.relation, name); + return ; + } try { for (int i = 0; i < from.columns.size(); i++)