mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 18:35:46 +02:00
chore: add half-range indices (#3041)
Add indices in form of [:end] or [start:] Also, enable jsonpathv2 by default Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
parent
3e0a9e16cc
commit
8721ca7fca
4 changed files with 16 additions and 2 deletions
|
@ -88,6 +88,8 @@ identifier: UNQ_STR
|
|||
bracket_index: WILDCARD { $$ = PathSegment{SegmentType::INDEX, IndexExpr::All()}; }
|
||||
| INT { $$ = PathSegment(SegmentType::INDEX, IndexExpr($1, $1)); }
|
||||
| INT COLON INT { $$ = PathSegment(SegmentType::INDEX, IndexExpr::HalfOpen($1, $3)); }
|
||||
| INT COLON { $$ = PathSegment(SegmentType::INDEX, IndexExpr($1, INT_MAX)); }
|
||||
| COLON INT { $$ = PathSegment(SegmentType::INDEX, IndexExpr::HalfOpen(0, $2)); }
|
||||
|
||||
function_expr: UNQ_STR { driver->AddFunction($1); } LPARENT ROOT relative_location RPARENT
|
||||
%%
|
||||
|
|
|
@ -519,6 +519,18 @@ TYPED_TEST(JsonPathTest, SubRange) {
|
|||
EvaluatePath(path, json, cb);
|
||||
ASSERT_THAT(arr, ElementsAre());
|
||||
arr.clear();
|
||||
|
||||
ASSERT_EQ(0, this->Parse("$.arr[:2]"));
|
||||
path = this->driver_.TakePath();
|
||||
EvaluatePath(path, json, cb);
|
||||
ASSERT_THAT(arr, ElementsAre(1, 2));
|
||||
arr.clear();
|
||||
|
||||
ASSERT_EQ(0, this->Parse("$.arr[2:]"));
|
||||
path = this->driver_.TakePath();
|
||||
EvaluatePath(path, json, cb);
|
||||
ASSERT_THAT(arr, ElementsAre(3, 4, 5));
|
||||
arr.clear();
|
||||
}
|
||||
|
||||
} // namespace dfly::json
|
||||
|
|
|
@ -55,7 +55,7 @@ IndexExpr IndexExpr::Normalize(size_t array_len) const {
|
|||
return IndexExpr(1, 0); // empty range.
|
||||
|
||||
IndexExpr res = *this;
|
||||
auto wrap = [=](int negative) {
|
||||
auto wrap = [array_len](int negative) {
|
||||
unsigned positive = -negative;
|
||||
return positive > array_len ? 0 : array_len - positive;
|
||||
};
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include "server/tiered_storage.h"
|
||||
#include "server/transaction.h"
|
||||
|
||||
ABSL_FLAG(bool, jsonpathv2, false,
|
||||
ABSL_FLAG(bool, jsonpathv2, true,
|
||||
"If true uses Dragonfly jsonpath implementation, "
|
||||
"otherwise uses legacy jsoncons implementation.");
|
||||
ABSL_FLAG(bool, experimental_flat_json, false, "If true uses flat json implementation.");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue