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

SPARQLStore: Use SPARQLWrapper for updates #397

Merged
merged 6 commits into from
Aug 26, 2014
Merged

Conversation

uholzer
Copy link
Contributor

@uholzer uholzer commented May 24, 2014

SPARQLStore was using its own implementation to send SPARQL Update requests.
I modified it to use SPARQLWrapper's update mechanism as it already does for queries.

Remaining problems to sort out before merge:

  • SPARQLWrapper does not allow to choose whether to send an update as application/x-www-form-urlencoded or as application/sparql-update. Since this has been possible with SPARQLStore, this currently breaks backwards compatibility of the API. See also Choose Content-type for Update Requests sparqlwrapper#28
  • I would have liked to get rid of the classes NSSPARQLWrapper and TraverseSPARQLResultDOM, but SPARQLWrapper doesn't seem to have similar capabilies.

fixes #392

New versions of SPARQLWrapper now support SPARQL updates too. Therefore
the methods inherited from SPARQLWrapper should be used for updates
instead of building the request manually.

Drawback:
The user can no longer set whether to send updates as
application/sparql-update or application/x-www-form-urlencoded.
This feature should be introduced in SPARQLWrapper and the old
behavoiur in SPARQLStore restored.
Mainly, we don't need to handle our own connection anymore. The
keep alive option of SPARQLWrapper is activated. Some other small
changes to improve consistency.
Removed empty/unnecessary comments and improved existing one.
@bcogrel
Copy link
Contributor

bcogrel commented Jun 14, 2014

Cool, so we will be able to use setCredentials() for updates (fixes #343).

However, I noticed a bug when making a CREATE query:

graph.update("CREATE GRAPH <urn:graph>")

This query is not treated like a SPARQL Update query but is sent to the query endpoint as follows:

15:15:29 INFO  [1] POST http://localhost:3030/ukpp/query
15:15:29 INFO  [1]   Host                 localhost:3030
15:15:29 INFO  [1]   Accept               application/sparql-results+xml
15:15:29 INFO  [1]   Content-Length       76
15:15:29 INFO  [1]   Content-Type         application/x-www-form-urlencoded
15:15:29 INFO  [1]   Connection           close
15:15:29 INFO  [1]   User-Agent           sparqlwrapper 1.6.0 (http://sparql-wrapper.sourceforge.net/)
15:15:29 INFO  [1]   Accept-Encoding      identity
15:15:29 WARN  SPARQL Query: Unrecognize request parameter (ignored): results
15:15:29 INFO  [1] Query = 


CREATE GRAPH <urn:graph>
15:15:29 INFO  [1]   Access-Control-Allow-Origin *
15:15:29 INFO  [1]   Server               Fuseki (1.0.1)
15:15:29 INFO  [1] 400 Parse error: 


CREATE GRAPH <urn:graph>
Encountered " "create" "CREATE "" at line 3, column 1.
Was expecting one of:
    "base" ...
    "prefix" ...
    "select" ...
    "describe" ...
    "construct" ...
    "ask" ...
     (53 ms) 

Instead of (with the current implementation)

15:17:11 INFO  [1] POST http://localhost:3030/ukpp/update
15:17:11 INFO  [1]   Host                 localhost:3030
15:17:11 INFO  [1]   Content-Length       40
15:17:11 INFO  [1]   Content-Type         application/x-www-form-urlencoded; charset=UTF-8
15:17:11 INFO  [1]   Connection           keep-alive
15:17:11 INFO  [1]   Accept-Encoding      identity
15:17:11 INFO  [1] Form update = 

CREATE GRAPH <urn:graph>
15:17:11 INFO  [1]   Content-Type         text/html
15:17:11 INFO  [1]   Access-Control-Allow-Origin *
15:17:11 INFO  [1]   Server               Fuseki (1.0.1)
15:17:11 INFO  [1] 200 OK (85 ms) 

@wikier
Copy link
Member

wikier commented Jun 14, 2014

guys, feel free to push to SPARQLWrapper whatever missing feature required for a better integration

@bcogrel
Copy link
Contributor

bcogrel commented Jun 14, 2014

Ok, I have submitted a pull request RDFLib/sparqlwrapper#29 to fix the regression I have mentioned.

@wikier
Copy link
Member

wikier commented Jun 15, 2014

great, pull request RDFLib/sparqlwrapper#29 merged on master

@bcogrel
Copy link
Contributor

bcogrel commented Jun 15, 2014

Thanks!

@uholzer
Copy link
Contributor Author

uholzer commented Jun 29, 2014

As I see, RDFLib/sparqlwrapper#28 is the only remaining issue wee have to address?

@bcogrel
Copy link
Contributor

bcogrel commented Jun 29, 2014

A priori, yes. But I cannot fully tested this branch because it does not include recent commits of the master branch (named graph support).

Support for named graphs in the SPARQLUpdateStore is required for
further development.

Conflicts:
	rdflib/plugins/stores/sparqlstore.py
@uholzer
Copy link
Contributor Author

uholzer commented Jul 4, 2014

There you go.

@bcogrel
Copy link
Contributor

bcogrel commented Jul 6, 2014

Thanks.

Ok, no problem detected while running the unittests of OldMan with Fuseki (mem and TDB) on Python 2.7. Looks good.

Thanks to the newly introduced method `setUpdateMethod` of the
SPARQLWrapper, the user can again choose whether to send SPARQL Updates
as `application/sparql-update` or as `application/x-www-form-urlencoded`.
@uholzer
Copy link
Contributor Author

uholzer commented Jul 20, 2014

Clearly, the travis build is failing because the spaqlstore tries to import newly introduced symbols from SPARQLWrapper which are not available in the latest release. The error message is a bit misleading as it claims that SPARQLWrapper is not installed at all. (Maybe I should make the import warning more clear or remove it entirely.)

Question is, what to do now? Wait with merging until the next release of SPARQLWrapper is published?

@wikier
Copy link
Member

wikier commented Jul 20, 2014

Sorry guys, as soon as we'll fix RDFLib/sparqlwrapper#17 release 1.6.1 will be out to not block this anymore.

@wikier
Copy link
Member

wikier commented Jul 21, 2014

SPARQLWrapper 1.6.1 has been released, but you should update this PR to reflect the last-minute changes introduced by RDFLib/sparqlwrapper#28

Please, let us know any issue with this feature or with any other you might need.

This should work with SPARQLWrapper 1.6.1.
@uholzer
Copy link
Contributor Author

uholzer commented Jul 26, 2014

Unfortunately, RDFLib/sparqlwrapper#35 causes trouble.

@wikier
Copy link
Member

wikier commented Jul 27, 2014

@uholzer that should be the single change, right. I preferred to do a last-minute change than deprecate the api later. Sorry.

@uholzer
Copy link
Contributor Author

uholzer commented Aug 25, 2014

Okay. This works now together with the master branch of SPARQLWrapper thanks to @indeyets and @wikier. Once a new release of SPARQLWrapper has arrived, I will hit the merge button.

uholzer added a commit that referenced this pull request Aug 26, 2014
SPARQLStore: Use SPARQLWrapper for updates

SPARQLStore was using its own implementation to send SPARQL Update requests.
Now, it uses SPARQLWrapper's update mechanism in the same way it already uses its query mechanism.
@uholzer uholzer merged commit af717b7 into master Aug 26, 2014
@uholzer
Copy link
Contributor Author

uholzer commented Aug 26, 2014

Finally, its done. Thanks to everyone involved!

@uholzer uholzer deleted the sparqlstore-sparqlwrapper branch August 26, 2014 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SPARQLUpdateStore should use SPARQLWrapper instead of custom httplib.HTTPConnection
5 participants