Skip to content

Commit c4b111b

Browse files
authored
Vector index Interface (#6090)
* LZY: Implement the ddl for vector property Signed-off-by: lzy <[email protected]> * LZY: dml for vertex of vector type finished and add new mock test LZY: dml fix bug and remove useless code Signed-off-by: lzy <[email protected]> * LZY: vector index interface and simple ann benchmark finished Signed-off-by: lzy <[email protected]> --------- Signed-off-by: lzy <[email protected]>
1 parent b7b841c commit c4b111b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+3479
-513
lines changed

cmake/nebula/ThirdPartyConfig.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ find_package(FLEX REQUIRED)
119119
find_package(LibLZMA REQUIRED)
120120
find_package(Fizz REQUIRED)
121121
find_package(Sodium REQUIRED)
122+
link_directories("${NEBULA_THIRDPARTY_ROOT}/lib")
122123
if (ENABLE_BREAKPAD)
123124
find_package(Breakpad REQUIRED)
124125
endif()

src/codec/RowReaderV2.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ Value RowReaderV2::getValueByIndex(const int64_t index) const {
330330

331331
Value RowReaderV2::getVectorValueByName(const std::string& prop) const {
332332
int64_t index = schema_->getVectorFieldIndex(prop);
333-
LOG(ERROR) << "LZY getVectorValueByName() prop: " << prop << ", index: " << index;
334333
return getVectorValueByIndex(index);
335334
}
336335

@@ -361,7 +360,7 @@ Value RowReaderV2::getVectorValueByIndex(const int64_t index) const {
361360
case PropertyType::UNKNOWN:
362361
break;
363362
default: {
364-
LOG(ERROR) << "Unsupported vector property type: " << static_cast<int>(field->type());
363+
LOG(FATAL) << "Unsupported vector property type: " << static_cast<int>(field->type());
365364
}
366365
}
367366
LOG(FATAL) << "Should not reach here, illegal property type: " << static_cast<int>(field->type());

src/codec/RowReaderWrapper.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,26 @@ RowReaderWrapper RowReaderWrapper::getTagPropReader(meta::SchemaManager* schemaM
2727
}
2828
}
2929

30+
RowReaderWrapper RowReaderWrapper::getTagPropReader(meta::SchemaManager* schemaMan,
31+
GraphSpaceID space,
32+
TagID tag,
33+
PropID vectorIndex,
34+
folly::StringPiece row) {
35+
SchemaVer schemaVer;
36+
int32_t readerVer;
37+
RowReaderWrapper::getVersions(row, schemaVer, readerVer);
38+
if (schemaVer >= 0) {
39+
auto schema = schemaMan->getTagSchema(space, tag, schemaVer);
40+
if (schema == nullptr) {
41+
return RowReaderWrapper();
42+
}
43+
return RowReaderWrapper(schema.get(), row, readerVer, true, static_cast<int32_t>(vectorIndex));
44+
} else {
45+
LOG(WARNING) << "Invalid schema version in the row data!";
46+
return RowReaderWrapper();
47+
}
48+
}
49+
3050
// static
3151
RowReaderWrapper RowReaderWrapper::getEdgePropReader(meta::SchemaManager* schemaMan,
3252
GraphSpaceID space,

src/codec/RowReaderWrapper.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ class RowReaderWrapper {
6464
GraphSpaceID space,
6565
TagID tag,
6666
folly::StringPiece row);
67+
static RowReaderWrapper getTagPropReader(meta::SchemaManager* schemaMan,
68+
GraphSpaceID space,
69+
TagID tag,
70+
PropID vectorIndex,
71+
folly::StringPiece row);
6772

6873
/**
6974
* @brief Generate a row reader wrapper of edge data

src/codec/RowWriterV2.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,6 @@ RowWriterV2::RowWriterV2(const meta::NebulaSchemaProvider* schema,
226226

227227
// Null flags
228228
size_t numNullables = schema_->vectorField(vector_field_index_)->nullable();
229-
LOG(ERROR) << "LZY Vector field index: " << vector_field_index_
230-
<< ", numNullables: " << numNullables;
231229
if (numNullables > 0) {
232230
numNullBytes_ = ((numNullables - 1) >> 3) + 1;
233231
}
@@ -382,8 +380,6 @@ void RowWriterV2::processV2EncodedStrVector() {
382380

383381
// Null flags
384382
size_t numNullables = schema_->vectorField(vector_field_index_)->nullable();
385-
LOG(ERROR) << "LZY Vector field index: " << vector_field_index_
386-
<< ", numNullables: " << numNullables;
387383
if (numNullables > 0) {
388384
numNullBytes_ = ((numNullables - 1) >> 3) + 1;
389385
} else {

src/common/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ nebula_add_subdirectory(geo)
2727
nebula_add_subdirectory(memory)
2828
nebula_add_subdirectory(id)
2929
nebula_add_subdirectory(log)
30+
nebula_add_subdirectory(vectorIndex)

src/common/meta/NebulaSchemaProvider.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ class NebulaSchemaProvider {
254254
std::string defaultValue = "",
255255
cpp2::GeoShape geoShape = cpp2::GeoShape::ANY);
256256

257-
258257
void setProp(cpp2::SchemaProp schemaProp);
259258

260259
const cpp2::SchemaProp getProp() const;
@@ -267,7 +266,7 @@ class NebulaSchemaProvider {
267266

268267
bool hasVectorCol() const {
269268
return !vector_fields_.empty();
270-
269+
}
271270

272271
private:
273272
std::size_t fieldSize(nebula::cpp2::PropertyType type, std::size_t fixedStrLimit);

src/common/thrift/ThriftTypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ using PartitionID = int32_t;
1717
using TermID = int64_t;
1818
using LogID = int64_t;
1919
using Port = int32_t;
20+
using VectorID = int64_t;
2021

2122
// Starting from 2.0, both string and int64 vertex ids will be supported.
2223
//

src/common/utils/NebulaKeyUtils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ std::string NebulaKeyUtils::vectorTagPrefix(size_t vIdLen,
240240
PartitionID partId,
241241
const VertexID& vId) {
242242
CHECK_GE(vIdLen, vId.size());
243-
PartitionID item = (partId << kPartitionOffset) | static_cast<uint32_t>(NebulaKeyType::kVector_);
243+
PartitionID item = (partId << kPartitionOffset) | static_cast<uint32_t>(NebulaKeyType::kVector_) |
244+
static_cast<uint32_t>(NebulaKeyType::kTag_);
244245
std::string key;
245246
key.reserve(sizeof(PartitionID) + vIdLen);
246247
key.append(reinterpret_cast<const char*>(&item), sizeof(PartitionID))

src/common/utils/NebulaKeyUtils.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#ifndef COMMON_UTILS_NEBULAKEYUTILS_H_
77
#define COMMON_UTILS_NEBULAKEYUTILS_H_
88

9+
#include "common/thrift/ThriftTypes.h"
910
#include "common/utils/Types.h"
1011

1112
namespace nebula {
@@ -210,6 +211,14 @@ class NebulaKeyUtils final {
210211
return readInt<TagID>(rawKey.data() + offset, sizeof(TagID));
211212
}
212213

214+
static PropID getTagPropId(size_t vIdLen, const folly::StringPiece& rawKey) {
215+
if (rawKey.size() != kVectorTagLen + vIdLen) {
216+
dumpBadKey(rawKey, kVectorTagLen + vIdLen, vIdLen);
217+
}
218+
auto offset = sizeof(PartitionID) + vIdLen + sizeof(TagID);
219+
return readInt<PropID>(rawKey.data() + offset, sizeof(PropID));
220+
}
221+
213222
static bool isEdge(size_t vIdLen, const folly::StringPiece& rawKey, char suffix = kEdgeVersion) {
214223
if (rawKey.size() != kEdgeLen + (vIdLen << 1)) {
215224
return false;
@@ -229,9 +238,6 @@ class NebulaKeyUtils final {
229238
}
230239

231240
static bool isVector(const folly::StringPiece& rawKey) {
232-
// if (rawKey.size() != kVectorTagLen + vIdLen) {
233-
// return false;
234-
// }
235241
constexpr int32_t len = static_cast<int32_t>(sizeof(NebulaKeyType));
236242
auto type = readInt<uint32_t>(rawKey.data(), len) & kTypeMaskWithVector;
237243
return static_cast<NebulaKeyType>(type) == NebulaKeyType::kVector_;
@@ -371,7 +377,7 @@ class NebulaKeyUtils final {
371377
auto offset = sizeof(PartitionID) + vIdLen + sizeof(EdgeType);
372378
return NebulaKeyUtils::decodeRank(rawKey.data() + offset);
373379
}
374-
static PropID getPropID(size_t vIdLen, const folly::StringPiece& rawKey) {
380+
static PropID getEdgePropID(size_t vIdLen, const folly::StringPiece& rawKey) {
375381
if (rawKey.size() < kVectorEdgeLen + (vIdLen << 1)) {
376382
dumpBadKey(rawKey, kVectorEdgeLen + (vIdLen << 1), vIdLen);
377383
}

0 commit comments

Comments
 (0)