Implement DataQuery
For now, the DataQuery class includes the listKeys method, which will be
used in the parser for tab-completion of values of keys.
The listKeys method uses similar arguments as many methods from the
Schema interface do. This is due to how parsing works: when I parse
lists I won't get the full list instance until all keys are typed.
That's why I can't get the full path to the list: it can't be a full
data path until all keys are known.
I tried many different return types of the method. The first iteration
used just a string to string map. That didn't work well, because
discarding type info meant that I needed to quote strings in THIS
method. And that didn't go well when trying to integrate this to the
parser, because I couldn't compare quoted strings with unquoted strings.
The next return type I tried - a set of string to leaf_data_ maps - was
better. It doesn't discard type info and that makes it possible to
compare in the parser. However, I didn't really make use of an ordered
container, so I changed the type to a vector.
The various implementations of this method were pretty straightforward.
They usually just retrieved all the instances from the datastore with
DatastoreAccess::getItems and then used some sort of an algorithm to
transform the instances into the desired return type. However, there was
a problem with this approach: it is difficult to get ONLY the instances,
and no other data. This means that it is unsuitable to use getItems for this, because:
a) it always works recursively
b) even if it didn't Netconf would still give me more data than I
wanted.
It is possible to create an XML filter, so that no data has to be
discarded, but it's only possible in Netconf and not sysrepo. This
difference is going to be (hopefully) removed with sysrepo2. I decided
to implement a datastore-specific method, where both sysrepo and netconf
use their own best implementation.
Change-Id: I2c978762d3a78286b4f7fb97e16118772ddeb7bc
diff --git a/tests/example-schema.yang b/tests/example-schema.yang
index d993781..a7ff3d8 100644
--- a/tests/example-schema.yang
+++ b/tests/example-schema.yang
@@ -2,6 +2,10 @@
prefix aha;
namespace "http://example.com";
+ import other-module {
+ prefix other;
+ }
+
leaf leafUInt8 {
type uint8;
}
@@ -127,4 +131,68 @@
}
rpc noop {}
+
+ list selectedNumbers {
+ key 'value';
+ leaf value {
+ type int8;
+ }
+ }
+
+ list animalWithColor {
+ key 'name color';
+ leaf name {
+ type string;
+ }
+ leaf color {
+ type string;
+ }
+ }
+
+ list ports {
+ key 'name';
+ leaf name {
+ type enumeration {
+ enum A;
+ enum B;
+ enum C;
+ enum D;
+ enum E;
+ }
+ }
+ }
+
+ list org {
+ key 'department';
+ leaf department {
+ type string;
+ }
+
+ list people {
+ key 'name';
+ leaf name {
+ type string;
+ }
+
+ list computers {
+ key 'type';
+ leaf type {
+ type enumeration {
+ enum PC;
+ enum laptop;
+ enum server;
+ }
+ }
+ }
+ }
+ }
+
+ augment "/other:parking-lot" {
+ list cars {
+ key 'id';
+ leaf id {
+ type int32;
+ }
+ }
+ }
}