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

How to process transformations on a container #35

Closed
matthieu-fesselier opened this issue Sep 5, 2019 · 8 comments
Closed

How to process transformations on a container #35

matthieu-fesselier opened this issue Sep 5, 2019 · 8 comments
Labels
question Further information is requested

Comments

@matthieu-fesselier
Copy link

For the needs of startinblox, we need to process some transformations on a container to sort, filter, group... resources.

To do this, we recreate an array of resources from the AsyncIterator returned by query-ldflex to perform the transformations.
We have two main concerns with this approach:

  • it's complicated to use native javascript functions on the arrays like sort, filter because of the asynchronous proxies
  • it's probably not a good practice to recreate an object from an already existing one.

Is there a smarter way to handle this?

@RubenVerborgh
Copy link
Member

You will probably like https://www.npmjs.com/package/iter-tools 🙂

@RubenVerborgh RubenVerborgh added the question Further information is requested label Sep 5, 2019
@matthieu-fesselier
Copy link
Author

Thanks, it sounds interesting! I'll take a look ;)

@RubenVerborgh
Copy link
Member

Feel free to reopen if you don't find what you need!

@matthieu-fesselier
Copy link
Author

I added iter-tools to startinblox and it fits almost all my needs. The only problem I face is that I can't sort a list of resource, because of the asynchronicity of the proxies (see iter-tools/iter-tools#286)
Should the sort feature be added to query-ldflex as a parameter? I guess it make sense to sort resources before creating an iterator?

@rubensworks
Copy link
Contributor

Sorting may indeed be valuable, as this could be pushed down to the SPARQL level by LDflex.

@RubenVerborgh
Copy link
Member

RubenVerborgh commented Sep 10, 2019

Good idea; tracking sorting in LDflex/LDflex#41.

Note however that, in several case, sorting makes operations blocking, i.e., you receive all of them at the end instead of incrementally. So this is why we, by default, prefer to leave it to the consumer to perform sorting. For instance, if you are feeding a UI, you could take unsorted results and then insert them in the right place as they arrive. But that all depends on the use case.

As iter-tools also says:

For example: sorting, shuffling and in general all operations that rely on having the full array at your disposal. In that case the way to go is to convert the iterable in an array and use that.

So you could do https://www.npmjs.com/package/iter-tools#to-array and take it from there for now?

Or, for your specific case, map to sorting keys (asynchronously) and then sort?

@matthieu-fesselier
Copy link
Author

Yes the solution would be to re-create an array with the sorting key and then sort the resources. This was our last choice but I think this is the only one possible for now

@RubenVerborgh
Copy link
Member

Sorting landed via LDflex/LDflex#43.

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

No branches or pull requests

3 participants