Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

IPLD Selector #12

Open
jbenet opened this issue May 29, 2015 · 13 comments
Open

IPLD Selector #12

jbenet opened this issue May 29, 2015 · 13 comments

Comments

@jbenet
Copy link
Member

jbenet commented May 29, 2015

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

  • Would be nice to use globbing <path>/*/**
  • Would be nice to use git revs <path>~10 <path>~10:<path>~5
  • Would be nice to use patterns <path>/foo*/*bar*
  • Would be crazy to use regex <path>/[a-z]+ ...
  • May we should just use XPath.

links:

@ion1
Copy link

ion1 commented Dec 5, 2015

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
Copy link
Member Author

jbenet commented Dec 6, 2015

more desired expressions:

  • $ref/* - one level under $ref
  • $ref/** - everything under $ref
  • $ref/parent/parent/txn/10 - specific nodes
  • $ref/movie.mp4/(chunks/0)+/* - selects a left-leaning subgraph
  • $ref1/$($ref2/followers/20/username) - sub-expressions-- uses product of one selection in another

@jbenet
Copy link
Member Author

jbenet commented Dec 6, 2015

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

and nice AST

@jbenet
Copy link
Member Author

jbenet commented Feb 20, 2016

it is looking like XPath has the wanted functionality here.

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

@jbenet
Copy link
Member Author

jbenet commented Feb 20, 2016

XPath pros:

  • already exists
  • tons of tutorials + help
  • powerful + expressive
  • path-oriented (css and json selectors are not path-oriented)
  • the simple cases, are very straight forward and readable

XPath cons:

  • it is very complex
  • no clear simpler subset to run in the common case.

XPath Questions:

  • are implementations in Golang and JS XML specific? or parse tree specific?
  • would be easy or absurdly hard to adapt an XPath resolver module to take in a graph we give it (i.e. not built from XML)
  • do we prefer css selectors instead??? they have problems too.

@jbenet
Copy link
Member Author

jbenet commented Feb 20, 2016

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

@jbenet
Copy link
Member Author

jbenet commented Feb 21, 2016

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
Copy link

mildred commented Feb 22, 2016

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
Copy link
Member Author

jbenet commented Apr 11, 2016

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

@jbenet jbenet changed the title dag path notation IPLD Selector Apr 11, 2016
@jbenet
Copy link
Member Author

jbenet commented Apr 11, 2016

interesting thought: graphql.org

@qxotk
Copy link

qxotk commented Apr 11, 2016

Seems like xpath from xslt might be informative


james mcfarland
[email protected]
www.jamesmcfarland.com
On Apr 11, 2016 04:23, "Juan Benet" [email protected] 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
#12 (comment)

@jbenet
Copy link
Member Author

jbenet commented Apr 16, 2016

TODO eval

  • json path
  • json pointer

@nicola
Copy link
Member

nicola commented Jul 22, 2016

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.

ipfs-inactive/2016-IPFS-Workshop-Lisbon#5

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

No branches or pull requests

6 participants