Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Fix query stalling #621

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/main/scala/org/renci/cam/QueryService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import io.circe.syntax._
import org.apache.jena.query.QuerySolution
import org.apache.jena.rdf.model.Resource
import org.phenoscape.sparql.SPARQLInterpolation._
import org.renci.cam.Biolink.{biolinkData, BiolinkData}
import org.renci.cam.Biolink.{BiolinkData, biolinkData}
import org.renci.cam.HttpClient.HttpClient
import org.renci.cam.SPARQLQueryExecutor.SPARQLCache
import org.renci.cam.Util.IterableSPARQLOps
import org.renci.cam.domain.{TRAPIAttribute, _}
import zio.config.{getConfig, ZConfig}
import zio.{config => _, Has, RIO, Task, UIO, ZIO}
import zio.config.{ZConfig, getConfig}
import zio.{Has, RIO, Task, UIO, ZIO, config => _}

import java.math.BigInteger
import java.nio.charset.StandardCharsets
Expand All @@ -21,6 +21,8 @@ import scala.jdk.CollectionConverters._

object QueryService extends LazyLogging {

val INNER_LIMIT_MULTIPLIER = 100

val ProvWasDerivedFrom: IRI = IRI("http://www.w3.org/ns/prov#wasDerivedFrom")

val RDFSSubClassOf: IRI = IRI("http://www.w3.org/2000/01/rdf-schema#subClassOf")
Expand Down Expand Up @@ -483,6 +485,8 @@ object QueryService extends LazyLogging {
val nodesToDirectTypes = getNodesToDirectTypes(queryGraph.nodes)
val edgePatterns = queryEdgeSparql.fold(sparql"")(_ + _)
val limitSparql = if (limit > 0) sparql" LIMIT $limit" else sparql""
val innerLimit = INNER_LIMIT_MULTIPLIER * limit
val innerLimitSparql = if (limit > 0) sparql" LIMIT $innerLimit" else sparql""
val queryString =
sparql"""SELECT DISTINCT $typeProjections
(GROUP_CONCAT(DISTINCT ?g; SEPARATOR='|') AS ?graphs)
Expand All @@ -494,7 +498,7 @@ object QueryService extends LazyLogging {
SELECT $nodeProjections ?g
WHERE {
$edgePatterns
}
} ${innerLimitSparql}
}
$BigDataQueryHintPrior $BigDataQueryHintRunFirst true .
}
Expand Down Expand Up @@ -565,7 +569,6 @@ object QueryService extends LazyLogging {
def getProjections(queryGraph: TRAPIQueryGraph, typesInsteadOfNodes: Boolean = false): QueryText = {
val projectionVariableNames =
queryGraph.edges.keys ++
queryGraph.nodes.keys.map(queryNodeID => s"${queryNodeID}_class") ++
(if (typesInsteadOfNodes) queryGraph.nodes.keys.map(queryNodeID => s"${queryNodeID}_type")
else queryGraph.edges.flatMap(e => List(e._2.subject, e._2.`object`)))
projectionVariableNames.map(Var(_)).map(v => sparql" $v ").fold(sparql"")(_ + _)
Expand Down