Skip to content

Implement SPARQL-based DataAccessor - #279

Merged
jvherweg merged 5 commits into
masterfrom
smessie-sparql-resource-store
Nov 2, 2020
Merged

jvherweg merged 5 commits into
masterfrom
smessie-sparql-resource-store

Conversation

@jvherweg

Copy link
Copy Markdown
Member

Continuation of #72 (new branch).

Part of #59 and resolves #220.

2 parts to this

  • SparqlDataAccessor using a SPARQL store to store incoming data and metadata.
  • FixedConvertingStore which converts any incoming data to one of the supported types if required. This is necessary so we can produce the Quads necessary for the SparqlDataAccessor.

Some notes:

Very open to better names than FixedConvertingStore.

We now have a RepresentationConvertingStore which converts outgoing data, and a FixedConvertingStore which converts incoming data. While they are similar there are still some differences. For the outgoing data it is based on the user preferences while for incoming it is a fixed list. The position of where we want them is different: we want to convert all outgoing data but only some incoming data (will be relevant when the other part if #59 is implemented: storing RDF data in a SPARQL backend and other binary data in a file store).

We could also have a single converting store class which would then take booleans as input to know which parts it has to support. We still would need 2 instances though so that doesn't seem cleaner. If the new store should also store preferences instead of types they both could have the same superclass if they need similar helper functions.

Integration tests are an issue. Since this needs a SPARQL store there is no easy way to add this to the currently existing integration tests. I did the tests by running my own triple store locally (and changing the tests so they use turtle instead of text/plain) which is how I know they work (and how I discovered some issues such as the metadata for the root container), but for having actual integration tests we would need a SPARQL store dependency (Comunica?) which seems quite heavy just for these tests.

@jvherweg jvherweg added the ☀️ enhancement New feature or request label Oct 21, 2020

@rubensworks rubensworks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After reading the code, I'm still wondering what will happen for triples in the non-default graph. Will this break things? Might be good to add unit tests and/or explicit checks for this.

for having actual integration tests we would need a SPARQL store dependency (Comunica?)

I don't think this is a big problem, since this would just be a dev dependency. Also, this would only be possible once we finish implementing update support in Comunica.

Comment thread src/storage/FixedConvertingStore.ts Outdated

public async addResource(container: ResourceIdentifier, representation: Representation,
conditions?: Conditions): Promise<ResourceIdentifier> {
// We can potentially run into problems here if we convert a turtle document where the base IRI is required,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would create an issue for this once the PR is merged.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, will probably stay there for a while because I have no idea how to cleanly solve this 😄

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dummy IRI that is replaced later.

Comment thread src/storage/FixedConvertingStore.ts Resolved
@jvherweg

Copy link
Copy Markdown
Member Author

After reading the code, I'm still wondering what will happen for triples in the non-default graph. Will this break things? Might be good to add unit tests and/or explicit checks for this.

True, I forgot to add a check for this. What will currently happen is that they would all be put in the default graph but we should just error instead.

@jvherweg
jvherweg force-pushed the smessie-sparql-resource-store branch from 66662ce to c86eae9 Compare October 21, 2020 14:31

@RubenVerborgh RubenVerborgh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be merged for me, but I don't like FixedConvertingStore. That could possibly be addressed in another issue though.

Comment thread src/storage/FixedConvertingStore.ts Outdated

public async addResource(container: ResourceIdentifier, representation: Representation,
conditions?: Conditions): Promise<ResourceIdentifier> {
// We can potentially run into problems here if we convert a turtle document where the base IRI is required,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dummy IRI that is replaced later.

Comment thread src/storage/FixedConvertingStore.ts Outdated
@@ -0,0 +1,45 @@
import type { Representation } from '../ldp/representation/Representation';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was actually a bit surprised to see this class, really. Don't we have a RepresentationConvertingStore already?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So on closer inspection, I was surprised that RepresentationConvertingStore only covers getRepresentation. But I get why.

I think we should extend RepresentationConvertingStore to also cover addResource and setRepresentation, and perform the steps below.

Then we can either a) only load the needed convertors (which acts as a filter) or b) have a ConditionalConverter.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had missed the intro text to this PR, so which is crucial to this point. So let me react:

For the outgoing data it is based on the user preferences while for incoming it is a fixed list.

Not necessarily though. A fixed list can indeed be an approximation / workable definition, or we can just reuse the same preference-based mechanism. But yeah, point taken.

We could also have a single converting store class which would then take booleans as input to know which parts it has to support. We still would need 2 instances though so that doesn't seem cleaner.

Yeah, not cleaner indeed, and I don't like the booleans.

But how about changing RepresentationConvertingStore to have in[coming]Convertors and out[going]Convertors? And if you set convertors, it just works for both?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily though. A fixed list can indeed be an approximation / workable definition, or we can just reuse the same preference-based mechanism.

The problem is that there are no preferences for PUT/POST requests. Unless you mean taking a preferences list as input. That would be no issue since the fixed list gets converted to preferences anyway before sending it to the converter.

But how about changing RepresentationConvertingStore to have in[coming]Convertors and out[going]Convertors? And if you set convertors, it just works for both?

Two points/"issues" with this:

  • This store needs to appear twice in our "store chain". Once to convert all outgoing data, once to convert all data that gets directed to the sparql store. This means we would need 2 instances of this class since they would have a different source store they continue the request to.
  • It would need constructor parameters for both functionalities. So the constructor would be something like constructor(source: ResourceStore, inConverter: RepresentationConverter, outConverter: RepresentationConverter, inPreferences: string[])

But both instances would only use half of that input, which is why I suggested perhaps having an abstract class that contains their common functions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless you mean taking a preferences list as input.

Yes indeed.

  • This store needs to appear twice in our "store chain".

I think that's okay; that's just specific to our chain then. Others might be different.

  • So the constructor would be something like

It would actually be

constructor(source: ResourceStore, {
    convertor?: RepresentationConverter,
    inConverter?: RepresentationConverter = convertor,
    outConverter?: RepresentationConverter = convertor,
    inPreferences?: string[] = [],
})

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't have type initializers in an object unfortunately so I'm just going to drop the convertor parameter from it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No default params? Argh. Or set in constructor. But yeah, no biggie.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also did the constructor, but there you can't combine the optional ? thingy with initializers, which caused the typing to be RepresentationConverter | undefined, which caused it be 3 lines, etc. 😂

@RubenVerborgh

Copy link
Copy Markdown
Member

Integration tests are an issue. Since this needs a SPARQL store there is no easy way to add this to the currently existing integration tests.

They could be system tests for Travis, where we just Docker in a SPARQL endpoint.

@jvherweg jvherweg mentioned this pull request Oct 26, 2020
@jvherweg
jvherweg force-pushed the smessie-sparql-resource-store branch 2 times, most recently from 78bddad to 2a5de5e Compare October 30, 2020 14:43
@jvherweg

Copy link
Copy Markdown
Member Author

PR should be done now, but blocked by LinkedSoftwareDependencies/Components-Generator.js#44 . Depending on how difficult the fix is there I might have to change the implementation here to be ready for the demo.

@RubenVerborgh

Copy link
Copy Markdown
Member

Rebased on master, since I wanted to try some test ideas.

@jvherweg
jvherweg force-pushed the smessie-sparql-resource-store branch from 6f72a62 to 740509b Compare November 2, 2020 13:53
@jvherweg

jvherweg commented Nov 2, 2020

Copy link
Copy Markdown
Member Author

PR has been changed to now have a constructor not conflicting with Components.js . Will create relevant issues to change this at a later time.

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.

Support triple stores as stores

4 participants