ipfs / notes

IPFS Collaborative Notebook for Research
MIT License
402 stars 30 forks source link

IPLD Selector #12

Open jbenet opened 9 years ago

jbenet commented 9 years ago

It is ideal to have a path notation (for use in bitswap and other tools) that allows expressing ranges of objects and queries.

links:

ion1 commented 8 years ago

It might be good to design the path traversals as an abstract syntax tree first. They are easy to create and manipulate in programming languages (without invoking a parser in runtime) and they are what binary (de)serializers input/output.

When the perfect AST structure is established, that would be a good time to specify a corresponding regexp/glob/XPath-like notation. Since the AST is already set in stone, no character that is ordinary now and does not need to be escaped in path components will become special later and silently break existing expressions.

(Alternatively, specify a “multitraversal” notation which indicates its version.)

Here’s pseudocode for the AST data types for some of the traversals that would be nice to have. This should map to actual code in any modern programming language rather trivially.

data Pattern = Pattern Reference [Traversal]

data Traversal = Glob [Glob]
               | RecursiveStar
               | Count Natural [Traversal]
               | CountMin Natural [Traversal]
               | Dereference Pattern

data Glob = Literal String
          | Star

Some pseudocode expressions using the data types defined above:

Pattern ref []

Pattern ref [Glob [Star]]

Pattern ref [RecursiveStar]

Pattern ref [Glob [Star], "bar", RecursiveStar]

Pattern ref [Glob ["foo", Star], Glob [Star, "bar", Star]]

Pattern ref [Count 10 ["parent"], "foo"]

Pattern ref ["movie.mp4", CountMin 1 ["chunks", "0"], Glob [Star]]

Pattern ref1 [Dereference (Pattern ref2 ["followers", "20", "username"])]
jbenet commented 8 years ago

more desired expressions:

jbenet commented 8 years ago

@ion1 haha i posted these before i read your examples-- nice!

and nice AST

jbenet commented 8 years ago

it is looking like XPath has the wanted functionality here.

Wonder if there is an XPath subset that's way simpler.

jbenet commented 8 years ago

XPath pros:

XPath cons:

XPath Questions:

jbenet commented 8 years ago

cc @mildred thoughts? think go-ipld could support this?

jbenet commented 8 years ago

Or do we use JSONPath? http://goessner.net/articles/JsonPath/ https://jsonpath.curiousconcept.com/

likely JSONPath wont work with all the things we may have in ipld?

mildred commented 8 years ago

The problem I have with XPath is that it is designed to work on XML document semantic. Those have attributes, nodes and a few other oddities that XPath can query. Moreover, it is quite complex.

JSONPath seems better to me. It fits the data model more closely. We will probably want to extend it to be able to traverse merkle links. We could use / that doesn't seems to be used in JSONPath.

JSONPath doesn't specify a language for expressions. We might want to define a common language for all implementations.

jbenet commented 8 years ago

cc @nicolagreco this is the "IPLD Selector" placeholder issue. we should discuss it more here.

jbenet commented 8 years ago

interesting thought: graphql.org

qxotk commented 8 years ago

Seems like xpath from xslt might be informative


james mcfarland james@jamesmcfarland.com www.jamesmcfarland.com On Apr 11, 2016 04:23, "Juan Benet" notifications@github.com wrote:

cc @nicolagreco https://github.com/nicolagreco this is the "IPLD Selector" placeholder issue. we should discuss it more here.

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/ipfs/notes/issues/12#issuecomment-208223422

jbenet commented 8 years ago

TODO eval

nicola commented 8 years ago

We are going to have a conversation in Lisbon during the IPFS workshop, this document is listing some points that may be relevant to the conversation. Once the conversation is done, I am going to do a write up.

https://github.com/ipfs/2016-Q3-Workshop/issues/5