Jena / Arq:查询处理卡住了

时间:2012-08-12 15:11:03

标签: sparql jena arq

如果出现以下SPARQL查询问题:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX :<http://www.test.at/DA.owl#>
SELECT ?ModuleName ?SLAName ?SLOName ?SLOTypeName ?SLOTHV (AVG(DISTINCT ?SLTTV) AS ?AVGTrackValue)  (COUNT(DISTINCT ?SLT) AS ?SLTCOUNT) 
WHERE {
    ?Module rdf:type :ServiceModule .
    ?SLA rdf:type :ServiceLevelAgreement.
    ?SLO rdf:type :ServiceLevelObjective .
    ?SLT rdf:type :ServiceLevelTracking .
    ?Day rdf:type :Day .
    ?Holiday rdf:type :Holiday .
    ?rel1 rdf:type :RelationFact .
    ?rel2 rdf:type :RelationFact .
    ?rel3 rdf:type :RelationFact .
    ?rel4 rdf:type :RelationFact .
    ?rel5 rdf:type :RelationFact .
    ?Module :hasName ?ModuleName .
    ?SLA :hasName ?SLAName .
    ?SLO :hasName ?SLOName .
    ?SLO :hasType ?SLOType . 
    ?SLO :hasThresholdValue ?SLOTHV .
    ?SLOType :hasName ?SLOTypeName .            
    ?SLT :hasDayName ?SLTDayName .
    ?SLT :hasType ?SLTType .        
    ?SLT :hasTrackedDateTime ?trackTime .
    ?SLT :hasTrackedValue ?SLTTV .
    ?Day :hasDayName ?DayName .
    ?Holiday :hasDate ?HolidayDate .
    ?Holiday :hasStartTime ?HolidayStartTime .
    ?Holiday :hasEndTime ?HolidayEndTime .      
    ?rel1 :hasParent ?Module .
    ?rel1 :hasChild ?SLA .  
    ?rel2 :hasParent ?Module.
    ?rel2 :hasChild ?SLT .      
    ?rel3 :hasParent ?SLA .
    ?rel3 :hasChild ?SLO .
    ?rel4 :hasParent ?SLA .
    ?rel4 :hasChild ?Day .
    ?rel5 :hasParent ?SLA .
    ?rel5 :hasChild ?Holiday .  
    Filter(regex(str(?ModuleName), "E-mail")) .
    Filter(?SLOType = ?SLTType) .
    Filter(xsd:dateTime(?trackTime)  >=  xsd:dateTime("2012-08-15T12:00:00") && ?trackTime  <  xsd:dateTime("2012-08-15T13:00:00")) .
    Filter(?DayName = ?SLTDayName || (xsd:dateTime("2012-08-15T00:00:00") = ?HolidayDate && xsd:dateTime(?trackTime) >= xsd:dateTime("2012-08-15T12:00:00") &&  xsd:dateTime(?trackTime) < xsd:dateTime("2012-08-15T14:00:00")))
} 
GROUP BY ?ModuleName ?SLAName ?SLOName ?SLOTypeName ?SLOTHV
HAVING (?AVGTrackValue < ?SLOTHV)

使用potégé4.2此查询可以正常运行并在1秒内返回结果。使用SPARQLer查询验证器(http://www.sparql.org/query-validator.html)进行语法检查也表明SPARQL查询有效。但是使用jena arq引擎,查询处理在等待结果集时始终处于停滞状态。我在命令行中使用jena-arq-2.9.1并在带有以下代码的java应用程序中尝试过它:

    Query q = QueryFactory.create(queryString);
    QueryExecution qexec = QueryExecutionFactory.create(q, currentOntologyModel);
    try {
        ResultSet results = qexec.execSelect();
        while (results.hasNext()) {
            QuerySolution soln = results.nextSolution();
            .
            .
            .
            <some other code>
            .
            .
            .
            }
        }
    } finally {
        qexec.close();
    }

也许有人知道问题是什么。

2 个答案:

答案 0 :(得分:2)

据推测,数据是在内存中。

看起来查询优化器没有找到有效的计划。一开始所有未连接的rdf:type可能导致计算效率低下的中间交叉产品。

重新排序三重模式可能会有所帮助(mayeb将rdf:type移到最后?查询本身不足以知道 - 这取决于数据)。如果您发现更快的订单,请将其发送到Apache的jena用户列表。

答案 1 :(得分:0)

谢谢你的回答安迪。 这似乎是执行计划的一个问题。现在我正在使用子选择来检索?SLT的数据,并且查询工作完美。这是现在有效的查询:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX :<http://www.test.at/DA.owl#>
SELECT ?ModuleName ?SLAName ?SLOName ?SLOTypeName ?SLOTHV (AVG(DISTINCT ?SLTTV) AS     ?AVGTrackValue)  (COUNT(DISTINCT ?SLT) AS ?SLTCOUNT) 
WHERE {
?Module rdf:type :ServiceModule .
?SLA rdf:type :ServiceLevelAgreement.
?SLO rdf:type :ServiceLevelObjective .
?Day rdf:type :Day .
?Holiday rdf:type :Holiday .
?rel1 rdf:type :RelationFact .
?rel3 rdf:type :RelationFact .
?rel4 rdf:type :RelationFact .
?rel5 rdf:type :RelationFact .
?Module :hasName ?ModuleName .
?SLA :hasName ?SLAName .
?SLO :hasName ?SLOName .
?SLO :hasType ?SLOType . 
?SLO :hasThresholdValue ?SLOTHV .
?SLOType :hasName ?SLOTypeName .            
?SLT :hasDayName ?SLTDayName .
?SLT :hasType ?SLTType .        
?SLT :hasTrackedDateTime ?trackTime .
?SLT :hasTrackedValue ?SLTTV .
?Day :hasDayName ?DayName .
?Holiday :hasDate ?HolidayDate .
?Holiday :hasStartTime ?HolidayStartTime .
?Holiday :hasEndTime ?HolidayEndTime .      
?rel1 :hasParent ?Module .
?rel1 :hasChild ?SLA .     
?rel3 :hasParent ?SLA .
?rel3 :hasChild ?SLO .
?rel4 :hasParent ?SLA .
?rel4 :hasChild ?Day .
?rel5 :hasParent ?SLA .
?rel5 :hasChild ?Holiday .
{
    SELECT ?SLT ?SLTType ?ModuleName
    WHERE {
    ?SLT rdf:type :ServiceLevelTracking .
    ?rel2 rdf:type :RelationFact .
    ?Module :hasName ?ModuleName .
    Filter(regex(str(?ModuleName), "E-mail")) .
    ?rel2 :hasParent ?Module.
    ?rel2 :hasChild ?SLT    
    }
}   
Filter(?SLOType = ?SLTType) .
Filter(xsd:dateTime(?trackTime)  >=  xsd:dateTime("2012-08-15T12:00:00") && ?trackTime  <  xsd:dateTime("2012-08-15T13:00:00")) .
Filter(?DayName = ?SLTDayName || (xsd:dateTime("2012-08-15T00:00:00") = ?HolidayDate && xsd:dateTime(?trackTime) >= xsd:dateTime("2012-08-15T12:00:00") &&  xsd:dateTime(?trackTime) < xsd:dateTime("2012-08-15T14:00:00")))
} 
GROUP BY ?ModuleName ?SLAName ?SLOName ?SLOTypeName ?SLOTHV
HAVING (?AVGTrackValue < ?SLOTHV)