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

Shortened Dot Notation Paths for Compatibility to MongoDB/CouchDB #24

Closed
pinnecke opened this issue Jul 1, 2019 · 1 comment

Comments

@pinnecke
Copy link
Contributor

commented Jul 1, 2019

Dot Notation Compatibility to MongoDB/CouchDB

Description

Similar to other document stores, elements in carbon files can be referred to by using a dot-notated path. A dot-notated path is the path from a documents root to a particular field, potentially crossing several arrays. A path consists of a series of nodes. A node is either a properties key name, or an index inside an list-container (arrays or columns).

Example
Consider to refer to the value C in the JSON below

{
  "A" : [{"X:":["Y"],"Z":[{"Z2": 123}]}, {"B:":"C"}]
}

Then a dot-notated path to C in MongoDB/CouchDB is A.1.B where A refers to the property with the key A, which maps to an array. Inside this array at the 1st position, there's another objects with a property called B that holds the desired value.

In contrast to typical procedure, the root of a document is not an object in Carbon but an array to have a strong compatibility to the JSON spec. As a consequence. any valid dot-notated path in carbon starts with an array index, i.e., 0.A.1.B for the example above. The reason is that internally, carbons treats the example from a above as an array containing one object with the property A. In JSON notation, internally, carbon stores

[
{
  "A" : [{"X:":"Y"}, {"B:":"C"}]
}
]

This issue is about a slight improvement by shortening dot-notated paths in Carbon with the following shorting rule:

    Whenever an array contains exactly 1 element, its dot-notated path can be empty

As a consequence, 0.A.1.B in carbon could be alternatively written as A.1.B. Likewise, from the above example, Y could be resolved via A.X instead of the full path 0.A.0.X.0., and 123 could be resolved viaA.0.Z.Z2 instead of 0.A.0.Z.0.Z2.

Version and Enviroment

Libcarbon version: 0.3.00.01

GitHub Branch (if needed): feature/docstore/bison or develop later

Implementations

  • src/include/core/bison/bison-dot.h that interprets a dot-notated user string into an internal format
  • src/include/core/bison/bison-path.h the path evaluator that must be modified to implement the shorting
@pinnecke

This comment has been minimized.

Copy link
Contributor Author

commented Aug 14, 2019

Done with commit 77f0a08

@pinnecke pinnecke closed this Aug 14, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.