Skip to content

Commit

Permalink
To improve index scan logic since string range scan disabled. (#2277)
Browse files Browse the repository at this point in the history
* disable string type range scan for index

* add some comments and examples

* To improve the range scan structure

* improve the index optimize logic in graph layer

* To improve the structure more easy to understand

* add comments

* Beautify code , add comments

* simplified method findValidIndex

* To improve the NE condition for storage layer

* fixed comment typo.

* When index field is string type, using length string to scan

* add testcases for string index

* Addressed dangleptr's comments since 2020-9-16 12:00:00

* Addressed critical27's comments
  • Loading branch information
bright-starry-sky authored Sep 17, 2020
1 parent a571719 commit 0d312e6
Show file tree
Hide file tree
Showing 13 changed files with 1,425 additions and 388 deletions.
108 changes: 108 additions & 0 deletions src/common/utils/NebulaKeyUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ enum class NebulaSystemKeyType : uint32_t {
kSystemPart = 0x00000002,
};

enum class NebulaBoundValueType : uint8_t {
kMax = 0x0001,
kMin = 0x0002,
kSubtraction = 0x0003,
kAddition = 0x0004,
};

/**
* This class supply some utils for transition between Vertex/Edge and key in kvstore.
* */
Expand Down Expand Up @@ -248,6 +255,107 @@ class NebulaKeyUtils final {
return rawKey.subpiece(0, rawKey.size() - sizeof(int64_t));
}

// Only int and double are supported
static std::string boundVariant(nebula::cpp2::SupportedType type,
NebulaBoundValueType op,
const VariantType& v = 0L) {
switch (op) {
case NebulaBoundValueType::kMax : {
return std::string(8, '\377');
}
case NebulaBoundValueType::kMin : {
return std::string(8, '\0');
}
case NebulaBoundValueType::kSubtraction : {
std::string str;
if (type == nebula::cpp2::SupportedType::INT) {
str = encodeInt64(boost::get<int64_t>(v));
} else {
str = encodeDouble(boost::get<double>(v));
}
std::vector<unsigned char> bytes(str.begin(), str.end());

for (size_t i = bytes.size();; i--) {
if (i > 0) {
if (bytes[i-1]-- != 0) break;
} else {
return std::string(bytes.size(), '\0');
}
}
return std::string(bytes.begin(), bytes.end());
}
case NebulaBoundValueType::kAddition : {
std::string str;
if (type == nebula::cpp2::SupportedType::INT) {
str = encodeInt64(boost::get<int64_t>(v));
} else {
str = encodeDouble(boost::get<double>(v));
}
std::vector<unsigned char> bytes(str.begin(), str.end());
for (size_t i = bytes.size();; i--) {
if (i > 0) {
if (bytes[i-1]++ != 255) break;
} else {
return std::string(bytes.size(), '\377');
}
}
return std::string(bytes.begin(), bytes.end());
}
}
return "";
}

static bool checkAndCastVariant(nebula::cpp2::SupportedType sType,
VariantType& v) {
nebula::cpp2::SupportedType type = nebula::cpp2::SupportedType::UNKNOWN;
switch (v.which()) {
case VAR_INT64: {
type = nebula::cpp2::SupportedType::INT;
break;
}
case VAR_DOUBLE: {
type = nebula::cpp2::SupportedType::DOUBLE;
break;
}
case VAR_BOOL: {
type = nebula::cpp2::SupportedType::BOOL;
break;
}
case VAR_STR: {
type = nebula::cpp2::SupportedType::STRING;
break;
}
default:
return false;
}
if (sType != type) {
switch (sType) {
case nebula::cpp2::SupportedType::INT:
case nebula::cpp2::SupportedType::TIMESTAMP: {
v = Expression::toInt(v);
break;
}
case nebula::cpp2::SupportedType::BOOL: {
v = Expression::toBool(v);
break;
}
case nebula::cpp2::SupportedType::FLOAT:
case nebula::cpp2::SupportedType::DOUBLE: {
v = Expression::toDouble(v);
break;
}
case nebula::cpp2::SupportedType::STRING: {
v = Expression::toString(v);
break;
}
default: {
return false;
}
}
}
return true;
}

static std::string encodeVariant(const VariantType& v) {
switch (v.which()) {
case VAR_INT64:
Expand Down
Loading

0 comments on commit 0d312e6

Please sign in to comment.