Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api-v1): Optimise link value queries for Fuseki (DSP-1243) #1791

Merged
merged 5 commits into from Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -136,11 +136,11 @@ object StandoffTagUtilV2 {
standoffPropertyEntities(standoffTagPropIri).entityInfoContent.predicates

// check if a cardinality exists for the current attribute
if (classSpecificProps.get(standoffTagPropIri).isEmpty) {
if (!classSpecificProps.contains(standoffTagPropIri)) {
throw BadRequestException(s"no cardinality defined for attr '${attr.key}'")
}

if (propPredicates.get(OntologyConstants.KnoraBase.ObjectDatatypeConstraint.toSmartIri).isDefined) {
if (propPredicates.contains(OntologyConstants.KnoraBase.ObjectDatatypeConstraint.toSmartIri)) {
// property is a data type property

val propDatatypeConstraint = propPredicates(OntologyConstants.KnoraBase.ObjectDatatypeConstraint.toSmartIri)
Expand Down
Expand Up @@ -45,44 +45,37 @@ SELECT ?linkValue ?directLinkExists ?targetResourceClass ?objPred ?objObj
FROM <http://www.ontotext.com/explicit>
}
WHERE {
BIND(IRI("@subjectIri") AS ?subject)
BIND(IRI("@predicateIri") AS ?predicate)
BIND(IRI("@{predicateIri}Value") AS ?predicateForLinkValue)

@maybeObjectIri match {
case Some(objectIri) => {

BIND(IRI("@objectIri") AS ?object)
BIND(IRI("@linkValueIri") AS ?linkValue)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In line 50 and 72 below, you are using <@linkValueIri> not the ?linkValue, is the bind here really necessary?
I see that ?linkValue is used in Select, so if for that purpose BIND is necessary, why not use ?linkValue in the other statements?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bind is there only so we can return ?linkValue in SELECT. Using an IRI literal instead of a variable improves performance, so I changed all the variables to literals wherever possible in these queries.


}
<@linkValueIri> rdf:type knora-base:LinkValue .

case None => {}
FILTER NOT EXISTS {
<@linkValueIri> knora-base:isDeleted true .
}

BIND(IRI("@linkValueIri") AS ?linkValue)
OPTIONAL {
@maybeObjectIri match {
case Some(objectIri) => {
<@objectIri> rdf:type ?targetResourceClass .
}

?subject ?predicateForLinkValue ?linkValue .
?linkValue rdf:type knora-base:LinkValue ;
rdf:subject ?subject ;
rdf:predicate ?predicate ;
rdf:object ?object ;
knora-base:isDeleted false .
case None => {
<@subjectIri> <@predicateIri> ?object .
?object rdf:type ?targetResourceClass .
}
}

OPTIONAL {
?subject ?predicate ?object .
?object rdf:type ?targetResourceClass .
BIND(true AS ?directLinkExists)
}

{
?linkValue ?objPred ?objObj .
<@linkValueIri> ?objPred ?objObj .
}
UNION
{
@* Return the project of the resource that contains the value. *@

?subject ?predicateForLinkValue ?linkValue . @* TODO: Why do we need this here? (Issue 235) *@
?subject knora-base:attachedToProject ?resourceProject .
<@subjectIri> knora-base:attachedToProject ?resourceProject .

BIND(knora-base:attachedToProject AS ?objPred)
BIND(?resourceProject AS ?objObj)
Expand Down
Expand Up @@ -47,23 +47,22 @@ SELECT ?linkValue ?directLinkExists ?targetResourceClass ?objPred ?objObj
FROM <http://www.ontotext.com/explicit>
}
WHERE {
BIND(IRI("@subjectIri") AS ?subject)
BIND(IRI("@predicateIri") AS ?predicate)
BIND(IRI("@{predicateIri}Value") AS ?predicateForLinkValue)
BIND(IRI("@objectIri") AS ?object)
<@subjectIri> <@{predicateIri}Value> ?linkValue .

?subject ?predicateForLinkValue ?linkValue .
?linkValue rdf:type knora-base:LinkValue ;
@if(!includeDeleted) {
knora-base:isDeleted false ;
rdf:subject <@subjectIri> ;
rdf:predicate <@predicateIri> ;
rdf:object <@objectIri> .

@if(!includeDeleted) {
FILTER NOT EXISTS {
?linkValue knora-base:isDeleted true ;
}
rdf:subject ?subject ;
rdf:predicate ?predicate ;
rdf:object ?object .
}

OPTIONAL {
?subject ?predicate ?object .
?object rdf:type ?targetResourceClass .
<@subjectIri> <@predicateIri> <@objectIri> .
<@objectIri> rdf:type ?targetResourceClass .
BIND(true AS ?directLinkExists)
}

Expand All @@ -76,8 +75,7 @@ WHERE {
{
@* Return the project of the resource that contains the value. *@

?subject ?predicateForLinkValue ?linkValue . @* TODO: Why do we need this here? (Issue 235) *@
?subject knora-base:attachedToProject ?resourceProject .
<@subjectIri> knora-base:attachedToProject ?resourceProject .

BIND(knora-base:attachedToProject AS ?objPred)
BIND(?resourceProject AS ?objObj)
Expand Down
Expand Up @@ -113,6 +113,7 @@ scala_test(
"//webapi:test_library",
"@maven//:org_scala_lang_modules_scala_xml_2_12",
"@maven//:org_xmlunit_xmlunit_core",
"@maven//:com_jsuereth_scala_arm_2_12",
] + BASE_TEST_DEPENDENCIES_WITH_JSON,
)

Expand Down