From f4a781b14c6bb08c393585b67591f3ef02d7b7d4 Mon Sep 17 00:00:00 2001 From: Sepideh Alassi Date: Mon, 20 Nov 2023 13:22:14 +0100 Subject: [PATCH] fix: BEOL timeouts (#2945) Co-authored-by: Sepideh Alassi <> --- .../SparqlTransformerSpec.scala | 6 ++--- .../transformers/ConstructTransformer.scala | 2 +- .../transformers/SelectTransformer.scala | 2 +- .../transformers/SparqlTransformer.scala | 23 ++++++++++--------- 4 files changed, 17 insertions(+), 16 deletions(-) rename integration/src/test/scala/org/knora/webapi/messages/util/search/{gravsearch/transformers => }/SparqlTransformerSpec.scala (99%) diff --git a/integration/src/test/scala/org/knora/webapi/messages/util/search/gravsearch/transformers/SparqlTransformerSpec.scala b/integration/src/test/scala/org/knora/webapi/messages/util/search/SparqlTransformerSpec.scala similarity index 99% rename from integration/src/test/scala/org/knora/webapi/messages/util/search/gravsearch/transformers/SparqlTransformerSpec.scala rename to integration/src/test/scala/org/knora/webapi/messages/util/search/SparqlTransformerSpec.scala index bb5f0395a1..6a62b134f5 100644 --- a/integration/src/test/scala/org/knora/webapi/messages/util/search/gravsearch/transformers/SparqlTransformerSpec.scala +++ b/integration/src/test/scala/org/knora/webapi/messages/util/search/SparqlTransformerSpec.scala @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package org.knora.webapi.messages.util.search.gravsearch.transformers +package org.knora.webapi.util.search import org.knora.webapi.CoreSpec import org.knora.webapi.messages.IriConversions._ @@ -80,11 +80,11 @@ class SparqlTransformerSpec extends CoreSpec { isDeletedStatement, linkStatement ) - val optimisedPatterns = SparqlTransformer.optimiseIsDeletedWithMinus(patterns) + val optimisedPatterns = SparqlTransformer.optimiseIsDeletedWithFilter(patterns) val expectedPatterns = Seq( typeStatement, linkStatement, - MinusPattern( + FilterNotExistsPattern( Seq( StatementPattern( subj = QueryVariable("foo"), diff --git a/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/transformers/ConstructTransformer.scala b/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/transformers/ConstructTransformer.scala index 447d114662..e4e9c65bac 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/transformers/ConstructTransformer.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/transformers/ConstructTransformer.scala @@ -38,7 +38,7 @@ final case class ConstructTransformer( optimisedPatterns <- ZIO.attempt( SparqlTransformer.moveBindToBeginning( - SparqlTransformer.optimiseIsDeletedWithMinus( + SparqlTransformer.optimiseIsDeletedWithFilter( SparqlTransformer.moveLuceneToBeginning(patterns) ) ) diff --git a/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/transformers/SelectTransformer.scala b/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/transformers/SelectTransformer.scala index 7d5b658bf1..903ba13665 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/transformers/SelectTransformer.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/transformers/SelectTransformer.scala @@ -39,7 +39,7 @@ class SelectTransformer( limitInferenceToOntologies = limitInferenceToOntologies ) override def optimiseQueryPatterns(patterns: Seq[QueryPattern]): Task[Seq[QueryPattern]] = ZIO.attempt { - moveBindToBeginning(optimiseIsDeletedWithMinus(moveLuceneToBeginning(patterns))) + moveBindToBeginning(optimiseIsDeletedWithFilter(moveLuceneToBeginning(patterns))) } /** diff --git a/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/transformers/SparqlTransformer.scala b/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/transformers/SparqlTransformer.scala index 2f41be4206..fafca73e39 100644 --- a/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/transformers/SparqlTransformer.scala +++ b/webapi/src/main/scala/org/knora/webapi/messages/util/search/gravsearch/transformers/SparqlTransformer.scala @@ -87,13 +87,13 @@ object SparqlTransformer { createUniqueVariableFromStatement(baseStatement, "LinkValue") /** - * Optimises a query by replacing `knora-base:isDeleted false` with a `MINUS` pattern + * Optimises a query by replacing `knora-base:isDeleted false` with a `FILTER NOT EXISTS` pattern * placed at the end of the block. * * @param patterns the block of patterns to be optimised. * @return the result of the optimisation. */ - def optimiseIsDeletedWithMinus(patterns: Seq[QueryPattern]): Seq[QueryPattern] = { + def optimiseIsDeletedWithFilter(patterns: Seq[QueryPattern]): Seq[QueryPattern] = { implicit val stringFormatter: StringFormatter = StringFormatter.getGeneralInstance // Separate the knora-base:isDeleted statements from the rest of the block. @@ -107,17 +107,18 @@ object SparqlTransformer { case _ => false } - // Replace the knora-base:isDeleted statements with MINUS patterns. - val filterPatterns: Seq[MinusPattern] = isDeletedPatterns.collect { case statementPattern: StatementPattern => - MinusPattern( - Seq( - StatementPattern( - subj = statementPattern.subj, - pred = IriRef(OntologyConstants.KnoraBase.IsDeleted.toSmartIri), - obj = XsdLiteral(value = "true", datatype = OntologyConstants.Xsd.Boolean.toSmartIri) + // Replace the knora-base:isDeleted statements with FILTER NOT EXISTS patterns. + val filterPatterns: Seq[FilterNotExistsPattern] = isDeletedPatterns.collect { + case statementPattern: StatementPattern => + FilterNotExistsPattern( + Seq( + StatementPattern( + subj = statementPattern.subj, + pred = IriRef(OntologyConstants.KnoraBase.IsDeleted.toSmartIri), + obj = XsdLiteral(value = "true", datatype = OntologyConstants.Xsd.Boolean.toSmartIri) + ) ) ) - ) } otherPatterns ++ filterPatterns