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

Replacement of # separator for fragments in the Selector #53

Closed
JEnoch opened this issue Nov 13, 2020 · 5 comments
Closed

Replacement of # separator for fragments in the Selector #53

JEnoch opened this issue Nov 13, 2020 · 5 comments

Comments

@JEnoch
Copy link
Member

JEnoch commented Nov 13, 2020

Rational

We need to replace the usage of # as separator for fragments in Selector because most of the web client won't send the fragment part of the URL to the zenoh HTTP plugin.

Detail

The current (in 0.5.0-beta.5) specification of a zenoh Selector is the following:

/s1/s2/.../sn?x>1&y<2&...&z=4(p1=v1;p2=v2;...;pn=vn)#a;b;x;y;...;z
|           | |             | |                   |  |           |
|-- expr ---| |--- filter --| |---- properties ---|  |--fragment-|

where:

  • expr: is a Path Expression (e.g.: /demo/example/**)
  • filter: a list of predicates separated by '&' allowing to perform filtering on the values
    associated with the matching keys. Each predicate has the form "field-operator-value" value where:
    • field is the name of a field in the value (is applicable and is existing. otherwise the predicate is false)
    • operator is one of a comparison operators: < , > , <= , >= , = , !=
    • value is the the value to compare the field’s value with
  • fragment: a list of fields names allowing to return a sub-part of each value. A.k.a. a projection in the mathematical sense of the term.
    This feature only applies to structured values using a “self-describing” encoding, such as JSON or XML.
    It allows to select only some fields within the structure. A new structure with only the selected fields
    will be used in place of the original value.

For instance, if we imagine GPS coordinates of objects stored zenoh's time-series storages, under an undetermined hierarchy prefixed by /demo/example/, this Selector:
/demo/examples/**/GPS-coordinate?lat>0(starttime=now()-1h)#lat;long;name
will retrieve all the GPS data of objects in the north hemisphere (lat>0) within the last hour (starttime=now()-1h) and for each data only the latitude, the longitude and the name should be returned.

A Selector can easily be used to get path/values from zenoh via the HTTP plugin, simply prepending the selector with the base URL of a zenoh router. E.g.:
http://localhost:8000/demo/examples/**/GPS-coordinate?lat>0(starttime=now()-1h)#lat;long;name
However, the majority of HTTP clients (web browsers, curl...) never send the fragment part of the URL (starting from #) to the web server (the zenoh HTTP plugin in our case). As a consequence, a web client won't be able to request only sub-parts of data.

@JEnoch
Copy link
Member Author

JEnoch commented Nov 13, 2020

For coherency with the zenoh API where the Selector is the only parameter used in a get() operation, we want to keep the expression of the projection within the Selector. And within in the URL for HTTP (not in a HTTP header).

The only parts from the URL that are sent by a web client to the server are the scheme, the authority, the path and the query. As the URL's path correspond to the Selector's path expression, only the query can be used for the projection. And we need to distinguish it from the filter and properties parts.

Considering the RFC-3986 section on URI reserved characters:

      reserved    = gen-delims / sub-delims
      gen-delims  = ":" / "/" / "?" / "#" / "[" / "]" / "@"
      sub-delims  = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="

"The purpose of reserved characters is to provide a set of delimiting characters that are distinguishable from other data within a URI."
...
"Thus, characters in the reserved set are protected from normalization and are therefore safe to be used by scheme-specific and producer-specific algorithms for delimiting data subcomponents within a URI."
I think one (or 2) of those reserved character shall be used.

Proposals distinguish the projection part within the query part:

  • [ ] surrounded.
    • pros: similar to ( ) surrounding the properties
    • cons: we could consider to use those in filter to test the nth value of a list. E.g.: /demo/example/**?my_list[0]>1
  • @ as separator.
    • pros: unlikely to be used in filter or properties. But should be percent-encoded (%40) if so.
    • cons: weird...?
  • $ as separator.
    • cons: we could consider to use it for placeholders (similar to env variable). E.g.: /demo/example/**?x>$LIMIT where the value of $LIMIT could be retrieved from a specific path in zenoh (e.g. /env/LIMIT)

@JEnoch
Copy link
Member Author

JEnoch commented Nov 13, 2020

@kydos, @OlivierHecart , @Mallets
My vote goes for [ ]. But feel free to give your opinion and/or make other suggestions.

@heyong4725
Copy link

My vote goes for [ ] as well:)

@kydos
Copy link
Member

kydos commented Nov 16, 2020

+1

@Mallets
Copy link
Member

Mallets commented Nov 16, 2020

+1 for [ ]

@JEnoch JEnoch closed this as completed in 4178e17 Dec 15, 2020
JEnoch added a commit to eclipse-zenoh/zenoh-plugin-webserver that referenced this issue Dec 15, 2020
JEnoch added a commit to eclipse-zenoh/zenoh-python that referenced this issue Dec 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants