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

Subquery Bug with GROUP BY and Variable Bindings in Corese Kernel #17

Open
remiceres opened this issue Oct 22, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@remiceres
Copy link
Contributor

Olivier identified a bug in the Corese kernel, occurring when using subqueries with a GROUP BY clause and passing variable bindings. The issue arises because executing the triple ?x ns:p ?y either before or after the subquery produces inconsistent results.

Reproduction Steps:

  1. Query:

    prefix ns: <http://ns.inria.fr/test/>
    
    select * where {
        ?x ns:p ?y
        {
            select ?x (count(*) as ?c)
            where {
                ?x ns:q ?z
            } group by ?x
        }
        #?x ns:p ?y
    }
  2. Dataset:

    prefix ns: <http://ns.inria.fr/test/>
    
    ns:a ns:p ns:b .
    ns:c ns:q ns:d .

Proposed Fix:

Olivier suggests modifying the queryNodeList function in the Exp class to resolve the issue by adjusting the handling of node lists when subqueries are involved.

void queryNodeList(ExpHandler h) {
    List<Node> selectList    = h.getSelectNodeList();
    List<Node> subSelectList = getQuery().getSelect(); //getSelectNodeList();
   
    if (h.isInSubScope()) {
        // focus on left optional etc. in query body
        // because select * includes right optional etc.
        List<Node> scopeList = getQuery().getBody().getTheNodes(h.copy());
        for (Node node : scopeList) {
            if (subSelectList.contains(node)) {
                if (! contain(getQuery().getGroupBy(), node)) {
                    add(selectList, node);
                }
            }
        }
    } else {
        for (Node node : subSelectList) {
            if (! contain(getQuery().getGroupBy(), node)) {
                add(selectList, node);
            }
        }
    }
}

Possible Side Effects:

This fix may impact performance, as it prevents passing the binding of the GROUP BY variable (in this case, ?x), which could lead to reduced optimization.

I also noticed that the testLetQuery in TestQuery1 fails with a StackOverflow error after applying this change. Further analysis is needed to evaluate the consequences of this modification.

@remiceres remiceres added the bug Something isn't working label Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant