Details
-
Improvement
-
Resolution: Fixed
-
Major
-
7.1.0
-
1
Description
Recently Donald Haggart have added the following functions
OBJECT_PATHS()
OBJECT_PAIRS_NESTED()
.....
These functions takes options produce results based on the object.
If we add the additional option say "index" (any alternative names also fine. like "leaf") produce the consistent/uniform results.
These can be used more powerful way in with ARRAY indexing by indexing and querying on any field in the document (replacement of adaptive index with more usage).
- When above option is specified only leaf values produced including arrays, nested object. (i.e. NO ARRAYS, No Objects. Users rarely query on whole ARRAY or objects due to position/name).
- The paths/names produced consistent way always so that we know what to expect. Always use back-tick on fields. no ARRAY subscript or star. instead it produce duplicates with empty array bracket.
Example:
Object
{
|
"a": { |
"b-c": 1 |
},
|
"airline": "AF", |
"airlineid": "airline_003", |
"destinationairport": "SFO", |
"distance": 2481.617376098415, |
"equipment": "320", |
"id": 3, |
"schedule": [ |
{
|
"day": 0, |
"flight": "AF198", |
"utc": "10:13:00" |
},
|
{
|
"day": 1, |
"flight": "AF250", |
"utc": "12:59:00" |
},
|
{
|
"day": 2, |
"flight": "AF223", |
"utc": "19:41:00" |
}
|
],
|
"sourceairport": "DFW" |
}
|
OBJECT_PATHS(obj, {"index":true}) |
[
|
`a`.`b-c`",
|
"`airline`", |
"`airlineid`", |
"`destinationairport`", |
"`distance`", |
"`equipment`", |
"`id`", |
"`schedule`[].`day`", |
"`schedule`[].`flight`", |
"`schedule`[].`utc`", |
"`sourceairport`" |
]
|
|
OBJECT_PAIRS_NESTED(obj,{"index":true}) |
|
[
|
{
|
"name": "`a`.`b-c`", |
"val": 1 |
},
|
{
|
"name": "`airline`", |
"val": "AF" |
},
|
{
|
"name": "`airlineid`", |
"val": "airline_003" |
},
|
{
|
"name": "`destinationairport`", |
"val": "SFO" |
},
|
{
|
"name": "`distance`", |
"val": 2481.617376098415 |
},
|
{
|
"name": "`equipment`", |
"val": "320" |
},
|
{
|
"name": "`id`", |
"val": 3 |
},
|
{
|
"name": "`schedule`[].`day`", |
"val": 0 |
},
|
{
|
"name": "`schedule`[].`flight`", |
"val": "AF198" |
},
|
{
|
"name": "`schedule`[].`utc`", |
"val": "10:13:00" |
},
|
{
|
"name": "`schedule`[].`day`", |
"val": 1 |
},
|
{
|
"name": "`schedule`[].`flight`", |
"val": "AF250" |
},
|
{
|
"name": "`schedule`[].`utc`", |
"val": "12:59:00" |
},
|
{
|
"name": "`schedule`[].`day`", |
"val": 2 |
},
|
{
|
"name": "`schedule`[].`flight`", |
"val": "AF223" |
},
|
{
|
"name": "`schedule`[].`utc`", |
"val": "19:41:00" |
}, {
|
"name": "`sourceairport`", |
"val": "DFW" |
}
|
]
|
How to use with Array indexing
CREATE INDEX ix1 ON bucket (DISTINCT OBJECT_PATHS(self, {"index":true})); |
SELECT * FROM default AS d ANY v IN OBJECT_PATHS(d, {"index":true) SATISFIES v = $p END; |
$p can be any value in the path. ex `schedule`[].`day`
|
It means document has schedule ARRAY of objects and it has at least one day field in the object. single index servers checking any field any level present.
|
|
Once MB-32506 implemented this can even turn more power full
CREATE INDEX ix1 ON bucket (FLATTEN DISTINCT ARRAY [v.name, v.val] FOR v IN OBJECT_PATHS(self, {"index":true}) END ); |
SELECT * FROM default AS d ANY v IN OBJECT_PATHS(d, {"index":true) SATISFIES v.name = $p AND v.val = $v END; |
|
$p can be any value in the path. ex "`a`.`b-c`" $v = 1 |
$p can be any value in the path. ex `schedule`[].`day` $v = 0 |