Igorkim78 added a comment.

  The EmptyLabelServiceOptimizer running optimizeJoinGroup(AST2BOpContext, 
StaticAnalysis, IBindingSet[], JoinGroupNode) as of current takes projection 
from StaticAnalisys.getQueryRoot() as parent of JoinGroupNode wrapping 
statement pattern of the LabelService clause is unavailable.
  
  parent is defined in GroupMemberNodeBase as IGroupNode<IGroupMemberNode>, so 
it could not give us a reference to ServiceNode to propagate to SubqueryBase, 
as both of them are not IGroupNode descendants.
  
  So to get back-references from nested statement patterns, clauses etc. to 
SubqueryBase which we need to extract it's projection, we would need to 
introduce proper annotations and propagate them through different types of 
nesting Nodes as actual service clause might be enclosed with for example 
UnionNode, etc.
  
  Assignment of annotation can be done in 
com.bigdata.rdf.sail.sparql.BigdataExprBuilder.handleWhereClause(ASTQuery, 
QueryBase) as
  
    queryRoot.setWhereClause(ret);
    if (queryRoot instanceof SubqueryBase) {
        ret.annotations().put(QueryBase.Annotations.PROJECTION, 
queryRoot.getProjection());
    }
  
  Then we could use it in 
org.wikidata.query.rdf.blazegraph.label.EmptyLabelServiceOptimizer.optimizeJoinGroup(AST2BOpContext,
 StaticAnalysis, IBindingSet[], JoinGroupNode) as
  
    if (!foundArg) {
        EmptyLabelServiceOptimizer.this.addResolutions(ctx, g, (ProjectionNode) 
service.getParent().annotations().get(QueryBase.Annotations.PROJECTION));
    }
  
  But this would require changing blazegraph core and also additional handling 
should be applied to properly propagate annotation to nested clauses.
  
  There is another option though, 
org.wikidata.query.rdf.blazegraph.label.EmptyLabelServiceOptimizer.optimizeJoinGroup(AST2BOpContext,
 StaticAnalysis, IBindingSet[], JoinGroupNode)
  is already traversing the whole tree to process LabelService clauses,  so we 
could hangle projection annotation at this point:
  
    join.getChildren(SubqueryBase.class).stream().forEach(node->{
        SubqueryBase subqueryBase = (SubqueryBase)node;
        JoinGroupNode whereClause = 
(JoinGroupNode)subqueryBase.getWhereClause();
        whereClause.setProperty(QueryBase.Annotations.PROJECTION, 
subqueryBase.getProjection());
    });
  
  Though here we might also need some additional handling for LabelService 
inside of nested clauses.
  
  Created changeset 
https://gerrit.wikimedia.org/r/#/c/wikidata/query/rdf/+/508725/
  I had to apply the same changes to pom as T213375 
<https://phabricator.wikimedia.org/T213375> to link with bigdata-rdf-test.

TASK DETAIL
  https://phabricator.wikimedia.org/T153353

EMAIL PREFERENCES
  https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: Igorkim78
Cc: Igorkim78, Aklapper, Smalyshev, hoo, darthmon_wmde, alaa_wmde, joker88john, 
ET4Eva, CucyNoiD, Nandana, NebulousIris, Gaboe420, Versusxo, 
Majesticalreaper22, Giuliamocci, Adrian1985, Cpaulf30, Lahi, Gq86, Baloch007, 
Darkminds3113, Bsandipan, Lordiis, Lucas_Werkmeister_WMDE, GoranSMilovanovic, 
Adik2382, Th3d3v1ls, Ramalepe, Liugev6, QZanden, EBjune, merbst, LawExplorer, 
WSH1906, Avner, Lewizho99, Maathavan, Gehel, _jensen, rosalieper, Jonas, 
FloNight, Xmlizer, jkroll, Wikidata-bugs, Jdouglas, aude, Tobias1984, 
Manybubbles, Mbch331, Krenair
_______________________________________________
Wikidata-bugs mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikidata-bugs

Reply via email to