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

count(*) seems to break the SPARQLPLUSPARSER #63

Closed
coreation opened this issue Apr 16, 2014 · 7 comments
Closed

count(*) seems to break the SPARQLPLUSPARSER #63

coreation opened this issue Apr 16, 2014 · 7 comments

Comments

@coreation
Copy link
Contributor

Hi all,

Upon performing the following query:

select (count(*) AS ?count) WHERE { ?s ?p ?o }

The SPARQLPLUSPARSER break, and throws an error that it cannot find an column value with key 'value'. After further investigation, I've come to the line where this is thrown which is line 51 (ish) in the corresponding php file of SPARQLPLUSPARSER.

After some debugging, I couldn't find what went wrong, but the value key wasnt present. This made me try the following work around, inspired by the comment that stands above the if which was "* or var" :

/* * or var */
    if ((list($sub_r, $sub_v) = $this->x('\*', $v)) && $sub_r) {

//[START WORKAROUND]
      // The regex fails to parse * from the count(*) as a selector
      $val = '*';

      if (!empty($sub_r['value'])) {
        $val = $sub_r['value'];
      }
// [END WORKAROUND]
      return array(array('var' => $val, 'aggregate' => $aggregate, 'alias' => $aggregate ? $result_var : ''), $sub_v);
    }

Does anyone have an idea if this might break other things, I'm going to try some queries with this workaround, also non * selectors. In any case, I'll do a fork and do my queries through the fork. If this is a valid bug, and this (sorta) solves it. I'd be happy to provide a pull request.

@bnowack
Copy link
Collaborator

bnowack commented Apr 17, 2014

Wow, how could that go unnoticed for so long...
Could you try wrapping the *-regex in parentheses? That should be the fix I think:

if ((list($sub_r, $sub_v) = $this->x('(*)', $v)) && $sub_r) {

@coreation
Copy link
Contributor Author

Hi @bnowack , no idea how that went on for so long ;) The fix sorta works in that it returns an array with "*" as a value in it, however it's not mapped to the key "value", which is called in the next line. It currently sits in the first value, making me think that it just gets there because of the preg_match function (index 1 = first match?)

I'm not sure what I should change now, because the function x() is heavily used, so tinkering with it seems a big "nono". So probably something needs to be changed in the line where that "value" index is used?

@bnowack
Copy link
Collaborator

bnowack commented Apr 17, 2014

The $sub_r doesn't really make any sense there, to be honest. I've pushed a tweak, want to give it a try?
Thanks!

@coreation
Copy link
Contributor Author

That seems to do the trick yes ;).

@coreation
Copy link
Contributor Author

Unrelated to this issue, but not wanting to create another issue When retrieving triples from the arc2 store, it's basically an assoc. array. How does one serialize this into a turtle or other structures, or even better, put this back into a arc2 graph? I don't seem to find this in the documentation :).

@bnowack
Copy link
Collaborator

bnowack commented Apr 22, 2014

When you use a query that uses ?s ?p ?o (i.e. SELECT ?s ?p ?o WHERE ...) then you can use the result array ($queryResult['result']['rows']) as a typical ARC structure that can be serialized.

@bnowack bnowack closed this as completed Apr 22, 2014
@coreation
Copy link
Contributor Author

Ah, that's what I initially thought but hadn't found the time yet to test it out. Thanks a bunch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants