[Solved] Defining Key Expressions #24
Replies: 6 comments 24 replies
-
Proposal 1:Under this proposal, ValidityThe criterion for syntactic validity is BOTH the absence of illegal patterns AND the canonical form of the expression.
A key belongs to the set defined by a KE iff by replacing all of the KE's Two KEs intersect if there exists at least one key that belongs to both sets. KE A string that doesn't contain illegal patterns may be canonized by steps equivalent to this python code: # Note, this is a very bad algorithm, do not canonize this way!
# This is just a concise way to express canonization.
def canonize(x: str):
pastX = ""
while pastX != x:
pastX = x
x = x.replace("**/**", "**") # note that python's replace method doesn't alter its arguments
if pastX == x:
x = x.replace("**/*", "*/**")
return x A string It is proposed that the default Other constructors may be provided to return errors for non-canon forms, and to unsafely construct From a network standpoint, routers should check incoming KEs for validity before performing any operation, and drop messages with invalid KEs that may have sneaked into the network. Concatenation and path joiningConcatenation and path joining should ensure that the Concatenation is defined as simple string concatenation. Where operator overloading is available, it should be performed by the Path Joining is defined as joining two KEs by a To avoid unexpected behaviors, concatenating a string that starts with Concatenating a string onto a
Extending the KE language through DSLsTo allow the KE language to grow and become more useful without causing breaking changes, Domain Specific Languages may be added to the KE language through updates. DSLs will be inserted into KEs via the DSLs will be presented to the user as a way to address more specific sets of keys than what the base KE language is able to, at the cost of performance. A The first DSL to be introduced will have the ID Note that DSLs will still have to be designed to maintain unicity: for the case of In the future, we hope to provide a new DSL which will offer a subset of regex's functions, but with many questions regarding unicity and canonization, as well as efficient intersection (especially when both KEs contain the regex-ike DSL), this DSL will probably take a long time to develop. |
Beta Was this translation helpful? Give feedback.
-
I generally happy with the proposal, but I have two comments:
|
Beta Was this translation helpful? Give feedback.
-
@p-avital / @Mallets which from the following are not valid KE?
|
Beta Was this translation helpful? Give feedback.
-
In order to bring clarity to
We can extend this if we decide to include DSL or regex. |
Beta Was this translation helpful? Give feedback.
-
After considering the discussions related to the comments under @cguimaraes 's remarks, it has been decided that We're not dropping support for the This introduces the concept of Domain Specific Languages as the future of extending the KE language, which is planned to follow a Note that we plan on introducing subsets of regex's feature set as a DSL, but since unicity is a great propriety for KEs to have, designing such a language is difficult and will take some time. |
Beta Was this translation helpful? Give feedback.
-
RFC available here: https://github.com/eclipse-zenoh/roadmap/blob/main/rfcs/ALL/Key%20Expressions.md |
Beta Was this translation helpful? Give feedback.
-
Key Expressions (KEs) are the representation of Zenoh's address space, but are currently code-defined rather than abstractly defined. This creates confusion (including among the team) as to its expected and true behavior. This discussion's goal is to reach a new definition of KEs that we may then adapt code to fit, while addressing some of the issues that current KEs raise.
Definitions
To be exact, Keys are Zenoh's address space.
Key Expressions is a language that allows to address sets of keys in a compact form.
Any Key is a valid KE that matches only itself (this point is debatable under current implementation, which is one of the issues this discussion seeks to address).
Almost all of Zenoh's directives may be applied to sets of keys equivalently to single keys, so Zenoh's API only works in terms of KEs.
Needs
Looking back at our experience with KEs, here are some of the goals we have set for the new definition of KEs. To simplify possible examples,
cke("...")
andke("...")
denote the construction of aKeyExpr
as currently defined and as proposed respectively, whilecke"..."
andke"..."
denote the resulting values of these constructions.Stringifiability
Currently,
KeyExpr
is shown to the user as a(u64, String)
tuple, where the u64 is aSession
-bound identifier for a prefix, with0
being always bound to""
. This presentation is confusing, may lead to issues for users that may spawn severalSession
s, and not generally useful consideringKeyExpr
that reach user-scope are always resolved by Zenoh so that the prefix is always0
.Our new definition of
KeyExpr
should makekey_expr.as_str()
an infallible and context-independent operation.Unicity
With their current definition, KEs present a subtle trap for users: there exist many strings that are different, but address the exact same set of keys:
cke"a" == cke"/a"
, orcke"/*/**" == cke"/**/*"
are some examples of this. This may lead user-code to misbehave if this isn't accounted for. This is compounded by the fact that we do not offer users a way to check for KE-equivalence.We propose to solve this issue by restricting the KE language by new syntactic rules that ensure that for any set of keys, at most a single KE exists to express it. For examples, under these rules,
ke"/a"
would not be a possible value, withke("/a")
either producing theke"a"
value instead, or yielding an error.Clearly defined syntactic rules
Currently,
KeyExpr
doesn't enforce any of the "rules" that we have set for excluded characters (such as?
), making these more alike to "suggestions". This may lead to odd behaviors as these characters are typically excluded because the have or may take roles in certain operations:?
acts as the separator between KE and arguments in selector-strings.The new definition for KEs should address this by defining a clear set of characters that are forbidden.
Opacity
Currently,
KeyExpr
expose their whole structure to users, despite the fact that modifying this structure currently has no point but creating bugs.The new
KeyExpr
type should be as opaque as possible to allow greater flexibility.Ease of use
Helper functions exist to let the user check KEs for intersection or inclusion, but they are hidden away as raw functions in obscure paths of the
zenoh
crate.The new definition of
KeyExpr
should support common operations such as equality, intersection, comparison and concatenation in a well defined way through methods.Beta Was this translation helpful? Give feedback.
All reactions