Skip to content
Snippets Groups Projects
Unverified Commit c5933119 authored by jie.wang's avatar jie.wang Committed by GitHub
Browse files

add drop, desc, show index's validator and executor (#309)


* add drop, desc, show, rebuid index's validator and executor

* add rebuild edge index

* add show tag indexes plannode

* add toDescIndex

* add show tag indexes validator

* remove offline flag of rebuild index

* add scoped_timer

* fix

* add python test

* move toDescIndex to IndexUtil

* remove rebuild index

* fix

* update code

* support show tag/edge status

* resolve conflict

* resolve conflict

* fix

* fix

* fix conflict

* remove unused code

* improve test

* improve index test

Co-authored-by: default avatarYee <2520865+yixinglu@users.noreply.github.com>
parent 8c474f71
No related branches found
No related tags found
No related merge requests found
Showing
with 820 additions and 547 deletions
......@@ -267,6 +267,18 @@ Executor *Executor::makeExecutor(QueryContext *qctx, const PlanNode *node) {
case PlanNode::Kind::kDescEdgeIndex: {
return pool->add(new DescEdgeIndexExecutor(node, qctx));
}
case PlanNode::Kind::kShowCreateTagIndex: {
return pool->add(new ShowCreateTagIndexExecutor(node, qctx));
}
case PlanNode::Kind::kShowCreateEdgeIndex: {
return pool->add(new ShowCreateEdgeIndexExecutor(node, qctx));
}
case PlanNode::Kind::kShowTagIndexes: {
return pool->add(new ShowTagIndexesExecutor(node, qctx));
}
case PlanNode::Kind::kShowEdgeIndexes: {
return pool->add(new ShowEdgeIndexesExecutor(node, qctx));
}
case PlanNode::Kind::kInsertVertices: {
return pool->add(new InsertVerticesExecutor(node, qctx));
}
......
......@@ -6,39 +6,139 @@
#include "executor/maintain/EdgeIndexExecutor.h"
#include "planner/Maintain.h"
#include "util/IndexUtil.h"
namespace nebula {
namespace graph {
folly::Future<Status> CreateEdgeIndexExecutor::execute() {
SCOPED_TIMER(&execTime_);
auto *ceiNode = asNode<CreateEdgeIndex>(node());
auto spaceId = qctx()->rctx()->session()->space().id;
return qctx()->getMetaClient()->createEdgeIndex(spaceId,
ceiNode->getIndexName(), ceiNode->getSchemaName(),
ceiNode->getFields(), ceiNode->getIfNotExists())
.via(runner())
.then([ceiNode, spaceId](StatusOr<IndexID> resp) {
if (!resp.ok()) {
LOG(ERROR) << "SpaceId: " << spaceId
<< ", Create index`" << ceiNode->getIndexName()
<< " at edge: " << ceiNode->getSchemaName()
<< "' failed: " << resp.status();
return resp.status();
}
return Status::OK();
});
return qctx()
->getMetaClient()
->createEdgeIndex(spaceId,
ceiNode->getIndexName(),
ceiNode->getSchemaName(),
ceiNode->getFields(),
ceiNode->getIfNotExists())
.via(runner())
.then([ceiNode, spaceId](StatusOr<IndexID> resp) {
if (!resp.ok()) {
LOG(ERROR) << "SpaceId: " << spaceId << ", Create index `"
<< ceiNode->getIndexName() << "' at edge: `" << ceiNode->getSchemaName()
<< "' failed: " << resp.status();
return resp.status();
}
return Status::OK();
});
}
folly::Future<Status> DropEdgeIndexExecutor::execute() {
// auto *deiNode = asNode<DropEdgeIndexNode>(node());
// auto spaceId = qctx()->rctx()->session()->space();
return Status::OK();
SCOPED_TIMER(&execTime_);
auto *deiNode = asNode<DropEdgeIndex>(node());
auto spaceId = qctx()->rctx()->session()->space().id;
return qctx()
->getMetaClient()
->dropEdgeIndex(spaceId, deiNode->getIndexName(), deiNode->getIfExists())
.via(runner())
.then([deiNode, spaceId](StatusOr<IndexID> resp) {
if (!resp.ok()) {
LOG(ERROR) << "SpaceId: " << spaceId << ", Drop edge index`"
<< deiNode->getIndexName() << "' failed: " << resp.status();
return resp.status();
}
return Status::OK();
});
}
folly::Future<Status> DescEdgeIndexExecutor::execute() {
// auto *deiNode = asNode<DescEdgeIndexNode>(node());
// auto spaceId = qctx()->rctx()->session()->space();
return Status::OK();
SCOPED_TIMER(&execTime_);
auto *deiNode = asNode<DescEdgeIndex>(node());
auto spaceId = qctx()->rctx()->session()->space().id;
return qctx()
->getMetaClient()
->getEdgeIndex(spaceId, deiNode->getIndexName())
.via(runner())
.then([this, deiNode, spaceId](StatusOr<meta::cpp2::IndexItem> resp) {
if (!resp.ok()) {
LOG(ERROR) << "SpaceId: " << spaceId << ", Desc edge index`"
<< deiNode->getIndexName() << "' failed: " << resp.status();
return resp.status();
}
auto ret = IndexUtil::toDescIndex(resp.value());
if (!ret.ok()) {
LOG(ERROR) << ret.status();
return ret.status();
}
return finish(ResultBuilder()
.value(std::move(ret).value())
.iter(Iterator::Kind::kDefault)
.finish());
});
}
folly::Future<Status> ShowCreateEdgeIndexExecutor::execute() {
SCOPED_TIMER(&execTime_);
auto *sceiNode = asNode<ShowCreateEdgeIndex>(node());
auto spaceId = qctx()->rctx()->session()->space().id;
return qctx()
->getMetaClient()
->getEdgeIndex(spaceId, sceiNode->getIndexName())
.via(runner())
.then([this, sceiNode, spaceId](StatusOr<meta::cpp2::IndexItem> resp) {
if (!resp.ok()) {
LOG(ERROR) << "SpaceId: " << spaceId << ", Show create edge index `"
<< sceiNode->getIndexName() << "' failed: " << resp.status();
return resp.status();
}
auto ret = IndexUtil::toShowCreateIndex(false, sceiNode->getIndexName(), resp.value());
if (!ret.ok()) {
LOG(ERROR) << ret.status();
return ret.status();
}
return finish(ResultBuilder()
.value(std::move(ret).value())
.iter(Iterator::Kind::kDefault)
.finish());
});
}
folly::Future<Status> ShowEdgeIndexesExecutor::execute() {
SCOPED_TIMER(&execTime_);
auto spaceId = qctx()->rctx()->session()->space().id;
return qctx()->getMetaClient()->listEdgeIndexes(spaceId).via(runner()).then(
[this, spaceId](StatusOr<std::vector<meta::cpp2::IndexItem>> resp) {
if (!resp.ok()) {
LOG(ERROR) << "SpaceId: " << spaceId << ", Show edge indexes failed"
<< resp.status();
return resp.status();
}
auto edgeIndexItems = std::move(resp).value();
DataSet dataSet;
dataSet.colNames = {"Names"};
std::set<std::string> orderEdgeIndexNames;
for (auto &edgeIndex : edgeIndexItems) {
orderEdgeIndexNames.emplace(edgeIndex.get_index_name());
}
for (auto &name : orderEdgeIndexNames) {
Row row;
row.values.emplace_back(name);
dataSet.rows.emplace_back(std::move(row));
}
return finish(ResultBuilder()
.value(Value(std::move(dataSet)))
.iter(Iterator::Kind::kDefault)
.finish());
});
}
} // namespace graph
......
......@@ -36,6 +36,22 @@ public:
folly::Future<Status> execute() override;
};
class ShowCreateEdgeIndexExecutor final : public Executor {
public:
ShowCreateEdgeIndexExecutor(const PlanNode *node, QueryContext *qctx)
: Executor("ShowCreateEdgeIndexExecutor", node, qctx) {}
folly::Future<Status> execute() override;
};
class ShowEdgeIndexesExecutor final : public Executor {
public:
ShowEdgeIndexesExecutor(const PlanNode *node, QueryContext *qctx)
: Executor("ShowEdgeIndexesExecutor", node, qctx) {}
folly::Future<Status> execute() override;
};
} // namespace graph
} // namespace nebula
......
......@@ -6,35 +6,139 @@
#include "executor/maintain/TagIndexExecutor.h"
#include "planner/Maintain.h"
#include "util/IndexUtil.h"
namespace nebula {
namespace graph {
folly::Future<Status> CreateTagIndexExecutor::execute() {
SCOPED_TIMER(&execTime_);
auto *ctiNode = asNode<CreateTagIndex>(node());
auto spaceId = qctx()->rctx()->session()->space().id;
return qctx()->getMetaClient()->createTagIndex(spaceId,
ctiNode->getIndexName(), ctiNode->getSchemaName(),
ctiNode->getFields(), ctiNode->getIfNotExists())
.via(runner())
.then([ctiNode, spaceId](StatusOr<IndexID> resp) {
if (!resp.ok()) {
LOG(ERROR) << "SpaceId: " << spaceId
<< ", Create index`" << ctiNode->getIndexName()
<< " at tag: " << ctiNode->getSchemaName()
<< "' failed: " << resp.status();
return resp.status();
}
return Status::OK();
});
return qctx()
->getMetaClient()
->createTagIndex(spaceId,
ctiNode->getIndexName(),
ctiNode->getSchemaName(),
ctiNode->getFields(),
ctiNode->getIfNotExists())
.via(runner())
.then([ctiNode, spaceId](StatusOr<IndexID> resp) {
if (!resp.ok()) {
LOG(ERROR) << "SpaceId: " << spaceId << ", Create index `"
<< ctiNode->getIndexName() << "' at tag: `" << ctiNode->getSchemaName()
<< "' failed: " << resp.status();
return resp.status();
}
return Status::OK();
});
}
folly::Future<Status> DropTagIndexExecutor::execute() {
return Status::OK();
SCOPED_TIMER(&execTime_);
auto *dtiNode = asNode<DropTagIndex>(node());
auto spaceId = qctx()->rctx()->session()->space().id;
return qctx()
->getMetaClient()
->dropTagIndex(spaceId, dtiNode->getIndexName(), dtiNode->getIfExists())
.via(runner())
.then([dtiNode, spaceId](StatusOr<bool> resp) {
if (!resp.ok()) {
LOG(ERROR) << "SpaceId: " << spaceId << ", Drop tag index `"
<< dtiNode->getIndexName() << "' failed: " << resp.status();
return resp.status();
}
return Status::OK();
});
}
folly::Future<Status> DescTagIndexExecutor::execute() {
return Status::OK();
SCOPED_TIMER(&execTime_);
auto *dtiNode = asNode<DescTagIndex>(node());
auto spaceId = qctx()->rctx()->session()->space().id;
return qctx()
->getMetaClient()
->getTagIndex(spaceId, dtiNode->getIndexName())
.via(runner())
.then([this, dtiNode, spaceId](StatusOr<meta::cpp2::IndexItem> resp) {
if (!resp.ok()) {
LOG(ERROR) << "SpaceId: " << spaceId << ", Desc tag index `"
<< dtiNode->getIndexName() << "' failed: " << resp.status();
return resp.status();
}
auto ret = IndexUtil::toDescIndex(resp.value());
if (!ret.ok()) {
LOG(ERROR) << ret.status();
return ret.status();
}
return finish(ResultBuilder()
.value(std::move(ret).value())
.iter(Iterator::Kind::kDefault)
.finish());
});
}
folly::Future<Status> ShowCreateTagIndexExecutor::execute() {
SCOPED_TIMER(&execTime_);
auto *sctiNode = asNode<ShowCreateTagIndex>(node());
auto spaceId = qctx()->rctx()->session()->space().id;
return qctx()
->getMetaClient()
->getTagIndex(spaceId, sctiNode->getIndexName())
.via(runner())
.then([this, sctiNode, spaceId](StatusOr<meta::cpp2::IndexItem> resp) {
if (!resp.ok()) {
LOG(ERROR) << "SpaceId: " << spaceId << ", Show create tag index `"
<< sctiNode->getIndexName() << "' failed: " << resp.status();
return resp.status();
}
auto ret = IndexUtil::toShowCreateIndex(true, sctiNode->getIndexName(), resp.value());
if (!ret.ok()) {
LOG(ERROR) << ret.status();
return ret.status();
}
return finish(ResultBuilder()
.value(std::move(ret).value())
.iter(Iterator::Kind::kDefault)
.finish());
});
}
folly::Future<Status> ShowTagIndexesExecutor::execute() {
SCOPED_TIMER(&execTime_);
auto spaceId = qctx()->rctx()->session()->space().id;
return qctx()->getMetaClient()->listTagIndexes(spaceId).via(runner()).then(
[this, spaceId](StatusOr<std::vector<meta::cpp2::IndexItem>> resp) {
if (!resp.ok()) {
LOG(ERROR) << "SpaceId: " << spaceId << ", Show tag indexes failed"
<< resp.status();
return resp.status();
}
auto tagIndexItems = std::move(resp).value();
DataSet dataSet;
dataSet.colNames = {"Names"};
std::set<std::string> orderTagIndexNames;
for (auto &tagIndex : tagIndexItems) {
orderTagIndexNames.emplace(tagIndex.get_index_name());
}
for (auto &name : orderTagIndexNames) {
Row row;
row.values.emplace_back(name);
dataSet.rows.emplace_back(std::move(row));
}
return finish(ResultBuilder()
.value(Value(std::move(dataSet)))
.iter(Iterator::Kind::kDefault)
.finish());
});
}
} // namespace graph
......
......@@ -36,6 +36,22 @@ public:
folly::Future<Status> execute() override;
};
class ShowCreateTagIndexExecutor final : public Executor {
public:
ShowCreateTagIndexExecutor(const PlanNode *node, QueryContext *qctx)
: Executor("ShowCreateTagIndexExecutor", node, qctx) {}
folly::Future<Status> execute() override;
};
class ShowTagIndexesExecutor final : public Executor {
public:
ShowTagIndexesExecutor(const PlanNode *node, QueryContext *qctx)
: Executor("ShowTagIndexesExecutor", node, qctx) {}
folly::Future<Status> execute() override;
};
} // namespace graph
} // namespace nebula
......
......@@ -85,22 +85,6 @@ nebula_add_test(
gtest_main
)
nebula_add_test(
NAME
index_test
SOURCES
IndexTest.cpp
OBJECTS
${GRAPH_TEST_LIB}
LIBRARIES
${THRIFT_LIBRARIES}
proxygenhttpserver
proxygenlib
wangle
gtest
gtest_main
)
nebula_add_test(
NAME
acl_test
......
/* Copyright (c) 2020 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License,
* attached with Common Clause Condition 1.0, found in the LICENSES directory.
*/
#include "mock/test/TestEnv.h"
#include "mock/test/TestBase.h"
#include <gtest/gtest.h>
DECLARE_int32(heartbeat_interval_secs);
namespace nebula {
namespace graph {
class IndexTest : public TestBase {
protected:
void SetUp() override {
TestBase::SetUp();
}
void TearDown() override {
TestBase::TearDown();
}
static void SetUpTestCase() {
client_ = gEnv->getGraphClient();
ASSERT_NE(nullptr, client_);
}
static void TearDownTestCase() {
client_.reset();
}
protected:
static std::unique_ptr<GraphClient> client_;
};
std::unique_ptr<GraphClient> IndexTest::client_{nullptr};
TEST_F(IndexTest, TagIndex) {
ASSERT_NE(nullptr, client_);
{
cpp2::ExecutionResponse resp;
std::string query = "CREATE SPACE tag_index_space(partition_num=1, replica_factor=1)";
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
sleep(FLAGS_heartbeat_interval_secs + 1);
{
cpp2::ExecutionResponse resp;
std::string query = "USE tag_index_space";
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string query = "CREATE TAG tag_1(col1 string, col2 int, col3 double, col4 timestamp)";
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
sleep(FLAGS_heartbeat_interval_secs + 1);
{
cpp2::ExecutionResponse resp;
std::string query = "SHOW TAGS;";
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
std::vector<std::string> colNames = {"Name"};
ASSERT_TRUE(verifyColNames(resp, colNames));
std::vector<std::vector<Value>> values = {{"tag_1"}};
ASSERT_TRUE(verifyValues(resp, values));
}
// Single Tag Single Field
{
cpp2::ExecutionResponse resp;
std::string query = "CREATE TAG INDEX single_tag_index ON tag_1(col2)";
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
// Property is empty
{
cpp2::ExecutionResponse resp;
std::string query = "CREATE TAG INDEX single_tag_index ON tag_1()";
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::E_SYNTAX_ERROR, code);
}
// Single Tag Multi Field
{
cpp2::ExecutionResponse resp;
std::string query = "CREATE TAG INDEX multi_tag_index ON tag_1(col2, col3)";
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string query = "CREATE TAG INDEX disorder_tag_index ON tag_1(col3, col2)";
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string query = "DROP TAG INDEX IF EXISTS not_exists_tag_index";
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
{
cpp2::ExecutionResponse resp;
std::string query = "DROP SPACE tag_index_space";
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
}
} // namespace graph
} // namespace nebula
......@@ -2103,12 +2103,6 @@ show_sentence
| KW_SHOW KW_CREATE KW_EDGE KW_INDEX name_label {
$$ = new ShowCreateEdgeIndexSentence($5);
}
| KW_SHOW KW_TAG KW_INDEX KW_STATUS {
$$ = new ShowTagIndexesSentence();
}
| KW_SHOW KW_EDGE KW_INDEX KW_STATUS {
$$ = new ShowEdgeIndexesSentence();
}
| KW_SHOW KW_SNAPSHOTS {
$$ = new ShowSnapshotsSentence();
}
......
......@@ -1337,18 +1337,18 @@ TEST(Parser, AdminOperation) {
auto result = parser.parse(query);
ASSERT_TRUE(result.ok()) << result.status();
}
{
GQLParser parser;
std::string query = "SHOW TAG INDEX STATUS";
auto result = parser.parse(query);
ASSERT_TRUE(result.ok()) << result.status();
}
{
GQLParser parser;
std::string query = "SHOW EDGE INDEX STATUS";
auto result = parser.parse(query);
ASSERT_TRUE(result.ok()) << result.status();
}
// {
// GQLParser parser;
// std::string query = "SHOW TAG INDEX STATUS";
// auto result = parser.parse(query);
// ASSERT_TRUE(result.ok()) << result.status();
// }
// {
// GQLParser parser;
// std::string query = "SHOW EDGE INDEX STATUS";
// auto result = parser.parse(query);
// ASSERT_TRUE(result.ok()) << result.status();
// }
{
GQLParser parser;
std::string query = "SHOW CHARSET";
......@@ -1551,7 +1551,7 @@ TEST(Parser, UnreservedKeywords) {
{
GQLParser parser;
std::string query = "CREATE TAG status(part int, parts int, job string, jobs string,"
" offline bool, rebuild bool, submit bool, compact bool, "
" rebuild bool, submit bool, compact bool, "
" bidirect bool, force bool, configs string)";
auto result = parser.parse(query);
}
......
......@@ -66,11 +66,5 @@ std::unique_ptr<cpp2::PlanNodeDescription> DropIndexNode::explain() const {
return desc;
}
std::unique_ptr<cpp2::PlanNodeDescription> RebuildIndexNode::explain() const {
auto desc = SingleInputNode::explain();
addDescription("indexName", indexName_, desc.get());
return desc;
}
} // namespace graph
} // namespace nebula
......@@ -7,9 +7,9 @@
#ifndef PLANNER_MAINTAIN_H_
#define PLANNER_MAINTAIN_H_
#include "planner/Query.h"
#include "common/interface/gen-cpp2/meta_types.h"
#include "common/clients/meta/MetaClient.h"
#include "common/interface/gen-cpp2/meta_types.h"
#include "planner/Query.h"
namespace nebula {
namespace graph {
......@@ -23,10 +23,10 @@ protected:
std::string name,
meta::cpp2::Schema schema,
bool ifNotExists)
: SingleInputNode(qctx, kind, input)
, name_(std::move(name))
, schema_(std::move(schema))
, ifNotExists_(ifNotExists) {}
: SingleInputNode(qctx, kind, input),
name_(std::move(name)),
schema_(std::move(schema)),
ifNotExists_(ifNotExists) {}
public:
const std::string& getName() const {
......@@ -44,9 +44,9 @@ public:
std::unique_ptr<cpp2::PlanNodeDescription> explain() const override;
protected:
std::string name_;
meta::cpp2::Schema schema_;
bool ifNotExists_;
std::string name_;
meta::cpp2::Schema schema_;
bool ifNotExists_;
};
class CreateTag final : public CreateSchemaNode {
......@@ -56,11 +56,8 @@ public:
std::string tagName,
meta::cpp2::Schema schema,
bool ifNotExists) {
return qctx->objPool()->add(new CreateTag(qctx,
input,
std::move(tagName),
std::move(schema),
ifNotExists));
return qctx->objPool()->add(
new CreateTag(qctx, input, std::move(tagName), std::move(schema), ifNotExists));
}
private:
......@@ -74,8 +71,7 @@ private:
Kind::kCreateTag,
std::move(tagName),
std::move(schema),
ifNotExists) {
}
ifNotExists) {}
};
class CreateEdge final : public CreateSchemaNode {
......@@ -85,11 +81,8 @@ public:
std::string edgeName,
meta::cpp2::Schema schema,
bool ifNotExists) {
return qctx->objPool()->add(new CreateEdge(qctx,
input,
std::move(edgeName),
std::move(schema),
ifNotExists));
return qctx->objPool()->add(
new CreateEdge(qctx, input, std::move(edgeName), std::move(schema), ifNotExists));
}
private:
......@@ -103,8 +96,7 @@ private:
Kind::kCreateEdge,
std::move(edgeName),
std::move(schema),
ifNotExists) {
}
ifNotExists) {}
};
class AlterSchemaNode : public SingleInputNode {
......@@ -116,11 +108,11 @@ protected:
std::string name,
std::vector<meta::cpp2::AlterSchemaItem> items,
meta::cpp2::SchemaProp schemaProp)
: SingleInputNode(qctx, kind, input)
, space_(space)
, name_(std::move(name))
, schemaItems_(std::move(items))
, schemaProp_(std::move(schemaProp)) {}
: SingleInputNode(qctx, kind, input),
space_(space),
name_(std::move(name)),
schemaItems_(std::move(items)),
schemaProp_(std::move(schemaProp)) {}
public:
const std::string& getName() const {
......@@ -142,10 +134,10 @@ public:
std::unique_ptr<cpp2::PlanNodeDescription> explain() const override;
protected:
GraphSpaceID space_;
std::string name_;
std::vector<meta::cpp2::AlterSchemaItem> schemaItems_;
meta::cpp2::SchemaProp schemaProp_;
GraphSpaceID space_;
std::string name_;
std::vector<meta::cpp2::AlterSchemaItem> schemaItems_;
meta::cpp2::SchemaProp schemaProp_;
};
class AlterTag final : public AlterSchemaNode {
......@@ -156,12 +148,8 @@ public:
std::string name,
std::vector<meta::cpp2::AlterSchemaItem> items,
meta::cpp2::SchemaProp schemaProp) {
return qctx->objPool()->add(new AlterTag(qctx,
input,
space,
std::move(name),
std::move(items),
std::move(schemaProp)));
return qctx->objPool()->add(new AlterTag(
qctx, input, space, std::move(name), std::move(items), std::move(schemaProp)));
}
private:
......@@ -177,8 +165,7 @@ private:
space,
std::move(name),
std::move(items),
std::move(schemaProp)) {
}
std::move(schemaProp)) {}
};
class AlterEdge final : public AlterSchemaNode {
......@@ -206,8 +193,7 @@ private:
space,
std::move(name),
std::move(items),
std::move(schemaProp)) {
}
std::move(schemaProp)) {}
};
class DescSchemaNode : public SingleInputNode {
......@@ -223,14 +209,12 @@ public:
std::unique_ptr<cpp2::PlanNodeDescription> explain() const override;
protected:
std::string name_;
std::string name_;
};
class DescTag final : public DescSchemaNode {
public:
static DescTag* make(QueryContext* qctx,
PlanNode* input,
std::string tagName) {
static DescTag* make(QueryContext* qctx, PlanNode* input, std::string tagName) {
return qctx->objPool()->add(new DescTag(qctx, input, std::move(tagName)));
}
......@@ -241,78 +225,56 @@ private:
class DescEdge final : public DescSchemaNode {
public:
static DescEdge* make(QueryContext* qctx,
PlanNode* input,
std::string edgeName) {
static DescEdge* make(QueryContext* qctx, PlanNode* input, std::string edgeName) {
return qctx->objPool()->add(new DescEdge(qctx, input, std::move(edgeName)));
}
private:
DescEdge(QueryContext* qctx,
PlanNode* input,
std::string edgeName)
: DescSchemaNode(qctx, input, Kind::kDescEdge, std::move(edgeName)) {
}
DescEdge(QueryContext* qctx, PlanNode* input, std::string edgeName)
: DescSchemaNode(qctx, input, Kind::kDescEdge, std::move(edgeName)) {}
};
class ShowCreateTag final : public DescSchemaNode {
public:
static ShowCreateTag* make(QueryContext* qctx,
PlanNode* input,
std::string name) {
static ShowCreateTag* make(QueryContext* qctx, PlanNode* input, std::string name) {
return qctx->objPool()->add(new ShowCreateTag(qctx, input, std::move(name)));
}
private:
ShowCreateTag(QueryContext* qctx,
PlanNode* input,
std::string name)
: DescSchemaNode(qctx, input, Kind::kShowCreateTag, std::move(name)) {
}
ShowCreateTag(QueryContext* qctx, PlanNode* input, std::string name)
: DescSchemaNode(qctx, input, Kind::kShowCreateTag, std::move(name)) {}
};
class ShowCreateEdge final : public DescSchemaNode {
public:
static ShowCreateEdge* make(QueryContext* qctx,
PlanNode* input,
std::string name) {
static ShowCreateEdge* make(QueryContext* qctx, PlanNode* input, std::string name) {
return qctx->objPool()->add(new ShowCreateEdge(qctx, input, std::move(name)));
}
private:
ShowCreateEdge(QueryContext* qctx,
PlanNode* input,
std::string name)
: DescSchemaNode(qctx, input, Kind::kShowCreateEdge, std::move(name)) {
}
ShowCreateEdge(QueryContext* qctx, PlanNode* input, std::string name)
: DescSchemaNode(qctx, input, Kind::kShowCreateEdge, std::move(name)) {}
};
class ShowTags final : public SingleInputNode {
public:
static ShowTags* make(QueryContext* qctx,
PlanNode* input) {
static ShowTags* make(QueryContext* qctx, PlanNode* input) {
return qctx->objPool()->add(new ShowTags(qctx, input));
}
private:
ShowTags(QueryContext* qctx,
PlanNode* input)
: SingleInputNode(qctx, Kind::kShowTags, input) {
}
ShowTags(QueryContext* qctx, PlanNode* input) : SingleInputNode(qctx, Kind::kShowTags, input) {}
};
class ShowEdges final : public SingleInputNode {
public:
static ShowEdges* make(QueryContext* qctx,
PlanNode* input) {
static ShowEdges* make(QueryContext* qctx, PlanNode* input) {
return qctx->objPool()->add(new ShowEdges(qctx, input));
}
private:
ShowEdges(QueryContext* qctx,
PlanNode* input)
: SingleInputNode(qctx, Kind::kShowEdges, input) {
}
ShowEdges(QueryContext* qctx, PlanNode* input)
: SingleInputNode(qctx, Kind::kShowEdges, input) {}
};
class DropSchemaNode : public SingleInputNode {
......@@ -332,42 +294,29 @@ public:
std::unique_ptr<cpp2::PlanNodeDescription> explain() const override;
protected:
std::string name_;
bool ifExists_;
std::string name_;
bool ifExists_;
};
class DropTag final : public DropSchemaNode {
public:
static DropTag* make(QueryContext* qctx,
PlanNode* input,
std::string name,
bool ifExists) {
static DropTag* make(QueryContext* qctx, PlanNode* input, std::string name, bool ifExists) {
return qctx->objPool()->add(new DropTag(qctx, input, std::move(name), ifExists));
}
private:
DropTag(QueryContext* qctx,
PlanNode* input,
std::string name,
bool ifExists)
: DropSchemaNode(qctx, Kind::kDropTag, input, std::move(name), ifExists) {
}
DropTag(QueryContext* qctx, PlanNode* input, std::string name, bool ifExists)
: DropSchemaNode(qctx, Kind::kDropTag, input, std::move(name), ifExists) {}
};
class DropEdge final : public DropSchemaNode {
public:
static DropEdge* make(QueryContext* qctx,
PlanNode* input,
std::string name,
bool ifExists) {
static DropEdge* make(QueryContext* qctx, PlanNode* input, std::string name, bool ifExists) {
return qctx->objPool()->add(new DropEdge(qctx, input, std::move(name), ifExists));
}
private:
DropEdge(QueryContext* qctx,
PlanNode* input,
std::string name,
bool ifExists)
DropEdge(QueryContext* qctx, PlanNode* input, std::string name, bool ifExists)
: DropSchemaNode(qctx, Kind::kDropEdge, input, std::move(name), ifExists) {}
};
......@@ -380,11 +329,11 @@ protected:
std::string indexName,
std::vector<std::string> fields,
bool ifNotExists)
: SingleInputNode(qctx, kind, input)
, schemaName_(std::move(schemaName))
, indexName_(std::move(indexName))
, fields_(std::move(fields))
, ifNotExists_(ifNotExists) {}
: SingleInputNode(qctx, kind, input),
schemaName_(std::move(schemaName)),
indexName_(std::move(indexName)),
fields_(std::move(fields)),
ifNotExists_(ifNotExists) {}
public:
const std::string& getSchemaName() const {
......@@ -406,10 +355,10 @@ public:
std::unique_ptr<cpp2::PlanNodeDescription> explain() const override;
protected:
std::string schemaName_;
std::string indexName_;
std::vector<std::string> fields_;
bool ifNotExists_;
std::string schemaName_;
std::string indexName_;
std::vector<std::string> fields_;
bool ifNotExists_;
};
class CreateTagIndex final : public CreateIndexNode {
......@@ -420,11 +369,8 @@ public:
std::string indexName,
std::vector<std::string> fields,
bool ifNotExists) {
return qctx->objPool()->add(new CreateTagIndex(qctx, input,
std::move(tagName),
std::move(indexName),
std::move(fields),
ifNotExists));
return qctx->objPool()->add(new CreateTagIndex(
qctx, input, std::move(tagName), std::move(indexName), std::move(fields), ifNotExists));
}
private:
......@@ -434,7 +380,8 @@ private:
std::string indexName,
std::vector<std::string> fields,
bool ifNotExists)
: CreateIndexNode(qctx, input,
: CreateIndexNode(qctx,
input,
Kind::kCreateTagIndex,
std::move(tagName),
std::move(indexName),
......@@ -450,7 +397,8 @@ public:
std::string indexName,
std::vector<std::string> fields,
bool ifNotExists) {
return qctx->objPool()->add(new CreateEdgeIndex(qctx, input,
return qctx->objPool()->add(new CreateEdgeIndex(qctx,
input,
std::move(edgeName),
std::move(indexName),
std::move(fields),
......@@ -464,7 +412,8 @@ private:
std::string indexName,
std::vector<std::string> fields,
bool ifNotExists)
: CreateIndexNode(qctx, input,
: CreateIndexNode(qctx,
input,
Kind::kCreateEdgeIndex,
std::move(edgeName),
std::move(indexName),
......@@ -474,12 +423,8 @@ private:
class DescIndexNode : public SingleInputNode {
protected:
DescIndexNode(QueryContext* qctx,
PlanNode* input,
Kind kind,
std::string indexName)
: SingleInputNode(qctx, kind, input)
, indexName_(std::move(indexName)) {}
DescIndexNode(QueryContext* qctx, PlanNode* input, Kind kind, std::string indexName)
: SingleInputNode(qctx, kind, input), indexName_(std::move(indexName)) {}
public:
const std::string& getIndexName() const {
......@@ -489,7 +434,7 @@ public:
std::unique_ptr<cpp2::PlanNodeDescription> explain() const override;
protected:
std::string indexName_;
std::string indexName_;
};
class DescTagIndex final : public DescIndexNode {
......@@ -499,9 +444,7 @@ public:
}
private:
DescTagIndex(QueryContext* qctx,
PlanNode* input,
std::string indexName)
DescTagIndex(QueryContext* qctx, PlanNode* input, std::string indexName)
: DescIndexNode(qctx, input, Kind::kDescTagIndex, std::move(indexName)) {}
};
......@@ -512,9 +455,7 @@ public:
}
private:
DescEdgeIndex(QueryContext* qctx,
PlanNode* input,
std::string indexName)
DescEdgeIndex(QueryContext* qctx, PlanNode* input, std::string indexName)
: DescIndexNode(qctx, input, Kind::kDescEdgeIndex, std::move(indexName)) {}
};
......@@ -525,9 +466,9 @@ protected:
PlanNode* input,
std::string indexName,
bool ifExists)
: SingleInputNode(qctx, kind, input)
, indexName_(std::move(indexName))
, ifExists_(ifExists) {}
: SingleInputNode(qctx, kind, input),
indexName_(std::move(indexName)),
ifExists_(ifExists) {}
public:
const std::string& getIndexName() const {
......@@ -541,8 +482,8 @@ public:
std::unique_ptr<cpp2::PlanNodeDescription> explain() const override;
protected:
std::string indexName_;
bool ifExists_;
std::string indexName_;
bool ifExists_;
};
class DropTagIndex final : public DropIndexNode {
......@@ -573,26 +514,50 @@ private:
: DropIndexNode(qctx, Kind::kDropEdgeIndex, input, std::move(indexName), ifExists) {}
};
class RebuildIndexNode : public SingleInputNode {
protected:
RebuildIndexNode(QueryContext* qctx,
Kind kind,
PlanNode* input,
std::string indexName)
: SingleInputNode(qctx, kind, input)
, indexName_(std::move(indexName)) {}
class ShowCreateTagIndex final : public DescIndexNode {
public:
static ShowCreateTagIndex* make(QueryContext* qctx, PlanNode* input, std::string indexName) {
return qctx->objPool()->add(new ShowCreateTagIndex(qctx, input, std::move(indexName)));
}
private:
ShowCreateTagIndex(QueryContext* qctx, PlanNode* input, std::string indexName)
: DescIndexNode(qctx, input, Kind::kShowCreateTagIndex, std::move(indexName)) {}
};
class ShowCreateEdgeIndex final : public DescIndexNode {
public:
const std::string& getIndexName() const {
return indexName_;
static ShowCreateEdgeIndex* make(QueryContext* qctx, PlanNode* input, std::string indexName) {
return qctx->objPool()->add(new ShowCreateEdgeIndex(qctx, input, std::move(indexName)));
}
std::unique_ptr<cpp2::PlanNodeDescription> explain() const override;
private:
ShowCreateEdgeIndex(QueryContext* qctx, PlanNode* input, std::string indexName)
: DescIndexNode(qctx, input, Kind::kShowCreateEdgeIndex, std::move(indexName)) {}
};
protected:
std::string indexName_;
class ShowTagIndexes final : public SingleInputNode {
public:
static ShowTagIndexes* make(QueryContext* qctx, PlanNode* input) {
return qctx->objPool()->add(new ShowTagIndexes(qctx, input));
}
private:
ShowTagIndexes(QueryContext* qctx, PlanNode* input)
: SingleInputNode(qctx, Kind::kShowTagIndexes, input) {}
};
class ShowEdgeIndexes final : public SingleInputNode {
public:
static ShowEdgeIndexes* make(QueryContext* qctx, PlanNode* input) {
return qctx->objPool()->add(new ShowEdgeIndexes(qctx, input));
}
private:
ShowEdgeIndexes(QueryContext* qctx, PlanNode* input)
: SingleInputNode(qctx, Kind::kShowEdgeIndexes, input) {}
};
} // namespace graph
} // namespace nebula
#endif // PLANNER_MAINTAIN_H_
} // namespace graph
} // namespace nebula
#endif // PLANNER_MAINTAIN_H_
......@@ -125,6 +125,10 @@ const char* PlanNode::toString(PlanNode::Kind kind) {
return "ShowCreateTag";
case Kind::kShowCreateEdge:
return "ShowCreateEdge";
case Kind::kShowCreateTagIndex:
return "ShowCreateTagIndex";
case Kind::kShowCreateEdgeIndex:
return "ShowCreateEdgeIndex";
case Kind::kDropSpace:
return "DropSpace";
case Kind::kDropTag:
......@@ -137,6 +141,10 @@ const char* PlanNode::toString(PlanNode::Kind kind) {
return "ShowTags";
case Kind::kShowEdges:
return "ShowEdges";
case Kind::kShowTagIndexes:
return "kShowTagIndexes";
case Kind::kShowEdgeIndexes:
return "kShowEdgeIndexes";
case Kind::kCreateSnapshot:
return "CreateSnapshot";
case Kind::kDropSnapshot:
......
......@@ -71,6 +71,10 @@ public:
kDropEdgeIndex,
kDescTagIndex,
kDescEdgeIndex,
kShowCreateTagIndex,
kShowCreateEdgeIndex,
kShowTagIndexes,
kShowEdgeIndexes,
kInsertVertices,
kInsertEdges,
kBalanceLeaders,
......
......@@ -22,6 +22,47 @@ Status IndexUtil::validateColumns(const std::vector<std::string>& fields) {
return Status::OK();
}
StatusOr<DataSet> IndexUtil::toDescIndex(const meta::cpp2::IndexItem &indexItem) {
DataSet dataSet({"Field", "Type"});
for (auto &col : indexItem.get_fields()) {
Row row;
row.values.emplace_back(Value(col.get_name()));
row.values.emplace_back(SchemaUtil::typeToString(col));
dataSet.emplace_back(std::move(row));
}
return dataSet;
}
StatusOr<DataSet> IndexUtil::toShowCreateIndex(bool isTagIndex,
const std::string &indexName,
const meta::cpp2::IndexItem &indexItem) {
DataSet dataSet;
std::string createStr;
createStr.reserve(1024);
std::string schemaName = indexItem.get_schema_name();
if (isTagIndex) {
dataSet.colNames = {"Tag Index Name", "Create Tag Index"};
createStr = "CREATE TAG INDEX `" + indexName + "` ON `" + schemaName + "` (\n";
} else {
dataSet.colNames = {"Edge Index Name", "Create Edge Index"};
createStr = "CREATE EDGE INDEX `" + indexName + "` ON `" + schemaName + "` (\n";
}
Row row;
row.emplace_back(indexName);
for (auto &col : indexItem.get_fields()) {
createStr += " `" + col.get_name() + "`";
createStr += ",\n";
}
if (!indexItem.fields.empty()) {
createStr.resize(createStr.size() -2);
createStr += "\n";
}
createStr += ")";
row.emplace_back(std::move(createStr));
dataSet.rows.emplace_back(std::move(row));
return dataSet;
}
} // namespace graph
} // namespace nebula
......@@ -10,6 +10,7 @@
#include "common/base/Base.h"
#include "common/base/StatusOr.h"
#include "parser/MaintainSentences.h"
#include "util/SchemaUtil.h"
namespace nebula {
namespace graph {
......@@ -19,6 +20,12 @@ public:
IndexUtil() = delete;
static Status validateColumns(const std::vector<std::string>& fields);
static StatusOr<DataSet> toDescIndex(const meta::cpp2::IndexItem &indexItem);
static StatusOr<DataSet> toShowCreateIndex(bool isTagIndex,
const std::string &indexName,
const meta::cpp2::IndexItem &indexItem);
};
} // namespace graph
......
......@@ -219,7 +219,7 @@ StatusOr<DataSet> SchemaUtil::toShowCreateSchema(bool isTag,
const meta::cpp2::Schema &schema) {
DataSet dataSet;
std::string createStr;
createStr.resize(1024);
createStr.reserve(1024);
if (isTag) {
dataSet.colNames = {"Tag", "Create Tag"};
createStr = "CREATE TAG `" + name + "` (\n";
......
This diff is collapsed.
......@@ -196,8 +196,8 @@ private:
Status toPlan() override;
private:
std::string name_;
std::string index_;
std::string tagName_;
std::string indexName_;
std::vector<std::string> fields_;
bool ifNotExist_;
};
......@@ -213,8 +213,8 @@ private:
Status toPlan() override;
private:
std::string name_;
std::string index_;
std::string edgeName_;
std::string indexName_;
std::vector<std::string> fields_;
bool ifNotExist_;
};
......@@ -230,7 +230,8 @@ private:
Status toPlan() override;
private:
std::string index_;
std::string indexName_;
bool ifExist_;
};
class DropEdgeIndexValidator final : public Validator {
......@@ -244,7 +245,8 @@ private:
Status toPlan() override;
private:
std::string index_;
std::string indexName_;
bool ifExist_;
};
class DescribeTagIndexValidator final : public Validator {
......@@ -258,7 +260,7 @@ private:
Status toPlan() override;
private:
std::string index_;
std::string indexName_;
};
class DescribeEdgeIndexValidator final : public Validator {
......@@ -272,7 +274,7 @@ private:
Status toPlan() override;
private:
std::string index_;
std::string indexName_;
};
class ShowCreateTagIndexValidator final : public Validator {
......@@ -286,22 +288,9 @@ private:
Status toPlan() override;
private:
std::string index_;
std::string indexName_;
};
class ShowTagIndexesValidator final : public Validator {
public:
ShowTagIndexesValidator(Sentence* sentence, QueryContext* context)
: Validator(sentence, context) {}
private:
Status validateImpl() override;
Status toPlan() override;
private:
std::string index_;
};
class ShowCreateEdgeIndexValidator final : public Validator {
public:
......@@ -312,22 +301,14 @@ private:
Status validateImpl() override;
Status toPlan() override;
};
class ShowEdgeIndexesValidator final : public Validator {
public:
ShowEdgeIndexesValidator(Sentence* sentence, QueryContext* context)
: Validator(sentence, context) {}
private:
Status validateImpl() override;
Status toPlan() override;
std::string indexName_;
};
class RebuildTagIndexValidator final : public Validator {
class ShowTagIndexesValidator final : public Validator {
public:
RebuildTagIndexValidator(Sentence* sentence, QueryContext* context)
ShowTagIndexesValidator(Sentence* sentence, QueryContext* context)
: Validator(sentence, context) {}
private:
......@@ -336,9 +317,9 @@ private:
Status toPlan() override;
};
class RebuildEdgeIndexValidator final : public Validator {
class ShowEdgeIndexesValidator final : public Validator {
public:
RebuildEdgeIndexValidator(Sentence* sentence, QueryContext* context)
ShowEdgeIndexesValidator(Sentence* sentence, QueryContext* context)
: Validator(sentence, context) {}
private:
......
......@@ -70,6 +70,109 @@ class TestIndex(NebulaTestSuite):
resp = self.client.execute('CREATE TAG INDEX disorder_tag_index ON tag_1(col3, col2)')
self.check_resp_succeeded(resp)
# Insert some data
resp = self.client.execute('INSERT VERTEX tag_1(col1, col2, col3, col4) VALUES \'101\':(\'Tom\', 18, 35.4, \'2010-09-01 08:00:00\')')
self.check_resp_succeeded(resp)
resp = self.client.execute('INSERT VERTEX tag_1(col1, col2, col3, col4) VALUES \'102\':(\'Jerry\', 22, 38.4, \'2011-09-01 08:00:00\')')
self.check_resp_succeeded(resp)
resp = self.client.execute('INSERT VERTEX tag_1(col1, col2, col3, col4) VALUES \'103\':(\'Bob\', 19, 36.4, \'2010-09-01 12:00:00\')')
self.check_resp_succeeded(resp)
# # Rebuild Tag Index
# resp = self.client.execute_query('REBUILD TAG INDEX single_tag_index')
# self.check_resp_succeeded(resp)
# resp = self.client.execute_query('REBUILD TAG INDEX multi_tag_index')
# self.check_resp_succeeded(resp)
# resp = self.client.execute_query('REBUILD TAG INDEX disorder_tag_index')
# self.check_resp_succeeded(resp)
# resp = self.client.execute_query('REBUILD TAG INDEX non_existent_tag_index')
# self.check_resp.succeeded(resp) # need to check if index exists in validator in future
# Show Tag Index Status
# resp = self.client.execute_query('SHOW TAG INDEX STATUS')
# self.check_resp_succeeded(resp)
# self.check_out_of_order_result(resp, [['single_tag_index', 'SUCCEEDED'], ['multi_tag_index', 'SUCCEEDED'], ['disorder_tag_index', 'SUCCEEDED']])
# Describe Tag Index
resp = self.client.execute_query('DESC TAG INDEX single_tag_index')
self.check_resp_succeeded(resp)
expect = [['col2', 'int64']]
self.check_result(resp, expect)
resp = self.client.execute_query('DESC TAG INDEX multi_tag_index')
self.check_resp_succeeded(resp)
expect = [['col2', 'int64'],
['col3', 'double']]
self.check_result(resp, expect)
resp = self.client.execute_query('DESC TAG INDEX disorder_tag_index')
self.check_resp_succeeded(resp)
expect = [['col3', 'double'],
['col2', 'int64']]
self.check_result(resp, expect)
resp = self.client.execute_query('DESC TAG INDEX non_existent_tag_index')
self.check_resp_failed(resp)
# Show Create Tag Index
resp = self.client.execute_query('SHOW CREATE TAG INDEX single_tag_index')
self.check_resp_succeeded(resp)
expect = [['single_tag_index', 'CREATE TAG INDEX `single_tag_index` ON `tag_1` (\n `col2`\n)']]
self.check_result(resp, expect)
resp = self.client.execute_query('SHOW CREATE TAG INDEX multi_tag_index')
self.check_resp_succeeded(resp)
expect = [['multi_tag_index', 'CREATE TAG INDEX `multi_tag_index` ON `tag_1` (\n `col2`,\n `col3`\n)']]
self.check_result(resp, expect)
# Check if show create tag index works well
resp = self.client.execute_query('DROP TAG INDEX multi_tag_index')
self.check_resp_succeeded(resp)
resp = self.client.execute_query(expect[0][1])
self.check_resp_succeeded(resp)
resp = self.client.execute_query('SHOW CREATE TAG INDEX disorder_tag_index')
self.check_resp_succeeded(resp)
expect = [['disorder_tag_index', 'CREATE TAG INDEX `disorder_tag_index` ON `tag_1` (\n `col3`,\n `col2`\n)']]
self.check_result(resp, expect)
# Check if show create tag index works well
resp = self.client.execute_query('DROP TAG INDEX disorder_tag_index')
self.check_resp_succeeded(resp)
resp = self.client.execute_query(expect[0][1])
self.check_resp_succeeded(resp)
resp = self.client.execute_query('SHOW CREATE TAG INDEX non_existent_tag_index')
self.check_resp_failed(resp)
# Show Tag Indexes
resp = self.client.execute_query('SHOW TAG INDEXES')
self.check_resp_succeeded(resp)
self.check_out_of_order_result(resp, [['single_tag_index'], ['multi_tag_index'], ['disorder_tag_index']])
# Drop Tag Index
resp = self.client.execute_query('DROP TAG INDEX single_tag_index')
self.check_resp_succeeded(resp)
# Check if the index is truly dropped
resp = self.client.execute_query('DESC TAG INDEX single_tag_index')
self.check_resp_failed(resp)
resp = self.client.execute_query('DROP TAG INDEX multi_tag_index')
self.check_resp_succeeded(resp)
resp = self.client.execute_query('DESC TAG INDEX multi_tag_index')
self.check_resp_failed(resp)
resp = self.client.execute_query('DROP TAG INDEX disorder_tag_index')
self.check_resp_succeeded(resp)
resp = self.client.execute_query('DESC TAG INDEX disorder_tag_index')
self.check_resp_failed(resp)
resp = self.client.execute_query('DROP TAG INDEX non_existent_tag_index')
self.check_resp_failed(resp)
def test_edge_index(self):
# Single Tag Single Field
resp = self.client.execute('CREATE EDGE INDEX single_edge_index ON edge_1(col2)')
......@@ -105,3 +208,106 @@ class TestIndex(NebulaTestSuite):
resp = self.client.execute('CREATE EDGE INDEX disorder_edge_1_index ON edge_1(col3, col2)')
self.check_resp_succeeded(resp)
# Insert some data
resp = self.client.execute('INSERT EDGE edge_1(col1, col2, col3, col4) VALUES \'101\'->\'102\':(\'Red\', 81, 45.3, \'2010-09-01 08:00:00\')')
self.check_resp_succeeded(resp)
resp = self.client.execute('INSERT EDGE edge_1(col1, col2, col3, col4) VALUES \'102\'->\'103\':(\'Yellow\', 22, 423.8, \'2011-09-01 08:00:00\')')
self.check_resp_succeeded(resp)
resp = self.client.execute('INSERT EDGE edge_1(col1, col2, col3, col4) VALUES \'103\'->\'101\':(\'Blue\', 91, 43.1, \'2010-09-01 12:00:00\')')
self.check_resp_succeeded(resp)
# # Rebuild Edge Index
# resp = self.client.execute_query('REBUILD EDGE INDEX single_edge_index')
# self.check_resp_succeeded(resp)
# resp = self.client.execute_query('REBUILD EDGE INDEX multi_edge_1_index')
# self.check_resp_succeeded(resp)
# resp = self.client.execute_query('REBUILD EDGE INDEX disorder_edge_1_index')
# self.check_resp_succeeded(resp)
# resp = self.client.execute_query('REBUILD EDGE INDEX non_existent_edge_index')
# self.check_resp.failed(resp)
# Show Edge Index Status
# resp = self.client.execute_query('SHOW EDGE INDEX STATUS')
# self.check_resp_succeeded(resp)
# self.check_out_of_order_result(resp, [['single_edge_index', 'SUCCEEDED'], ['multi_edge_1_index', 'SUCCEEDED'], ['disorder_edge_1_index', 'SUCCEEDED']])
# Describe Edge Index
resp = self.client.execute_query('DESC EDGE INDEX single_edge_index')
self.check_resp_succeeded(resp)
expect = [['col2', 'int64']]
self.check_result(resp, expect)
resp = self.client.execute_query('DESC EDGE INDEX multi_edge_1_index')
self.check_resp_succeeded(resp)
expect = [['col2', 'int64'],
['col3', 'double']]
self.check_result(resp, expect)
resp = self.client.execute_query('DESC EDGE INDEX disorder_edge_1_index')
self.check_resp_succeeded(resp)
expect = [['col3', 'double'],
['col2', 'int64']]
self.check_result(resp, expect)
resp = self.client.execute_query('DESC EDGE INDEX non_existent_edge_index')
self.check_resp_failed(resp)
# Show Create Edge Index
resp = self.client.execute_query('SHOW CREATE EDGE INDEX single_edge_index')
self.check_resp_succeeded(resp)
expect = [['single_edge_index', 'CREATE EDGE INDEX `single_edge_index` ON `edge_1` (\n `col2`\n)']]
self.check_result(resp, expect)
resp = self.client.execute_query('SHOW CREATE EDGE INDEX multi_edge_1_index')
self.check_resp_succeeded(resp)
expect = [['multi_edge_1_index', 'CREATE EDGE INDEX `multi_edge_1_index` ON `edge_1` (\n `col2`,\n `col3`\n)']]
self.check_result(resp, expect)
# Check if show create edge index works well
resp = self.client.execute_query('DROP EDGE INDEX multi_edge_1_index')
self.check_resp_succeeded(resp)
resp = self.client.execute_query(expect[0][1])
self.check_resp_succeeded(resp)
resp = self.client.execute_query('SHOW CREATE EDGE INDEX disorder_edge_1_index')
self.check_resp_succeeded(resp)
expect = [['disorder_edge_1_index', 'CREATE EDGE INDEX `disorder_edge_1_index` ON `edge_1` (\n `col3`,\n `col2`\n)']]
self.check_result(resp, expect)
# Check if show create edge index works well
resp = self.client.execute_query('DROP EDGE INDEX disorder_edge_1_index')
self.check_resp_succeeded(resp)
resp = self.client.execute_query(expect[0][1])
self.check_resp_succeeded(resp)
resp = self.client.execute_query('SHOW CREATE EDGE INDEX non_existent_edge_index')
self.check_resp_failed(resp)
# Show Edge Indexes
resp = self.client.execute_query('SHOW EDGE INDEXES')
self.check_resp_succeeded(resp)
self.check_out_of_order_result(resp, [['single_edge_index'], ['multi_edge_1_index'], ['disorder_edge_1_index']])
# Drop Edge Index
resp = self.client.execute_query('DROP EDGE INDEX single_edge_index')
self.check_resp_succeeded(resp)
# Check if the index is truly dropped
resp = self.client.execute_query('DESC EDGE INDEX single_edge_index')
self.check_resp_failed(resp)
resp = self.client.execute_query('DROP EDGE INDEX multi_edge_1_index')
self.check_resp_succeeded(resp)
resp = self.client.execute_query('DESC EDGE INDEX multi_edge_1_index')
self.check_resp_failed(resp)
resp = self.client.execute_query('DROP EDGE INDEX disorder_edge_1_index')
self.check_resp_succeeded(resp)
resp = self.client.execute_query('DESC EDGE INDEX disorder_edge_1_index')
self.check_resp_failed(resp)
resp = self.client.execute_query('DROP EDGE INDEX non_existent_edge_index')
self.check_resp_failed(resp)
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment