diff --git a/client/cpp/GraphDbClient.cpp b/client/cpp/GraphDbClient.cpp index d0c5fe0a139..1eda5ed9035 100644 --- a/client/cpp/GraphDbClient.cpp +++ b/client/cpp/GraphDbClient.cpp @@ -8,7 +8,6 @@ #include "client/cpp/GraphDbClient.h" #include #include -#include "dataman/RowSetReader.h" DEFINE_int32(conn_timeout_ms, 1000, "Connection timeout in milliseconds"); @@ -17,15 +16,6 @@ DEFINE_int32(conn_timeout_ms, 1000, namespace vesoft { namespace vgraph { -enum class ClientError { - SUCCEEDED = 0, - - E_DISCONNECTED = -1001, - E_FAIL_TO_CONNECT = -1002, - E_RPC_FAILURE = -1003, -}; - - GraphDbClient::GraphDbClient(const std::string& addr, uint16_t port) : addr_(addr) , port_(port) @@ -38,8 +28,8 @@ GraphDbClient::~GraphDbClient() { } -int32_t GraphDbClient::connect(const std::string& username, - const std::string& password) { +cpp2::ErrorCode GraphDbClient::connect(const std::string& username, + const std::string& password) { using namespace apache::thrift; auto socket = async::TAsyncSocket::newSocket( @@ -50,11 +40,12 @@ int32_t GraphDbClient::connect(const std::string& username, if (!socket) { // Bad connection LOG(ERROR) << "Failed to connect to " << addr_ << ":" << port_; - errorStr_ = "Server is unavailable"; - return static_cast(ClientError::E_FAIL_TO_CONNECT); + return cpp2::ErrorCode::E_FAIL_TO_CONNECT; } - // Wait until the socket bcomes connected + // Wait until the socket becomes connected + // TODO Obviously this is not the most efficient way. We need to + // change it to async implementation later for (int i = 0; i < 4; i++) { usleep(1000 * FLAGS_conn_timeout_ms / 4); if (socket->good()) { @@ -64,8 +55,7 @@ int32_t GraphDbClient::connect(const std::string& username, } if (!socket->good()) { LOG(ERROR) << "Timed out when connecting to " << addr_ << ":" << port_; - errorStr_ = "Server is unavailable"; - return static_cast(ClientError::E_FAIL_TO_CONNECT); + return cpp2::ErrorCode::E_FAIL_TO_CONNECT; } client_ = std::make_unique( @@ -74,19 +64,18 @@ int32_t GraphDbClient::connect(const std::string& username, cpp2::AuthResponse resp; try { client_->sync_authenticate(resp, username, password); - if (resp.get_result() != cpp2::ResultCode::SUCCEEDED) { - errorStr_ = std::move(*(resp.get_errorMsg())); - return static_cast(resp.get_result()); + if (resp.get_error_code() != cpp2::ErrorCode::SUCCEEDED) { + LOG(ERROR) << "Failed to authenticate \"" << username << "\": " + << resp.get_error_msg(); + return resp.get_error_code(); } - sessionId_ = *(resp.get_sessionId()); } catch (const std::exception& ex) { LOG(ERROR) << "Thrift rpc call failed: " << ex.what(); - errorStr_ = folly::stringPrintf("Failed to make the RPC call: %s", - ex.what()); - return static_cast(ClientError::E_RPC_FAILURE); + return cpp2::ErrorCode::E_RPC_FAILURE; } - return static_cast(ClientError::SUCCEEDED); + sessionId_ = *(resp.get_session_id()); + return cpp2::ErrorCode::SUCCEEDED; } @@ -102,40 +91,21 @@ void GraphDbClient::disconnect() { } -int32_t GraphDbClient::execute(folly::StringPiece stmt, - std::unique_ptr& rowsetReader) { +cpp2::ErrorCode GraphDbClient::execute(folly::StringPiece stmt, + cpp2::ExecutionResponse& resp) { if (!client_) { - errorStr_ = "Disconnected from the server"; - return static_cast(ClientError::E_DISCONNECTED); + LOG(ERROR) << "Disconnected from the server"; + return cpp2::ErrorCode::E_DISCONNECTED; } - cpp2::ExecutionResponse resp; try { client_->sync_execute(resp, sessionId_, stmt.toString()); - if (resp.get_result() != cpp2::ResultCode::SUCCEEDED) { - errorStr_ = std::move(*(resp.get_errorMsg())); - return static_cast(resp.get_result()); - } } catch (const std::exception& ex) { LOG(ERROR) << "Thrift rpc call failed: " << ex.what(); - errorStr_ = folly::stringPrintf("Failed to make the RPC call: %s", - ex.what()); - return static_cast(ClientError::E_RPC_FAILURE); + return cpp2::ErrorCode::E_RPC_FAILURE; } - latencyInMs_ = resp.get_latencyInMs(); - rowsetReader.reset(new RowSetReader(resp)); - return static_cast(ClientError::SUCCEEDED); -} - - -const char* GraphDbClient::getErrorStr() const { - return errorStr_.c_str(); -} - - -int32_t GraphDbClient::getServerLatency() const { - return latencyInMs_; + return resp.get_error_code(); } } // namespace vgraph diff --git a/client/cpp/GraphDbClient.h b/client/cpp/GraphDbClient.h index 86371a32307..438695c3113 100644 --- a/client/cpp/GraphDbClient.h +++ b/client/cpp/GraphDbClient.h @@ -13,44 +13,24 @@ namespace vesoft { namespace vgraph { -class RowSetReader; - class GraphDbClient { public: GraphDbClient(const std::string& addr, uint16_t port); virtual ~GraphDbClient(); - // When authentication succeeds, the method returns 0, otherwise - // an negative error code will be returned - // - // When the method returns error, getErrorStr() can be called to - // get the human readable error message - int32_t connect(const std::string& username, - const std::string& password); + // Authenticate the user + cpp2::ErrorCode connect(const std::string& username, + const std::string& password); void disconnect(); - // When execution succeeds, the method returns 0, otherwise - // a negative error code will be returned - // - // When the method returns error, getErrorStr() can be called to - // get the human readable error message - int32_t execute(folly::StringPiece stmt, - std::unique_ptr& rowsetReader); - - // Get the server latency in milliseconds - int32_t getServerLatency() const; - - // Return the last human readable error message - const char* getErrorStr() const; + cpp2::ErrorCode execute(folly::StringPiece stmt, + cpp2::ExecutionResponse& resp); private: std::unique_ptr client_; const std::string addr_; const uint16_t port_; int64_t sessionId_; - - std::string errorStr_; - int32_t latencyInMs_; }; } // namespace vgraph diff --git a/console/CMakeLists.txt b/console/CMakeLists.txt index 93e24feb06a..04831c89422 100644 --- a/console/CMakeLists.txt +++ b/console/CMakeLists.txt @@ -6,7 +6,6 @@ add_executable( GraphDbConsole.cpp $ $ - $ $ $ $ diff --git a/console/CliManager.cpp b/console/CliManager.cpp index f4f8848c5f2..c03a0097ae4 100644 --- a/console/CliManager.cpp +++ b/console/CliManager.cpp @@ -64,14 +64,14 @@ bool CliManager::connect(const std::string& addr, username_ = user; auto client = std::make_unique(addr_, port_); - int32_t err = client->connect(user, pass); - if (!err) { + cpp2::ErrorCode res = client->connect(user, pass); + if (res == cpp2::ErrorCode::SUCCEEDED) { std::cerr << "\nWelcome to vGraph (Version 0.1)\n\n"; cmdProcessor_ = std::make_unique(std::move(client)); return true; } else { // There is an error - std::cout << "Authentication failed: " << client->getErrorStr() << "\n"; + std::cout << "Authentication failed\n"; return false; } } diff --git a/console/CmdProcessor.cpp b/console/CmdProcessor.cpp index 46d911ad3e0..a4ef04215ab 100644 --- a/console/CmdProcessor.cpp +++ b/console/CmdProcessor.cpp @@ -7,89 +7,189 @@ #include "base/Base.h" #include "console/CmdProcessor.h" #include "time/Duration.h" -#include "dataman/RowSetReader.h" -#include "dataman/RowReader.h" namespace vesoft { namespace vgraph { #define GET_VALUE_WIDTH(VT, FN, FMT) \ - VT val; \ - if (fieldIt->get ## FN (val) == ResultType::SUCCEEDED) { \ - int32_t len = folly::stringPrintf(FMT, val).size(); \ - if (widths[fieldIdx] < len) { \ - widths[fieldIdx] = len; \ - } \ + VT val = col.get_ ## FN(); \ + size_t len = folly::stringPrintf(FMT, val).size(); \ + if (widths[idx] < len) { \ + widths[idx] = len; \ + genFmt = true; \ } -std::vector CmdProcessor::calColumnWidths( - const RowSetReader* dataReader) const { - std::vector widths; +void CmdProcessor::calColumnWidths( + const cpp2::ExecutionResponse& resp, + std::vector& widths, + std::vector& formats) const { + widths.clear(); + formats.clear(); // Check column names first - auto* schema = dataReader->schema(); - for (int i = 0; i < schema->getNumFields(0); i++) { - widths.emplace_back(strlen(schema->getFieldName(i, 0))); + if (resp.get_column_names() != nullptr) { + for (size_t i = 0; i < resp.get_column_names()->size(); i++) { + widths.emplace_back(resp.get_column_names()->at(i).size()); + } + } + if (widths.size() == 0) { + return; } - // TODO Then check data width - auto rowIt = dataReader->begin(); - while (bool(rowIt)) { - int32_t fieldIdx = 0; - auto fieldIt = rowIt->begin(); - while (bool(fieldIt)) { - switch (schema->getFieldType(fieldIdx, 0)->get_type()) { - case cpp2::SupportedType::BOOL: { + std::vector types( + widths.size(), cpp2::ColumnValue::Type::__EMPTY__); + formats.resize(widths.size()); + // Then check data width + for (auto& row : *(resp.get_rows())) { + size_t idx = 0; + for (auto& col : row.get_columns()) { + CHECK(types[idx] == cpp2::ColumnValue::Type::__EMPTY__ + || types[idx] == col.getType()); + bool genFmt = types[idx] == cpp2::ColumnValue::Type::__EMPTY__; + if (types[idx] == cpp2::ColumnValue::Type::__EMPTY__) { + types[idx] = col.getType(); + } else { + CHECK_EQ(types[idx], col.getType()); + } + + switch (col.getType()) { + case cpp2::ColumnValue::Type::__EMPTY__: { + break; + } + case cpp2::ColumnValue::Type::boolean: { // Enough to hold "false" - if (widths[fieldIdx] < 5) { - widths[fieldIdx] = 5; + if (widths[idx] < 5UL) { + widths[idx] = 5UL; + genFmt = true; + } + if (genFmt) { + formats[idx] = + folly::stringPrintf(" %%%lds |", widths[idx]); } break; } - case cpp2::SupportedType::INT: { - GET_VALUE_WIDTH(int64_t, Int, "%ld") + case cpp2::ColumnValue::Type::integer: { + GET_VALUE_WIDTH(int64_t, integer, "%ld") + if (genFmt) { + formats[idx] = + folly::stringPrintf(" %%%ldld |", widths[idx]); + } break; } - case cpp2::SupportedType::FLOAT: { - GET_VALUE_WIDTH(float, Float, "%f") + case cpp2::ColumnValue::Type::id: { + // Enough to hold "0x{16 letters}" + if (widths[idx] < 18UL) { + widths[idx] = 18UL; + genFmt = true; + } + if (genFmt) { + formats[idx] = + folly::stringPrintf(" %%%ldX |", widths[idx]); + } break; } - case cpp2::SupportedType::DOUBLE: { - GET_VALUE_WIDTH(double, Double, "%lf") + case cpp2::ColumnValue::Type::single_precision: { + GET_VALUE_WIDTH(float, single_precision, "%f") + if (genFmt) { + formats[idx] = + folly::stringPrintf(" %%%ldf |", widths[idx]); + } break; } - case cpp2::SupportedType::STRING: { - folly::StringPiece val; - if (fieldIt->getString(val) == ResultType::SUCCEEDED) { - if (widths[fieldIdx] < static_cast(val.size())) { - widths[fieldIdx] = val.size(); - } + case cpp2::ColumnValue::Type::double_precision: { + GET_VALUE_WIDTH(double, double_precision, "%lf") + if (genFmt) { + formats[idx] = + folly::stringPrintf(" %%%ldf |", widths[idx]); } break; } - case cpp2::SupportedType::VID: { - // Enough to hold "0x{16 letters}" - if (widths[fieldIdx] < 18) { - widths[fieldIdx] = 18; + case cpp2::ColumnValue::Type::str: { + size_t len = col.get_str().size(); + if (widths[idx] < len) { + widths[idx] = len; + genFmt = true; + } + if (genFmt) { + formats[idx] = + folly::stringPrintf(" %%%lds |", widths[idx]); + } + break; + } + case cpp2::ColumnValue::Type::timestamp: { + GET_VALUE_WIDTH(int64_t, timestamp, "%ld") + if (genFmt) { + formats[idx] = + folly::stringPrintf(" %%%ldld |", widths[idx]); + } + break; + } + case cpp2::ColumnValue::Type::year: { + if (widths[idx] < 4UL) { + widths[idx] = 4UL; + genFmt = true; + } + if (genFmt) { + formats[idx] = folly::stringPrintf(" %%%ldd |", widths[idx]); + } + break; + } + case cpp2::ColumnValue::Type::month: { + if (widths[idx] < 7UL) { + widths[idx] = 7UL; + genFmt = true; + } + if (genFmt) { + formats[idx] = folly::stringPrintf(" %%%ldd/%%02d |", + widths[idx] - 3); + } + break; + } + case cpp2::ColumnValue::Type::date: { + if (widths[idx] < 10UL) { + widths[idx] = 10UL; + genFmt = true; + } + if (genFmt) { + formats[idx] = + folly::stringPrintf(" %%%ldd/%%02d/%%02d |", + widths[idx] - 6); } break; } - default: { + case cpp2::ColumnValue::Type::datetime: { + if (widths[idx] < 26UL) { + widths[idx] = 26UL; + genFmt = true; + } + if (genFmt) { + formats[idx] = + folly::stringPrintf(" %%%ldd/%%02d/%%02d" + " %%02d:%%02d:%%02d" + ".%%03d%%03d |", + widths[idx] - 22); + } + break; } } - ++fieldIt; - ++fieldIdx; + ++idx; } - ++rowIt; } - - return std::move(widths); } #undef GET_VALUE_WIDTH -int32_t CmdProcessor::printResult(const RowSetReader* dataReader) const { - std::vector widths = calColumnWidths(dataReader); +void CmdProcessor::printResult(const cpp2::ExecutionResponse& resp) const { + std::vector widths; + std::vector formats; + + calColumnWidths(resp, widths, formats); + + if (widths.size() == 0) { + return; + } + + // Calculate the total width int32_t sum = 0; for (auto w : widths) { sum += w; @@ -99,117 +199,109 @@ int32_t CmdProcessor::printResult(const RowSetReader* dataReader) const { std::string rowLine(sum + 3 * widths.size() + 1, '-'); std::cout << headerLine << "\n|"; - std::vector formats = printHeader(dataReader, widths); + printHeader(resp, widths); std::cout << headerLine << "\n"; - int32_t numRows = printData(dataReader, rowLine, formats); - return numRows; + printData(resp, rowLine, widths, formats); } -std::vector CmdProcessor::printHeader( - const RowSetReader* dataReader, - const std::vector& widths) const { - std::vector formats; +void CmdProcessor::printHeader( + const cpp2::ExecutionResponse& resp, + const std::vector& widths) const { + size_t idx = 0; + if (resp.get_column_names() == nullptr) { + return; + } - auto* schema = dataReader->schema(); - for (int i = 0; i < schema->getNumFields(0); i++) { - std::string fmt = folly::stringPrintf(" %%%ds |", widths[i]); - std::cout << folly::stringPrintf(fmt.c_str(), schema->getFieldName(i, 0)); - switch (schema->getFieldType(i, 0)->get_type()) { - case cpp2::SupportedType::BOOL: { - formats.emplace_back(folly::stringPrintf(" %%%ds |", widths[i])); - break; - } - case cpp2::SupportedType::INT: { - formats.emplace_back(folly::stringPrintf(" %%%dld |", widths[i])); - break; - } - case cpp2::SupportedType::FLOAT: { - formats.emplace_back(folly::stringPrintf(" %%%df |", widths[i])); - break; - } - case cpp2::SupportedType::DOUBLE: { - formats.emplace_back(folly::stringPrintf(" %%%df |", widths[i])); - break; - } - case cpp2::SupportedType::STRING: { - formats.emplace_back(folly::stringPrintf(" %%%ds |", widths[i])); - break; - } - case cpp2::SupportedType::VID: { - formats.emplace_back(folly::stringPrintf(" %%%dX |", widths[i])); - break; - } - default: { - formats.emplace_back(" *ERROR* |"); - } - } + for (auto& cname : (*resp.get_column_names())) { + std::string fmt = folly::stringPrintf(" %%%lds |", widths[idx]); + std::cout << folly::stringPrintf(fmt.c_str(), cname.c_str()); } std::cout << "\n"; - - return std::move(formats); } -#define PRINT_FIELD_VALUE(VT, FN, VAL) \ - VT val; \ - if (fIt->get ## FN (val) == ResultType::SUCCEEDED) { \ - std::cout << folly::stringPrintf(formats[fIdx].c_str(), (VAL)); \ - } else { \ - std::cout << " *BAD* |"; \ - } +#define PRINT_FIELD_VALUE(...) \ + std::cout << folly::stringPrintf(formats[cIdx].c_str(), __VA_ARGS__) -int32_t CmdProcessor::printData(const RowSetReader* dataReader, - const std::string& rowLine, - const std::vector& formats) const { - int32_t numRows = 0; +void CmdProcessor::printData(const cpp2::ExecutionResponse& resp, + const std::string& rowLine, + const std::vector& widths, + const std::vector& formats) const { + if (resp.get_rows() == nullptr) { + return; + } - auto* schema = dataReader->schema(); - auto rowIt = dataReader->begin(); - while (bool(rowIt)) { - int32_t fIdx = 0; - auto fIt = rowIt->begin(); + for (auto& row : (*resp.get_rows())) { + int32_t cIdx = 0; std::cout << "|"; - while (bool(fIt)) { - switch (schema->getFieldType(fIdx, 0)->get_type()) { - case cpp2::SupportedType::BOOL: { - PRINT_FIELD_VALUE(bool, Bool, (val ? "true" : "false")) + for (auto& col : row.get_columns()) { + switch (col.getType()) { + case cpp2::ColumnValue::Type::__EMPTY__: { + std::string fmt = folly::stringPrintf(" %%%ldc |", widths[cIdx]); + std::cout << folly::stringPrintf(fmt.c_str(), ' '); + break; + } + case cpp2::ColumnValue::Type::boolean: { + PRINT_FIELD_VALUE(col.get_boolean() ? "true" : "false"); + break; + } + case cpp2::ColumnValue::Type::integer: { + PRINT_FIELD_VALUE(col.get_integer()); break; } - case cpp2::SupportedType::INT: { - PRINT_FIELD_VALUE(int64_t, Int, val) + case cpp2::ColumnValue::Type::id: { + PRINT_FIELD_VALUE(col.get_id()); break; } - case cpp2::SupportedType::FLOAT: { - PRINT_FIELD_VALUE(float, Float, val) + case cpp2::ColumnValue::Type::single_precision: { + PRINT_FIELD_VALUE(col.get_single_precision()); break; } - case cpp2::SupportedType::DOUBLE: { - PRINT_FIELD_VALUE(double, Double, val) + case cpp2::ColumnValue::Type::double_precision: { + PRINT_FIELD_VALUE(col.get_double_precision()); break; } - case cpp2::SupportedType::STRING: { - PRINT_FIELD_VALUE(folly::StringPiece, String, val.toString().c_str()) + case cpp2::ColumnValue::Type::str: { + PRINT_FIELD_VALUE(col.get_str().c_str()); break; } - case cpp2::SupportedType::VID: { - PRINT_FIELD_VALUE(int64_t, Vid, val) + case cpp2::ColumnValue::Type::timestamp: { + PRINT_FIELD_VALUE(col.get_timestamp()); break; } - default: { - std::cout << " *ERROR* |"; + case cpp2::ColumnValue::Type::year: { + PRINT_FIELD_VALUE(col.get_year()); + break; + } + case cpp2::ColumnValue::Type::month: { + cpp2::YearMonth month = col.get_month(); + PRINT_FIELD_VALUE(month.get_year(), month.get_month()); + break; + } + case cpp2::ColumnValue::Type::date: { + cpp2::Date date = col.get_date(); + PRINT_FIELD_VALUE(date.get_year(), date.get_month(), date.get_day()); + break; + } + case cpp2::ColumnValue::Type::datetime: { + cpp2::DateTime dt = col.get_datetime(); + PRINT_FIELD_VALUE(dt.get_year(), + dt.get_month(), + dt.get_day(), + dt.get_hour(), + dt.get_minute(), + dt.get_second(), + dt.get_millisec(), + dt.get_microsec()); + break; } } - ++fIt; - ++fIdx; + ++cIdx; } std::cout << "\n" << rowLine << "\n"; - ++numRows; - ++rowIt; } - - return numRows; } #undef PRINT_FIELD_VALUE @@ -231,23 +323,27 @@ bool CmdProcessor::processClientCmd(folly::StringPiece cmd, void CmdProcessor::processServerCmd(folly::StringPiece cmd) { time::Duration dur; - std::unique_ptr dataReader; - int32_t res = client_->execute(cmd, dataReader); - if (!res) { + cpp2::ExecutionResponse resp; + cpp2::ErrorCode res = client_->execute(cmd, resp); + if (res == cpp2::ErrorCode::SUCCEEDED) { // Succeeded - auto* schema = dataReader->schema(); - UNUSED(schema); - int32_t numRows = 0; - if (dataReader->schema()) { - // Only print when the schema is no empty - numRows = printResult(dataReader.get()); + printResult(resp); + if (resp.get_rows() != nullptr) { + std::cout << "Got " << resp.get_rows()->size() + << " rows (Time spent: " + << resp.get_latency_in_ms() << "/" + << dur.elapsedInMSec() << " ms)\n"; + } else { + std::cout << "Execution succeeded (Time spent: " + << resp.get_latency_in_ms() << "/" + << dur.elapsedInMSec() << " ms)\n"; } - std::cout << "Got " << numRows << " rows (Time spent: " - << client_->getServerLatency() << "/" - << dur.elapsedInMSec() << " ms)\n"; } else { - std::cout << "[ERROR (" << res << ")] " - << client_->getErrorStr() << "\n"; + // TODO(sye) Need to print human-readable error strings + auto msg = resp.get_error_msg(); + std::cout << "[ERROR (" << static_cast(res) + << ")]: " << (msg != nullptr ? *msg : "") + << "\n"; } } diff --git a/console/CmdProcessor.h b/console/CmdProcessor.h index 88b5a1be8ed..8de95f7c96b 100644 --- a/console/CmdProcessor.h +++ b/console/CmdProcessor.h @@ -34,15 +34,17 @@ class CmdProcessor final { void processServerCmd(folly::StringPiece cmd); - std::vector calColumnWidths(const RowSetReader* dataReader) const; - - int32_t printResult(const RowSetReader* dataReader) const; - std::vector printHeader(const RowSetReader* dataReader, - const std::vector& widths) const; - // The method returns the total number of rows - int32_t printData(const RowSetReader* dataReader, - const std::string& rowLine, - const std::vector& formats) const; + void calColumnWidths(const cpp2::ExecutionResponse& resp, + std::vector& widths, + std::vector& formats) const; + + void printResult(const cpp2::ExecutionResponse& resp) const; + void printHeader(const cpp2::ExecutionResponse& resp, + const std::vector& widths) const; + void printData(const cpp2::ExecutionResponse& resp, + const std::string& rowLine, + const std::vector& widths, + const std::vector& formats) const; }; } // namespace vgraph diff --git a/dataman/ResultSchemaProvider.cpp b/dataman/ResultSchemaProvider.cpp index 9fdc2a6213d..b537556da51 100644 --- a/dataman/ResultSchemaProvider.cpp +++ b/dataman/ResultSchemaProvider.cpp @@ -11,6 +11,7 @@ namespace vesoft { namespace vgraph { using namespace folly::hash; +using namespace storage; /*********************************** * diff --git a/dataman/ResultSchemaProvider.h b/dataman/ResultSchemaProvider.h index ecfb2cf48bc..5be893138ac 100644 --- a/dataman/ResultSchemaProvider.h +++ b/dataman/ResultSchemaProvider.h @@ -14,24 +14,25 @@ namespace vesoft { namespace vgraph { class ResultSchemaProvider : public SchemaProviderIf { - using ColumnDefs = std::vector; + using ColumnDefs = std::vector; public: class ResultSchemaField : public Field { public: - explicit ResultSchemaField(const cpp2::ColumnDef* col = nullptr); + explicit ResultSchemaField( + const storage::cpp2::ColumnDef* col = nullptr); const char* getName() const override; - const cpp2::ValueType* getType() const override; + const storage::cpp2::ValueType* getType() const override; bool isValid() const override; private: - const cpp2::ColumnDef* column_; + const storage::cpp2::ColumnDef* column_; }; public: - explicit ResultSchemaProvider(cpp2::Schema&&); + explicit ResultSchemaProvider(storage::cpp2::Schema&&); virtual ~ResultSchemaProvider() = default; int32_t getLatestVer() const noexcept override; @@ -41,10 +42,12 @@ class ResultSchemaProvider : public SchemaProviderIf { int32_t ver) const override; const char* getFieldName(int32_t index, int32_t ver) const override; - const cpp2::ValueType* getFieldType(int32_t index, - int32_t ver) const override; - const cpp2::ValueType* getFieldType(const folly::StringPiece name, - int32_t ver) const override; + const storage::cpp2::ValueType* getFieldType( + int32_t index, + int32_t ver) const override; + const storage::cpp2::ValueType* getFieldType( + const folly::StringPiece name, + int32_t ver) const override; std::unique_ptr field(int32_t index, int32_t ver) const override; std::unique_ptr field(const folly::StringPiece name, diff --git a/dataman/RowReader.cpp b/dataman/RowReader.cpp index 4e1f3151852..8fcb6e0dcc9 100644 --- a/dataman/RowReader.cpp +++ b/dataman/RowReader.cpp @@ -194,19 +194,19 @@ int32_t RowReader::schemaVer() const noexcept { int64_t RowReader::skipToNext(int32_t index, int64_t offset) const noexcept { - const cpp2::ValueType* vType = schema_->getFieldType(index, schemaVer_); + const storage::cpp2::ValueType* vType = schema_->getFieldType(index, schemaVer_); CHECK(vType) << "No schema for the index " << index; if (offsets_[index + 1] >= 0) { return offsets_[index + 1]; } switch (vType->get_type()) { - case cpp2::SupportedType::BOOL: { + case storage::cpp2::SupportedType::BOOL: { // One byte offset++; break; } - case cpp2::SupportedType::INT: { + case storage::cpp2::SupportedType::INT: { int64_t v; int32_t len = readInteger(offset, v); if (len <= 0) { @@ -215,17 +215,17 @@ int64_t RowReader::skipToNext(int32_t index, int64_t offset) const noexcept { offset += len; break; } - case cpp2::SupportedType::FLOAT: { + case storage::cpp2::SupportedType::FLOAT: { // Eight bytes offset += sizeof(float); break; } - case cpp2::SupportedType::DOUBLE: { + case storage::cpp2::SupportedType::DOUBLE: { // Eight bytes offset += sizeof(double); break; } - case cpp2::SupportedType::STRING: { + case storage::cpp2::SupportedType::STRING: { int64_t strLen; int32_t intLen = readInteger(offset, strLen); if (intLen <= 0) { @@ -234,7 +234,7 @@ int64_t RowReader::skipToNext(int32_t index, int64_t offset) const noexcept { offset += intLen + strLen; break; } - case cpp2::SupportedType::VID: { + case storage::cpp2::SupportedType::VID: { // Eight bytes offset += sizeof(int64_t); break; @@ -338,12 +338,12 @@ int32_t RowReader::readVid(int64_t offset, int64_t& v) const noexcept { ResultType RowReader::getBool(int32_t index, int64_t& offset, bool& v) const noexcept { switch (schema_->getFieldType(index, schemaVer_)->get_type()) { - case cpp2::SupportedType::BOOL: { + case storage::cpp2::SupportedType::BOOL: { v = intToBool(data_[offset]); offset++; break; } - case cpp2::SupportedType::INT: { + case storage::cpp2::SupportedType::INT: { int64_t intV; int32_t numBytes = readInteger(offset, intV); if (numBytes > 0) { @@ -354,7 +354,7 @@ ResultType RowReader::getBool(int32_t index, int64_t& offset, bool& v) } break; } - case cpp2::SupportedType::STRING: { + case storage::cpp2::SupportedType::STRING: { folly::StringPiece strV; int32_t numBytes = readString(offset, strV); if (numBytes > 0) { @@ -377,7 +377,7 @@ ResultType RowReader::getBool(int32_t index, int64_t& offset, bool& v) ResultType RowReader::getFloat(int32_t index, int64_t& offset, float& v) const noexcept { switch (schema_->getFieldType(index, schemaVer_)->get_type()) { - case cpp2::SupportedType::FLOAT: { + case storage::cpp2::SupportedType::FLOAT: { int32_t numBytes = readFloat(offset, v); if (numBytes < 0) { return static_cast(numBytes); @@ -385,7 +385,7 @@ ResultType RowReader::getFloat(int32_t index, int64_t& offset, float& v) offset += numBytes; break; } - case cpp2::SupportedType::DOUBLE: { + case storage::cpp2::SupportedType::DOUBLE: { double d; int32_t numBytes = readDouble(offset, d); if (numBytes < 0) { @@ -407,7 +407,7 @@ ResultType RowReader::getFloat(int32_t index, int64_t& offset, float& v) ResultType RowReader::getDouble(int32_t index, int64_t& offset, double& v) const noexcept { switch (schema_->getFieldType(index, schemaVer_)->get_type()) { - case cpp2::SupportedType::FLOAT: { + case storage::cpp2::SupportedType::FLOAT: { float f; int32_t numBytes = readFloat(offset, f); if (numBytes < 0) { @@ -417,7 +417,7 @@ ResultType RowReader::getDouble(int32_t index, int64_t& offset, double& v) offset += numBytes; break; } - case cpp2::SupportedType::DOUBLE: { + case storage::cpp2::SupportedType::DOUBLE: { int32_t numBytes = readDouble(offset, v); if (numBytes < 0) { return static_cast(numBytes); @@ -438,7 +438,7 @@ ResultType RowReader::getString(int32_t index, int64_t& offset, folly::StringPiece& v) const noexcept { switch (schema_->getFieldType(index, schemaVer_)->get_type()) { - case cpp2::SupportedType::STRING: { + case storage::cpp2::SupportedType::STRING: { int32_t numBytes = readString(offset, v); if (numBytes < 0) { return static_cast(numBytes); @@ -458,7 +458,7 @@ ResultType RowReader::getString(int32_t index, ResultType RowReader::getVid(int32_t index, int64_t& offset, int64_t& v) const noexcept { switch (schema_->getFieldType(index, schemaVer_)->get_type()) { - case cpp2::SupportedType::INT: { + case storage::cpp2::SupportedType::INT: { int32_t numBytes = readInteger(offset, v); if (numBytes < 0) { return static_cast(numBytes); @@ -466,7 +466,7 @@ ResultType RowReader::getVid(int32_t index, int64_t& offset, int64_t& v) offset += numBytes; break; } - case cpp2::SupportedType::VID: { + case storage::cpp2::SupportedType::VID: { int32_t numBytes = readVid(offset, v); if (numBytes < 0) { return static_cast(numBytes); diff --git a/dataman/RowReader.inl b/dataman/RowReader.inl index 4a79d830202..783d6875ba2 100644 --- a/dataman/RowReader.inl +++ b/dataman/RowReader.inl @@ -28,7 +28,7 @@ template typename std::enable_if::value, ResultType>::type RowReader::getInt(int32_t index, int64_t& offset, T& v) const noexcept { switch (schema_->getFieldType(index, schemaVer_)->get_type()) { - case cpp2::SupportedType::INT: { + case storage::cpp2::SupportedType::INT: { int32_t numBytes = readInteger(offset, v); if (numBytes < 0) { return static_cast(numBytes); diff --git a/dataman/RowSetReader.cpp b/dataman/RowSetReader.cpp index bb88b083060..d999c632d00 100644 --- a/dataman/RowSetReader.cpp +++ b/dataman/RowSetReader.cpp @@ -83,7 +83,7 @@ bool RowSetReader::Iterator::operator==(const Iterator& rhs) { * RowSetReader class * **********************************/ -RowSetReader::RowSetReader(cpp2::ExecutionResponse& resp) +RowSetReader::RowSetReader(storage::cpp2::QueryResponse& resp) : takeOwnership_(true) { auto schema = resp.get_schema(); if (schema) { diff --git a/dataman/RowSetReader.h b/dataman/RowSetReader.h index f10bfa18728..0713fce7dfc 100644 --- a/dataman/RowSetReader.h +++ b/dataman/RowSetReader.h @@ -8,7 +8,7 @@ #define DATAMAN_ROWSETREADER_H_ #include "base/Base.h" -#include "interface/gen-cpp2/vgraph_types.h" +#include "interface/gen-cpp2/storage_types.h" #include "dataman/SchemaProviderIf.h" namespace vesoft { @@ -55,7 +55,7 @@ class RowSetReader { // // In this case, the RowSetReader will take the ownership of the schema // and the data - explicit RowSetReader(cpp2::ExecutionResponse& resp); + explicit RowSetReader(storage::cpp2::QueryResponse& resp); // Constructor to process the property value // diff --git a/dataman/RowUpdater.cpp b/dataman/RowUpdater.cpp index ae01911a36a..9b420a90398 100644 --- a/dataman/RowUpdater.cpp +++ b/dataman/RowUpdater.cpp @@ -36,27 +36,27 @@ void RowUpdater::encodeTo(std::string& encoded) const noexcept { auto it = schema_->begin(schemaVer_); while(bool(it)) { switch(it->getType()->get_type()) { - case cpp2::SupportedType::BOOL: { + case storage::cpp2::SupportedType::BOOL: { RU_OUTPUT_VALUE(bool, Bool, false); break; } - case cpp2::SupportedType::INT: { + case storage::cpp2::SupportedType::INT: { RU_OUTPUT_VALUE(int64_t, Int, 0); break; } - case cpp2::SupportedType::FLOAT: { + case storage::cpp2::SupportedType::FLOAT: { RU_OUTPUT_VALUE(float, Float, (float)0.0); break; } - case cpp2::SupportedType::DOUBLE: { + case storage::cpp2::SupportedType::DOUBLE: { RU_OUTPUT_VALUE(double, Double, (double)0.0); break; } - case cpp2::SupportedType::STRING: { + case storage::cpp2::SupportedType::STRING: { RU_OUTPUT_VALUE(folly::StringPiece, String, ""); break; } - case cpp2::SupportedType::VID: { + case storage::cpp2::SupportedType::VID: { RU_OUTPUT_VALUE(int64_t, Vid, 0); break; } @@ -82,7 +82,7 @@ ResultType RowUpdater::setBool(const folly::StringPiece name, uint64_t hash; switch (type->get_type()) { - case cpp2::SupportedType::BOOL: + case storage::cpp2::SupportedType::BOOL: hash = SpookyHashV2::Hash64(name.begin(), name.size(), 0); updatedFields_[hash] = v; break; @@ -100,11 +100,11 @@ ResultType RowUpdater::setFloat(const folly::StringPiece name, uint64_t hash; switch (type->get_type()) { - case cpp2::SupportedType::FLOAT: + case storage::cpp2::SupportedType::FLOAT: hash = SpookyHashV2::Hash64(name.begin(), name.size(), 0); updatedFields_[hash] = v; break; - case cpp2::SupportedType::DOUBLE: + case storage::cpp2::SupportedType::DOUBLE: hash = SpookyHashV2::Hash64(name.begin(), name.size(), 0); updatedFields_[hash] = (double)v; break; @@ -122,11 +122,11 @@ ResultType RowUpdater::setDouble(const folly::StringPiece name, uint64_t hash; switch (type->get_type()) { - case cpp2::SupportedType::FLOAT: + case storage::cpp2::SupportedType::FLOAT: hash = SpookyHashV2::Hash64(name.begin(), name.size(), 0); updatedFields_[hash] = (float)v; break; - case cpp2::SupportedType::DOUBLE: + case storage::cpp2::SupportedType::DOUBLE: hash = SpookyHashV2::Hash64(name.begin(), name.size(), 0); updatedFields_[hash] = v; break; @@ -144,7 +144,7 @@ ResultType RowUpdater::setString(const folly::StringPiece name, uint64_t hash; switch (type->get_type()) { - case cpp2::SupportedType::STRING: + case storage::cpp2::SupportedType::STRING: hash = SpookyHashV2::Hash64(name.begin(), name.size(), 0); updatedFields_[hash] = std::move(v.toString()); break; @@ -162,7 +162,7 @@ ResultType RowUpdater::setVid(const folly::StringPiece name, uint64_t hash; switch (type->get_type()) { - case cpp2::SupportedType::VID: + case storage::cpp2::SupportedType::VID: hash = SpookyHashV2::Hash64(name.begin(), name.size(), 0); updatedFields_[hash] = v; break; diff --git a/dataman/RowUpdater.h b/dataman/RowUpdater.h index 7c3158172c6..b114a3397d0 100644 --- a/dataman/RowUpdater.h +++ b/dataman/RowUpdater.h @@ -80,7 +80,8 @@ class RowUpdater { #define RU_GET_TYPE_BY_NAME() \ - const cpp2::ValueType* type = schema_->getFieldType(name, schemaVer_); \ + const storage::cpp2::ValueType* type \ + = schema_->getFieldType(name, schemaVer_); \ if (!type) { \ return ResultType::E_NAME_NOT_FOUND; \ } diff --git a/dataman/RowUpdater.inl b/dataman/RowUpdater.inl index 2dc401fedfe..bb74d24c636 100644 --- a/dataman/RowUpdater.inl +++ b/dataman/RowUpdater.inl @@ -14,7 +14,7 @@ RowUpdater::setInt(const folly::StringPiece name, T v) noexcept { uint64_t hash; switch (type->get_type()) { - case cpp2::SupportedType::INT: + case storage::cpp2::SupportedType::INT: hash = folly::hash::SpookyHashV2::Hash64(name.begin(), name.size(), 0); diff --git a/dataman/RowWriter.cpp b/dataman/RowWriter.cpp index 1705d62222d..ecc4542e6a0 100644 --- a/dataman/RowWriter.cpp +++ b/dataman/RowWriter.cpp @@ -10,6 +10,8 @@ namespace vesoft { namespace vgraph { +using namespace storage; + RowWriter::RowWriter(SchemaProviderIf* schema, int32_t schemaVer) : schema_(schema) , schemaVer_(schemaVer) { diff --git a/dataman/RowWriter.h b/dataman/RowWriter.h index 10dcc05c117..a2d68d5fe6a 100644 --- a/dataman/RowWriter.h +++ b/dataman/RowWriter.h @@ -46,12 +46,12 @@ class RowWriter { friend class RowWriter; template explicit ColType(VType&& type) : type_(std::forward(type)) {} - explicit ColType(cpp2::SupportedType type) { + explicit ColType(storage::cpp2::SupportedType type) { type_.set_type(type); } ColType(ColType&& rhs) : type_(std::move(rhs.type_)) {} private: - cpp2::ValueType type_; + storage::cpp2::ValueType type_; }; // Skip next few columns. Default values will be written for those @@ -84,7 +84,7 @@ class RowWriter { // Move the schema out of the writer // After the schema being moved, **NO MORE** write should happen - cpp2::Schema moveSchema(); + storage::cpp2::Schema moveSchema(); // Data stream RowWriter& operator<<(bool v) noexcept; @@ -130,11 +130,11 @@ class RowWriter { #define RW_GET_COLUMN_TYPE(STYPE) \ - const cpp2::ValueType* type; \ + const storage::cpp2::ValueType* type; \ if (colNum_ >= schema_->getNumFields(schemaVer_)) { \ CHECK(!!schemaWriter_) << "SchemaWriter cannot be NULL"; \ if (!colType_) { \ - colType_.reset(new ColType(cpp2::SupportedType::STYPE)); \ + colType_.reset(new ColType(storage::cpp2::SupportedType::STYPE)); \ } \ type = &(colType_->type_); \ } else { \ diff --git a/dataman/RowWriter.inl b/dataman/RowWriter.inl index 70774c1acad..67d652f4ff8 100644 --- a/dataman/RowWriter.inl +++ b/dataman/RowWriter.inl @@ -13,11 +13,11 @@ RowWriter::operator<<(T v) noexcept { RW_GET_COLUMN_TYPE(INT) switch (type->get_type()) { - case cpp2::SupportedType::INT: { + case storage::cpp2::SupportedType::INT: { writeInt(v); break; } - case cpp2::SupportedType::VID: { + case storage::cpp2::SupportedType::VID: { cord_ << (uint64_t)v; break; } diff --git a/dataman/SchemaProviderIf.h b/dataman/SchemaProviderIf.h index 2b54314af60..a4555042a88 100644 --- a/dataman/SchemaProviderIf.h +++ b/dataman/SchemaProviderIf.h @@ -8,7 +8,7 @@ #define DATAMAN_SCHEMAPROVIDERIF_H_ #include "base/Base.h" -#include "interface/gen-cpp2/vgraph_types.h" +#include "interface/gen-cpp2/storage_types.h" namespace vesoft { namespace vgraph { @@ -21,7 +21,7 @@ class SchemaProviderIf { virtual ~Field() = default; virtual const char* getName() const = 0; - virtual const cpp2::ValueType* getType() const = 0; + virtual const storage::cpp2::ValueType* getType() const = 0; virtual bool isValid() const = 0; }; @@ -60,10 +60,12 @@ class SchemaProviderIf { virtual const char* getFieldName(int32_t index, int32_t ver) const = 0; - virtual const cpp2::ValueType* getFieldType(int32_t index, - int32_t ver) const = 0; - virtual const cpp2::ValueType* getFieldType(const folly::StringPiece name, - int32_t ver) const = 0; + virtual const storage::cpp2::ValueType* getFieldType( + int32_t index, + int32_t ver) const = 0; + virtual const storage::cpp2::ValueType* getFieldType( + const folly::StringPiece name, + int32_t ver) const = 0; virtual std::unique_ptr field(int32_t index, int32_t ver) const = 0; virtual std::unique_ptr field(const folly::StringPiece name, diff --git a/dataman/SchemaWriter.cpp b/dataman/SchemaWriter.cpp index 32a9015b87b..fb63a71ae9e 100644 --- a/dataman/SchemaWriter.cpp +++ b/dataman/SchemaWriter.cpp @@ -10,6 +10,8 @@ namespace vesoft { namespace vgraph { +using namespace storage; + cpp2::Schema SchemaWriter::moveSchema() noexcept { cpp2::Schema schema; schema.set_columns(std::move(columns_)); diff --git a/dataman/SchemaWriter.h b/dataman/SchemaWriter.h index 6bfb59ffe5d..a9148fb8b30 100644 --- a/dataman/SchemaWriter.h +++ b/dataman/SchemaWriter.h @@ -18,21 +18,21 @@ class SchemaWriter : public ResultSchemaProvider { SchemaWriter() = default; // Move the schema out of the writer - cpp2::Schema moveSchema() noexcept; + storage::cpp2::Schema moveSchema() noexcept; SchemaWriter& appendCol(const char* name, - cpp2::SupportedType type) noexcept; + storage::cpp2::SupportedType type) noexcept; SchemaWriter& appendCol(const folly::StringPiece name, - cpp2::SupportedType type) noexcept; + storage::cpp2::SupportedType type) noexcept; SchemaWriter& appendCol(std::string&& name, - cpp2::SupportedType type) noexcept; + storage::cpp2::SupportedType type) noexcept; SchemaWriter& appendCol(const char* name, - cpp2::ValueType&& type)noexcept; + storage::cpp2::ValueType&& type)noexcept; SchemaWriter& appendCol(const folly::StringPiece name, - cpp2::ValueType&& type)noexcept; + storage::cpp2::ValueType&& type)noexcept; SchemaWriter& appendCol(std::string&& name, - cpp2::ValueType&& type)noexcept; + storage::cpp2::ValueType&& type)noexcept; private: }; diff --git a/dataman/ThriftSchemaProvider.cpp b/dataman/ThriftSchemaProvider.cpp index d7183ab84b0..6dfb78f1e1f 100644 --- a/dataman/ThriftSchemaProvider.cpp +++ b/dataman/ThriftSchemaProvider.cpp @@ -11,6 +11,7 @@ namespace vesoft { namespace vgraph { using namespace folly::hash; +using namespace storage; /*********************************** * diff --git a/dataman/ThriftSchemaProvider.h b/dataman/ThriftSchemaProvider.h index f64ca89c3a6..71ee72948b9 100644 --- a/dataman/ThriftSchemaProvider.h +++ b/dataman/ThriftSchemaProvider.h @@ -19,24 +19,25 @@ namespace vgraph { * It will not take the ownership of the schema */ class ThriftSchemaProvider : public SchemaProviderIf { - using ColumnDefs = std::vector; + using ColumnDefs = std::vector; public: class ThriftSchemaField : public Field { public: - explicit ThriftSchemaField(const cpp2::ColumnDef* col = nullptr); + explicit ThriftSchemaField( + const storage::cpp2::ColumnDef* col = nullptr); const char* getName() const override; - const cpp2::ValueType* getType() const override; + const storage::cpp2::ValueType* getType() const override; bool isValid() const override; private: - const cpp2::ColumnDef* column_; + const storage::cpp2::ColumnDef* column_; }; public: - explicit ThriftSchemaProvider(const cpp2::Schema*); + explicit ThriftSchemaProvider(const storage::cpp2::Schema*); virtual ~ThriftSchemaProvider() = default; int32_t getLatestVer() const noexcept override; @@ -46,10 +47,12 @@ class ThriftSchemaProvider : public SchemaProviderIf { int32_t ver) const override; const char* getFieldName(int32_t index, int32_t ver) const override; - const cpp2::ValueType* getFieldType(int32_t index, - int32_t ver) const override; - const cpp2::ValueType* getFieldType(const folly::StringPiece name, - int32_t ver) const override; + const storage::cpp2::ValueType* getFieldType( + int32_t index, + int32_t ver) const override; + const storage::cpp2::ValueType* getFieldType( + const folly::StringPiece name, + int32_t ver) const override; std::unique_ptr field(int32_t index, int32_t ver) const override; std::unique_ptr field(const folly::StringPiece name, diff --git a/dataman/test/CMakeLists.txt b/dataman/test/CMakeLists.txt index a81ddcd3a0e..a2d08f5f997 100644 --- a/dataman/test/CMakeLists.txt +++ b/dataman/test/CMakeLists.txt @@ -2,7 +2,7 @@ add_executable( row_reader_test RowReaderTest.cpp $ - $ + $ $ ) target_link_libraries( @@ -29,7 +29,7 @@ add_executable( row_writer_test RowWriterTest.cpp $ - $ + $ $ ) target_link_libraries( @@ -56,7 +56,7 @@ add_executable( row_updater_test RowUpdaterTest.cpp $ - $ + $ $ ) target_link_libraries( @@ -83,7 +83,7 @@ add_executable( rowset_reader_writer_test RowSetReaderWriterTest.cpp $ - $ + $ $ ) target_link_libraries( @@ -110,7 +110,7 @@ add_executable( row_writer_bm RowWriterBenchmark.cpp $ - $ + $ $ ) target_link_libraries( @@ -137,7 +137,7 @@ add_executable( row_reader_bm RowReaderBenchmark.cpp $ - $ + $ $ ) target_link_libraries( diff --git a/dataman/test/RowReaderBenchmark.cpp b/dataman/test/RowReaderBenchmark.cpp index 95ab8608bb6..ca97de45f8b 100644 --- a/dataman/test/RowReaderBenchmark.cpp +++ b/dataman/test/RowReaderBenchmark.cpp @@ -29,50 +29,55 @@ std::string dataMix; void prepareSchema() { for (int i = 0; i < 32; i++) { - schemaAllInts.appendCol(folly::stringPrintf("col%02d", i), - cpp2::SupportedType::INT); - schemaAllBools.appendCol(folly::stringPrintf("col%02d", i), - cpp2::SupportedType::BOOL); - schemaAllStrings.appendCol(folly::stringPrintf("col%02d", i), - cpp2::SupportedType::STRING); - schemaAllDoubles.appendCol(folly::stringPrintf("col%02d", i), - cpp2::SupportedType::DOUBLE); - schemaAllVids.appendCol(folly::stringPrintf("col%02d", i), - cpp2::SupportedType::VID); + schemaAllInts.appendCol( + folly::stringPrintf("col%02d", i), + vesoft::storage::cpp2::SupportedType::INT); + schemaAllBools.appendCol( + folly::stringPrintf("col%02d", i), + vesoft::storage::cpp2::SupportedType::BOOL); + schemaAllStrings.appendCol( + folly::stringPrintf("col%02d", i), + vesoft::storage::cpp2::SupportedType::STRING); + schemaAllDoubles.appendCol( + folly::stringPrintf("col%02d", i), + vesoft::storage::cpp2::SupportedType::DOUBLE); + schemaAllVids.appendCol( + folly::stringPrintf("col%02d", i), + vesoft::storage::cpp2::SupportedType::VID); } - schemaMix.appendCol("col01", cpp2::SupportedType::BOOL) - .appendCol("col02", cpp2::SupportedType::BOOL) - .appendCol("col03", cpp2::SupportedType::BOOL) - .appendCol("col04", cpp2::SupportedType::BOOL) - .appendCol("col05", cpp2::SupportedType::INT) - .appendCol("col06", cpp2::SupportedType::INT) - .appendCol("col07", cpp2::SupportedType::INT) - .appendCol("col08", cpp2::SupportedType::INT) - .appendCol("col09", cpp2::SupportedType::STRING) - .appendCol("col10", cpp2::SupportedType::STRING) - .appendCol("col11", cpp2::SupportedType::STRING) - .appendCol("col12", cpp2::SupportedType::STRING) - .appendCol("col13", cpp2::SupportedType::FLOAT) - .appendCol("col14", cpp2::SupportedType::FLOAT) - .appendCol("col15", cpp2::SupportedType::FLOAT) - .appendCol("col16", cpp2::SupportedType::FLOAT) - .appendCol("col17", cpp2::SupportedType::DOUBLE) - .appendCol("col18", cpp2::SupportedType::DOUBLE) - .appendCol("col19", cpp2::SupportedType::DOUBLE) - .appendCol("col20", cpp2::SupportedType::DOUBLE) - .appendCol("col21", cpp2::SupportedType::VID) - .appendCol("col22", cpp2::SupportedType::VID) - .appendCol("col23", cpp2::SupportedType::VID) - .appendCol("col24", cpp2::SupportedType::VID) - .appendCol("col25", cpp2::SupportedType::INT) - .appendCol("col26", cpp2::SupportedType::INT) - .appendCol("col27", cpp2::SupportedType::INT) - .appendCol("col28", cpp2::SupportedType::INT) - .appendCol("col29", cpp2::SupportedType::INT) - .appendCol("col30", cpp2::SupportedType::INT) - .appendCol("col31", cpp2::SupportedType::INT) - .appendCol("col32", cpp2::SupportedType::INT); + schemaMix.appendCol("col01",vesoft::storage::cpp2::SupportedType::BOOL) + .appendCol("col02",vesoft::storage::cpp2::SupportedType::BOOL) + .appendCol("col03",vesoft::storage::cpp2::SupportedType::BOOL) + .appendCol("col04",vesoft::storage::cpp2::SupportedType::BOOL) + .appendCol("col05",vesoft::storage::cpp2::SupportedType::INT) + .appendCol("col06",vesoft::storage::cpp2::SupportedType::INT) + .appendCol("col07",vesoft::storage::cpp2::SupportedType::INT) + .appendCol("col08",vesoft::storage::cpp2::SupportedType::INT) + .appendCol("col09",vesoft::storage::cpp2::SupportedType::STRING) + .appendCol("col10",vesoft::storage::cpp2::SupportedType::STRING) + .appendCol("col11",vesoft::storage::cpp2::SupportedType::STRING) + .appendCol("col12",vesoft::storage::cpp2::SupportedType::STRING) + .appendCol("col13",vesoft::storage::cpp2::SupportedType::FLOAT) + .appendCol("col14",vesoft::storage::cpp2::SupportedType::FLOAT) + .appendCol("col15",vesoft::storage::cpp2::SupportedType::FLOAT) + .appendCol("col16",vesoft::storage::cpp2::SupportedType::FLOAT) + .appendCol("col17",vesoft::storage::cpp2::SupportedType::DOUBLE) + .appendCol("col18",vesoft::storage::cpp2::SupportedType::DOUBLE) + .appendCol("col19",vesoft::storage::cpp2::SupportedType::DOUBLE) + .appendCol("col20",vesoft::storage::cpp2::SupportedType::DOUBLE) + .appendCol("col21",vesoft::storage::cpp2::SupportedType::VID) + .appendCol("col22",vesoft::storage::cpp2::SupportedType::VID) + .appendCol("col23",vesoft::storage::cpp2::SupportedType::VID) + .appendCol("col24",vesoft::storage::cpp2::SupportedType::VID) + .appendCol("col25",vesoft::storage::cpp2::SupportedType::INT) + .appendCol("col26",vesoft::storage::cpp2::SupportedType::INT) + .appendCol("col27",vesoft::storage::cpp2::SupportedType::INT) + .appendCol("col28",vesoft::storage::cpp2::SupportedType::INT) + .appendCol("col29",vesoft::storage::cpp2::SupportedType::INT) + .appendCol("col30",vesoft::storage::cpp2::SupportedType::INT) + .appendCol("col31",vesoft::storage::cpp2::SupportedType::INT) + .appendCol("col32",vesoft::storage::cpp2::SupportedType::INT); } diff --git a/dataman/test/RowReaderTest.cpp b/dataman/test/RowReaderTest.cpp index 2837041a447..20c4bb219d7 100644 --- a/dataman/test/RowReaderTest.cpp +++ b/dataman/test/RowReaderTest.cpp @@ -29,7 +29,7 @@ TEST(RowReader, headerInfo) { // Insert 33 fields into schema, so we will get 2 offsets for (int i = 0; i < 33; i++) { schema.appendCol(folly::stringPrintf("Column%02d", i), - cpp2::SupportedType::INT); + storage::cpp2::SupportedType::INT); } // With schema version and offsets @@ -61,24 +61,28 @@ TEST(RowReader, encodedData) { SchemaWriter schema; // Col 0: bool_col1 -- BOOL - schema.appendCol("bool_col1", cpp2::SupportedType::BOOL); + schema.appendCol("bool_col1", storage::cpp2::SupportedType::BOOL); // Col 1: str_col1 -- STRING schema.appendCol(folly::stringPrintf("str_col1"), - cpp2::SupportedType::STRING); + storage::cpp2::SupportedType::STRING); // Col 2: int_col1 -- INT - schema.appendCol(colName1, cpp2::SupportedType::INT); + schema.appendCol(colName1, storage::cpp2::SupportedType::INT); // Col 3: int_col2 -- INT - schema.appendCol(colName2, cpp2::SupportedType::INT); + schema.appendCol(colName2, storage::cpp2::SupportedType::INT); // Col 4: vid_col -- VID - schema.appendCol(folly::StringPiece(colName3), cpp2::SupportedType::VID); + schema.appendCol(folly::StringPiece(colName3), + storage::cpp2::SupportedType::VID); // Col 5: str_col2 -- STRING - schema.appendCol("str_col2", cpp2::SupportedType::STRING); + schema.appendCol("str_col2", storage::cpp2::SupportedType::STRING); // Col 6: bool_col2 -- BOOL - schema.appendCol(std::string("bool_col2"), cpp2::SupportedType::BOOL); + schema.appendCol(std::string("bool_col2"), + storage::cpp2::SupportedType::BOOL); // Col 7: float_col -- FLOAT - schema.appendCol(std::string("float_col"), cpp2::SupportedType::FLOAT); + schema.appendCol(std::string("float_col"), + storage::cpp2::SupportedType::FLOAT); // Col 8: double_col -- DOUBLE - schema.appendCol(std::string("double_col"), cpp2::SupportedType::DOUBLE); + schema.appendCol(std::string("double_col"), + storage::cpp2::SupportedType::DOUBLE); std::string encoded; // Single byte header (Schema version is 0, no offset) @@ -159,7 +163,7 @@ TEST(RowReader, encodedData) { EXPECT_EQ(ResultType::SUCCEEDED, reader.getString("str_col1", sVal)); EXPECT_EQ(str1, sVal.toString()); - + // Col 2 EXPECT_EQ(ResultType::SUCCEEDED, reader.getInt(2, i32Val)); @@ -168,7 +172,7 @@ TEST(RowReader, encodedData) { EXPECT_EQ(ResultType::SUCCEEDED, reader.getInt("int_col1", i32Val)); EXPECT_EQ(100, i32Val); - + // Col 3 EXPECT_EQ(ResultType::SUCCEEDED, reader.getInt(3, i32Val)); @@ -181,7 +185,7 @@ TEST(RowReader, encodedData) { EXPECT_EQ(ResultType::SUCCEEDED, reader.getInt("int_col2", u64Val)); EXPECT_EQ(0xFFFFFFFFFFFFFFFFL, u64Val); - + // Col 4 EXPECT_EQ(ResultType::SUCCEEDED, reader.getVid(4, i64Val)); @@ -190,7 +194,7 @@ TEST(RowReader, encodedData) { EXPECT_EQ(ResultType::SUCCEEDED, reader.getVid("vid_col", i64Val)); EXPECT_EQ(0x8877665544332211L, i64Val); - + // Col 5 EXPECT_EQ(ResultType::SUCCEEDED, reader.getString(5, sVal)); @@ -199,7 +203,7 @@ TEST(RowReader, encodedData) { EXPECT_EQ(ResultType::SUCCEEDED, reader.getString("str_col2", sVal)); EXPECT_EQ(str2, sVal.toString()); - + // Col 6 EXPECT_EQ(ResultType::SUCCEEDED, reader.getBool(6, bVal)); @@ -246,7 +250,7 @@ TEST(RowReader, iterator) { SchemaWriter schema; for (int i = 0; i < 64; i++) { schema.appendCol(folly::stringPrintf("Col%02d", i), - cpp2::SupportedType::INT); + storage::cpp2::SupportedType::INT); encoded.append(1, i + 1); } diff --git a/dataman/test/RowSetReaderWriterTest.cpp b/dataman/test/RowSetReaderWriterTest.cpp index 25ba5b0ed32..875865fca8d 100644 --- a/dataman/test/RowSetReaderWriterTest.cpp +++ b/dataman/test/RowSetReaderWriterTest.cpp @@ -19,7 +19,7 @@ TEST(RowSetReaderWriter, allInts) { SchemaWriter schema; for (int i = 0; i < 33; i++) { schema.appendCol(folly::stringPrintf("col%02d", i), - cpp2::SupportedType::INT); + storage::cpp2::SupportedType::INT); } RowSetWriter rsWriter(&schema); diff --git a/dataman/test/RowUpdaterTest.cpp b/dataman/test/RowUpdaterTest.cpp index 7c76e8aa8f3..3d20400c90d 100644 --- a/dataman/test/RowUpdaterTest.cpp +++ b/dataman/test/RowUpdaterTest.cpp @@ -15,14 +15,14 @@ using namespace vesoft::vgraph; SchemaWriter schema; void prepareSchema() { - schema.appendCol("col1", cpp2::SupportedType::INT); - schema.appendCol("col2", cpp2::SupportedType::INT); - schema.appendCol("col3", cpp2::SupportedType::STRING); - schema.appendCol("col4", cpp2::SupportedType::STRING); - schema.appendCol("col5", cpp2::SupportedType::BOOL); - schema.appendCol("col6", cpp2::SupportedType::FLOAT); - schema.appendCol("col7", cpp2::SupportedType::VID); - schema.appendCol("col8", cpp2::SupportedType::DOUBLE); + schema.appendCol("col1", vesoft::storage::cpp2::SupportedType::INT); + schema.appendCol("col2", vesoft::storage::cpp2::SupportedType::INT); + schema.appendCol("col3", vesoft::storage::cpp2::SupportedType::STRING); + schema.appendCol("col4", vesoft::storage::cpp2::SupportedType::STRING); + schema.appendCol("col5", vesoft::storage::cpp2::SupportedType::BOOL); + schema.appendCol("col6", vesoft::storage::cpp2::SupportedType::FLOAT); + schema.appendCol("col7", vesoft::storage::cpp2::SupportedType::VID); + schema.appendCol("col8", vesoft::storage::cpp2::SupportedType::DOUBLE); } diff --git a/dataman/test/RowWriterBenchmark.cpp b/dataman/test/RowWriterBenchmark.cpp index 3d280bbb0db..13f742c9fe2 100644 --- a/dataman/test/RowWriterBenchmark.cpp +++ b/dataman/test/RowWriterBenchmark.cpp @@ -10,6 +10,7 @@ #include "dataman/RowWriter.h" using namespace vesoft::vgraph; +using namespace vesoft::storage; SchemaWriter schemaAllInts; SchemaWriter schemaAllBools; diff --git a/dataman/test/RowWriterTest.cpp b/dataman/test/RowWriterTest.cpp index 43f4ee8bb8e..83f9ce5269c 100644 --- a/dataman/test/RowWriterTest.cpp +++ b/dataman/test/RowWriterTest.cpp @@ -82,9 +82,10 @@ TEST(RowWriter, streamControl) { RowWriter writer(nullptr, 0x0000FFFF); writer << RowWriter::ColName("bool_col") << true << RowWriter::ColName("vid_col") - << RowWriter::ColType(cpp2::SupportedType::VID) << 10 - << RowWriter::ColType(cpp2::SupportedType::STRING) << "Hello World!" - << RowWriter::ColType(cpp2::SupportedType::DOUBLE) + << RowWriter::ColType(storage::cpp2::SupportedType::VID) << 10 + << RowWriter::ColType(storage::cpp2::SupportedType::STRING) + << "Hello World!" + << RowWriter::ColType(storage::cpp2::SupportedType::DOUBLE) << (float)3.1415926; std::string encoded = writer.encode(); @@ -144,13 +145,13 @@ TEST(RowWriter, offsetsCreation) { TEST(RowWriter, withSchema) { SchemaWriter schema; - schema.appendCol("col1", cpp2::SupportedType::INT); - schema.appendCol("col2", cpp2::SupportedType::INT); - schema.appendCol("col3", cpp2::SupportedType::STRING); - schema.appendCol("col4", cpp2::SupportedType::STRING); - schema.appendCol("col5", cpp2::SupportedType::BOOL); - schema.appendCol("col6", cpp2::SupportedType::FLOAT); - schema.appendCol("col7", cpp2::SupportedType::VID); + schema.appendCol("col1", storage::cpp2::SupportedType::INT); + schema.appendCol("col2", storage::cpp2::SupportedType::INT); + schema.appendCol("col3", storage::cpp2::SupportedType::STRING); + schema.appendCol("col4", storage::cpp2::SupportedType::STRING); + schema.appendCol("col5", storage::cpp2::SupportedType::BOOL); + schema.appendCol("col6", storage::cpp2::SupportedType::FLOAT); + schema.appendCol("col7", storage::cpp2::SupportedType::VID); RowWriter writer(&schema); writer << 1 << 2 << "Hello" << "World" << true @@ -203,14 +204,14 @@ TEST(RowWriter, withSchema) { TEST(RowWriter, skip) { SchemaWriter schema; - schema.appendCol("col1", cpp2::SupportedType::INT); - schema.appendCol("col2", cpp2::SupportedType::FLOAT); - schema.appendCol("col3", cpp2::SupportedType::INT); - schema.appendCol("col4", cpp2::SupportedType::STRING); - schema.appendCol("col5", cpp2::SupportedType::STRING); - schema.appendCol("col6", cpp2::SupportedType::BOOL); - schema.appendCol("col7", cpp2::SupportedType::VID); - schema.appendCol("col8", cpp2::SupportedType::DOUBLE); + schema.appendCol("col1", storage::cpp2::SupportedType::INT); + schema.appendCol("col2", storage::cpp2::SupportedType::FLOAT); + schema.appendCol("col3", storage::cpp2::SupportedType::INT); + schema.appendCol("col4", storage::cpp2::SupportedType::STRING); + schema.appendCol("col5", storage::cpp2::SupportedType::STRING); + schema.appendCol("col6", storage::cpp2::SupportedType::BOOL); + schema.appendCol("col7", storage::cpp2::SupportedType::VID); + schema.appendCol("col8", storage::cpp2::SupportedType::DOUBLE); RowWriter writer(&schema); // Implicitly skip the last two fields diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index f413cd18746..cf6b70b412e 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -1,5 +1,5 @@ add_custom_command( - OUTPUT + OUTPUT gen-cpp2/GraphDbService.cpp gen-cpp2/GraphDbServiceAsyncClient.cpp gen-cpp2/GraphDbService_processmap_binary.cpp @@ -7,13 +7,13 @@ add_custom_command( gen-cpp2/vgraph_constants.cpp gen-cpp2/vgraph_data.cpp gen-cpp2/vgraph_types.cpp - COMMAND "${CMAKE_HOME_DIRECTORY}/third-party/fbthrift/_install/bin/thrift1" "--allow-neg-enum-vals" "--templates" "${CMAKE_HOME_DIRECTORY}/third-party/fbthrift/_install/include/thrift/templates" "--gen" "mstch_cpp2:include_prefix=\"interface\",process_in_event_base,stack_arguments" "--gen" "java:hashcode" "--gen" "go" "--gen" "py:new_style" "-o" "." "./vgraph.thrift" + COMMAND "${CMAKE_HOME_DIRECTORY}/third-party/fbthrift/_install/bin/thrift1" "--allow-neg-enum-vals" "--templates" "${CMAKE_HOME_DIRECTORY}/third-party/fbthrift/_install/include/thrift/templates" "--gen" "mstch_cpp2:include_prefix=\"interface\",process_in_event_base,stack_arguments" "--gen" "java:hashcode" "--gen" "go" "-o" "." "./vgraph.thrift" DEPENDS vgraph.thrift ) add_custom_command( - OUTPUT + OUTPUT gen-cpp2/RaftexService.cpp gen-cpp2/RaftexServiceAsyncClient.cpp gen-cpp2/RaftexService_processmap_binary.cpp @@ -21,11 +21,25 @@ add_custom_command( gen-cpp2/raftex_constants.cpp gen-cpp2/raftex_data.cpp gen-cpp2/raftex_types.cpp - COMMAND "${CMAKE_HOME_DIRECTORY}/third-party/fbthrift/_install/bin/thrift1" "--allow-neg-enum-vals" "--templates" "${CMAKE_HOME_DIRECTORY}/third-party/fbthrift/_install/include/thrift/templates" "--gen" "mstch_cpp2:include_prefix=\"interface\",process_in_event_base,stack_arguments" "--gen" "java:hashcode" "--gen" "go" "--gen" "py:new_style" "-o" "." "./raftex.thrift" + COMMAND "${CMAKE_HOME_DIRECTORY}/third-party/fbthrift/_install/bin/thrift1" "--allow-neg-enum-vals" "--templates" "${CMAKE_HOME_DIRECTORY}/third-party/fbthrift/_install/include/thrift/templates" "--gen" "mstch_cpp2:include_prefix=\"interface\",process_in_event_base,stack_arguments" "--gen" "java:hashcode" "--gen" "go" "-o" "." "./raftex.thrift" DEPENDS raftex.thrift ) +add_custom_command( + OUTPUT + gen-cpp2/StorageService.cpp + gen-cpp2/StorageServiceAsyncClient.cpp + gen-cpp2/StorageService_processmap_binary.cpp + gen-cpp2/StorageService_processmap_compact.cpp + gen-cpp2/storage_constants.cpp + gen-cpp2/storage_data.cpp + gen-cpp2/storage_types.cpp + COMMAND "${CMAKE_HOME_DIRECTORY}/third-party/fbthrift/_install/bin/thrift1" "--allow-neg-enum-vals" "--templates" "${CMAKE_HOME_DIRECTORY}/third-party/fbthrift/_install/include/thrift/templates" "--gen" "mstch_cpp2:include_prefix=\"interface\",process_in_event_base,stack_arguments" "--gen" "java:hashcode" "--gen" "go" "-o" "." "./storage.thrift" + DEPENDS storage.thrift +) + + add_custom_target( clean-interface COMMAND "rm" "-fr" "gen-cpp2" "gen-java" "gen-go" "gen-py" @@ -56,3 +70,16 @@ add_library( gen-cpp2/raftex_types.cpp ) add_dependencies(raftex_thrift_obj tgt_fbthrift) + + +add_library( + storage_thrift_obj OBJECT + gen-cpp2/StorageService.cpp + gen-cpp2/StorageServiceAsyncClient.cpp + gen-cpp2/StorageService_processmap_binary.cpp + gen-cpp2/StorageService_processmap_compact.cpp + gen-cpp2/storage_constants.cpp + gen-cpp2/storage_data.cpp + gen-cpp2/storage_types.cpp +) +add_dependencies(storage_thrift_obj tgt_fbthrift) diff --git a/interface/raftex.thrift b/interface/raftex.thrift index 3c20dc1a520..d21c2c4cd05 100644 --- a/interface/raftex.thrift +++ b/interface/raftex.thrift @@ -4,12 +4,12 @@ * (found in the LICENSE.Apache file in the root directory) */ -namespace cpp vesoft.vgraph.raftex -namespace java vesoft.vgraph.raftex -namespace go vesoft.vgraph.raftex +namespace cpp vesoft.raftex +namespace java vesoft.raftex +namespace go vesoft.raftex -enum ResultCode { +enum ErrorCode { SUCCEEDED = 0; E_LOG_GAP = -1; E_LOG_STALE = -2; @@ -41,25 +41,25 @@ typedef i32 Port // A request to ask for vote struct AskForVoteRequest { - 1: GraphSpaceID space; // My graph space id - 2: PartitionID partition; // The data partition - 3: IPv4 candidateIp; // My IP - 4: Port candidatePort; // My port - 5: TermID term; // Proposed term (current term + 1) - 6: LogID committedLogId; // My last committed log id - 7: LogID lastLogId; // My last received log id + 1: GraphSpaceID space; // My graph space id + 2: PartitionID partition; // The data partition + 3: IPv4 candidate_ip; // My IP + 4: Port candidate_port; // My port + 5: TermID term; // Proposed term (current term + 1) + 6: LogID committed_log_id; // My last committed log id + 7: LogID last_log_id; // My last received log id } // Response message for the vote call struct AskForVoteResponse { - 1: ResultCode result; + 1: ErrorCode error_code; } struct LogEntry { - 1: bool sendToListenersToo; - 2: binary logStr; + 1: bool send_to_listeners_too; + 2: binary log_str; } @@ -67,43 +67,43 @@ struct LogEntry { AppendLogRequest serves two purposes: 1) Send a log message to followers and listeners - 2) Or, when logId == 0 and len(logStr) == 0, it serves as a heartbeat + 2) Or, when log_id == 0 and len(log_str) == 0, it serves as a heartbeat */ struct AppendLogRequest { // Fields 1 - 7 are common for both log appendent and heartbeat 1: GraphSpaceID space; 2: PartitionID partition; 3: TermID term; - 4: IPv4 leaderIp; - 5: Port leaderPort; - 6: LogID committedLogId; + 4: IPv4 leader_ip; + 5: Port leader_port; + 6: LogID committed_log_id; // This is the id of the first log in the current term - 7: LogID firstLogInTerm; + 7: LogID first_log_in_term; // Fields 8 and 9 are used for LogAppend. // - // In the case of heartbeat, firstLogId will be set zero and - // the logStrList will be empty + // In the case of heartbeat, first_log_id will be set zero and + // the log_str_list will be empty // - // In the case of LogAppend, firstLogId is the id for the first log - // in logStrList - 8: LogID firstLogId; - 9: list logStrList; + // In the case of LogAppend, first_log_id is the id for the first log + // in log_str_list + 8: LogID first_log_id; + 9: list log_str_list; // URI for snapshot - 10: binary snapshotURI; + 10: binary snapshot_uri; } struct AppendLogResponse { - 1: ResultCode result; + 1: ErrorCode error_code; 2: TermID term; - 3: IPv4 leaderIp; - 4: Port leaderPort; - 5: LogID committedLogId; - 6: LogID lastLogId; - 7: bool pullingSnapshot; + 3: IPv4 leader_ip; + 4: Port leader_port; + 5: LogID committed_log_id; + 6: LogID last_log_id; + 7: bool pulling_snapshot; } diff --git a/interface/storage.thrift b/interface/storage.thrift new file mode 100644 index 00000000000..d545833ae52 --- /dev/null +++ b/interface/storage.thrift @@ -0,0 +1,83 @@ +/* Copyright (c) 2018 - present, VE Software Inc. All rights reserved + * + * This source code is licensed under Apache 2.0 License + * (found in the LICENSE.Apache file in the root directory) + */ + +namespace cpp vesoft.storage +namespace java vesoft.storage +namespace go vesoft.storage + +enum ErrorCode { + SUCCEEDED = 0, + + // RPC Failure + E_DISCONNECTED = -1, + E_FAILED_TO_CONNECT = -2, + E_RPC_FAILURE = -3, +} (cpp.enum_strict) + + +// These are all data types supported in the graph properties +enum SupportedType { + // Simple types + BOOL = 1, + INT = 2, + FLOAT = 3, + DOUBLE = 4, + STRING = 5, + VID = 6, + + // Date time + TIMESTAMP = 21, + YEAR = 22, + YEARMONTH = 23, + DATE = 24, + DATETIME = 25, + + // Graph specific + PATH = 41, + + // Container types + LIST = 101, + SET = 102, + MAP = 103, // The key type is always a STRING + STRUCT = 104, +} (cpp.enum_strict) + + +struct ValueType { + 1: SupportedType type; + // vtype only exists when the type is a LIST, SET, or MAP + 2: optional ValueType value_type (cpp.ref = true); + // When the type is STRUCT, schema defines the struct + 3: optional Schema schema (cpp.ref = true); +} (cpp.virtual) + + +struct ColumnDef { + 1: required string name, + 2: required ValueType type, +} + + +struct Schema { + 1: list columns, +} + + +struct QueryResponse { + 1: required ErrorCode error_code, + 2: required i32 latency_in_ms, // Query latency from storage service + 3: optional Schema schema, + 4: optional binary data, +} + + +service StorageService { + QueryResponse getOutBound(1: list ids, + 2: list edgeTypes, + 3: binary filter + 4: list returnColumns) +} + diff --git a/interface/vgraph.thrift b/interface/vgraph.thrift index c5bd95ebccd..e01d4d0e213 100644 --- a/interface/vgraph.thrift +++ b/interface/vgraph.thrift @@ -8,84 +8,94 @@ namespace cpp vesoft.vgraph namespace java vesoft.vgraph namespace go vesoft.vgraph - -enum ResultCode { +enum ErrorCode { SUCCEEDED = 0, + // RPC Failure + E_DISCONNECTED = -1, + E_FAIL_TO_CONNECT = -2, + E_RPC_FAILURE = -3, + // Authentication error - E_BAD_USERNAME_PASSWORD = -1, + E_BAD_USERNAME_PASSWORD = -4, // Execution errors - E_SESSION_INVALID = -2, - E_SESSION_TIMEOUT = -3, + E_SESSION_INVALID = -5, + E_SESSION_TIMEOUT = -6, - E_SYNTAX_ERROR = -4, + E_SYNTAX_ERROR = -7, } (cpp.enum_strict) -// These are all data types supported in the graph properties -enum SupportedType { +typedef i64 IdType +typedef i64 Timestamp +typedef i16 Year +struct YearMonth { + 1: i16 year; + 2: byte month; +} +struct Date { + 1: i16 year; + 2: byte month; + 3: byte day; +} +struct DateTime { + 1: i16 year; + 2: byte month; + 3: byte day; + 4: byte hour; + 5: byte minute; + 6: byte second; + 7: i16 millisec; + 8: i16 microsec; +} + + +union ColumnValue { // Simple types - BOOL = 1, - INT = 2, - FLOAT = 3, - DOUBLE = 4, - STRING = 5, - VID = 6, - - // Date time - TIMESTAMP = 21, - DATE = 22, - TIME = 23, - DATETIME = 24, - YEAR = 25, + 1: bool boolean, + 2: i64 integer; + 3: IdType id; + 4: float single_precision; + 5: double double_precision; + 6: binary str; + + // Date time types + 7: Timestamp timestamp; + 8: Year year; + 9: YearMonth month; + 10: Date date; + 11: DateTime datetime; // Graph specific - PATH = 41, +// PATH = 41; // Container types - LIST = 101, - SET = 102, - MAP = 103, // The key type is always a STRING - STRUCT = 104, -} (cpp.enum_strict) - - -struct ValueType { - 1: SupportedType type; - // vtype only exists when the type is a LIST, SET, or MAP - 2: optional ValueType vType (cpp.ref = true); - // When the type is STRUCT, schema defines the struct - 3: optional Schema schema (cpp.ref = true); -} (cpp.virtual) - - -struct ColumnDef { - 1: required string name, - 2: required ValueType type, +// LIST = 101; +// SET = 102; +// MAP = 103; +// STRUCT = 104; } -struct Schema { - 1: list columns, +struct RowValue { + 1: list columns; } struct ExecutionResponse { - 1: required ResultCode result, - 2: required i32 latencyInMs, - 3: optional string errorMsg, - 4: optional Schema schema, - // The returned data is encoded and will be decoded when it's read - 5: optional binary data, - // The query latency on the server side + 1: required ErrorCode error_code; + 2: required i32 latency_in_ms; // Execution time on server + 3: optional string error_msg; + 4: optional list column_names; // Column names + 5: optional list rows; } struct AuthResponse { - 1: required ResultCode result, - 2: optional i64 sessionId, - 3: optional string errorMsg, + 1: required ErrorCode error_code; + 2: optional i64 session_id; + 3: optional string error_msg; } diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 89f03194278..38281a9e348 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -5,7 +5,6 @@ add_executable( vgraphd GraphDbDaemon.cpp $ - $ $ $ $ diff --git a/server/GraphDbServiceHandler.cpp b/server/GraphDbServiceHandler.cpp index d04b31842ce..6d5b72e4d41 100644 --- a/server/GraphDbServiceHandler.cpp +++ b/server/GraphDbServiceHandler.cpp @@ -7,9 +7,6 @@ #include "base/Base.h" #include "server/GraphDbServiceHandler.h" #include "time/Duration.h" -#include "dataman/RowWriter.h" -#include "dataman/RowSetWriter.h" -#include "dataman/ThriftSchemaProvider.h" namespace vesoft { namespace vgraph { @@ -22,11 +19,11 @@ folly::Future GraphDbServiceHandler::future_authenticate( cpp2::AuthResponse resp; // TODO(sye) For test purpose, we only allow test/user to pass if (username == "test" && password == "user") { - resp.set_result(cpp2::ResultCode::SUCCEEDED); - resp.set_sessionId(1); + resp.set_error_code(cpp2::ErrorCode::SUCCEEDED); + resp.set_session_id(1); } else { - resp.set_result(cpp2::ResultCode::E_BAD_USERNAME_PASSWORD); - resp.set_errorMsg(getErrorStr(cpp2::ResultCode::E_BAD_USERNAME_PASSWORD)); + resp.set_error_code(cpp2::ErrorCode::E_BAD_USERNAME_PASSWORD); + resp.set_error_msg(getErrorStr(cpp2::ErrorCode::E_BAD_USERNAME_PASSWORD)); } folly::Promise promise; @@ -52,34 +49,73 @@ folly::Future GraphDbServiceHandler::future_execute( // TODO For test purpose, we only generate two valid results and // return error for all others if (stmt == "version") { - resp.set_result(cpp2::ResultCode::SUCCEEDED); - - RowWriter row1; - row1 << RowWriter::ColName("major") << 1 - << RowWriter::ColName("minor") << 2 - << RowWriter::ColName("release") << 1234567890; - resp.set_schema(std::move(row1.moveSchema())); - - ThriftSchemaProvider schema(resp.get_schema()); - - RowSetWriter rs(&schema); - rs.addRow(row1); - - RowWriter row2(&schema); - row2 << 2 << 3 << 4; - rs.addRow(row2); - - resp.set_data(std::move(rs.data())); + resp.set_error_code(cpp2::ErrorCode::SUCCEEDED); + + std::vector headers; + headers.emplace_back("major"); + headers.emplace_back("minor"); + headers.emplace_back("release"); + headers.emplace_back("release_date"); + headers.emplace_back("expiration"); + resp.set_column_names(std::move(headers)); + + std::vector cols; + + // Row 1 + cols.emplace_back(cpp2::ColumnValue()); + cols.back().set_integer(1); + cols.emplace_back(cpp2::ColumnValue()); + cols.back().set_integer(1); + cols.emplace_back(cpp2::ColumnValue()); + cols.back().set_integer(1); + cols.emplace_back(cpp2::ColumnValue()); + cpp2::Date date; + date.year = 2017; + date.month = 10; + date.day = 8; + cols.back().set_date(std::move(date)); + cols.emplace_back(cpp2::ColumnValue()); + cpp2::YearMonth month; + month.year = 2018; + month.month = 4; + cols.back().set_month(std::move(month)); + + std::vector rows; + rows.emplace_back(); + rows.back().set_columns(std::move(cols)); + + // Row 2 + cols.clear(); + cols.emplace_back(cpp2::ColumnValue()); + cols.back().set_integer(2); + cols.emplace_back(cpp2::ColumnValue()); + cols.back().set_integer(2); + cols.emplace_back(cpp2::ColumnValue()); + cols.back().set_integer(2); + cols.emplace_back(cpp2::ColumnValue()); + date.year = 2018; + date.month = 10; + date.day = 8; + cols.back().set_date(std::move(date)); + cols.emplace_back(cpp2::ColumnValue()); + month.year = 2019; + month.month = 4; + cols.back().set_month(std::move(month)); + + rows.emplace_back(); + rows.back().set_columns(std::move(cols)); + + resp.set_rows(std::move(rows)); } else if (stmt == "select") { usleep(2000); - resp.set_result(cpp2::ResultCode::SUCCEEDED); + resp.set_error_code(cpp2::ErrorCode::SUCCEEDED); } else { // TODO otherwuse, return error - resp.set_result(cpp2::ResultCode::E_SYNTAX_ERROR); - resp.set_errorMsg("Syntax error: Unknown statement"); + resp.set_error_code(cpp2::ErrorCode::E_SYNTAX_ERROR); + resp.set_error_msg("Syntax error: Unknown statement"); } - resp.set_latencyInMs(dur.elapsedInMSec()); + resp.set_latency_in_ms(dur.elapsedInMSec()); folly::Promise promise; promise.setValue(std::move(resp)); @@ -87,20 +123,20 @@ folly::Future GraphDbServiceHandler::future_execute( } -const char* GraphDbServiceHandler::getErrorStr(cpp2::ResultCode result) { +const char* GraphDbServiceHandler::getErrorStr(cpp2::ErrorCode result) { switch (result) { - case cpp2::ResultCode::SUCCEEDED: + case cpp2::ErrorCode::SUCCEEDED: return "Succeeded"; /********************** * Server side errors **********************/ - case cpp2::ResultCode::E_BAD_USERNAME_PASSWORD: + case cpp2::ErrorCode::E_BAD_USERNAME_PASSWORD: return "Bad username/password"; - case cpp2::ResultCode::E_SESSION_INVALID: + case cpp2::ErrorCode::E_SESSION_INVALID: return "The session is invalid"; - case cpp2::ResultCode::E_SESSION_TIMEOUT: + case cpp2::ErrorCode::E_SESSION_TIMEOUT: return "The session timed out"; - case cpp2::ResultCode::E_SYNTAX_ERROR: + case cpp2::ErrorCode::E_SYNTAX_ERROR: return "Syntax error"; /********************** * Unknown error diff --git a/server/GraphDbServiceHandler.h b/server/GraphDbServiceHandler.h index 20ee9f8291a..c060d4d26b9 100644 --- a/server/GraphDbServiceHandler.h +++ b/server/GraphDbServiceHandler.h @@ -25,7 +25,7 @@ class GraphDbServiceHandler final : public cpp2::GraphDbServiceSvIf { int64_t sessionId, const std::string& stmt) override; - const char* getErrorStr(cpp2::ResultCode result); + const char* getErrorStr(cpp2::ErrorCode result); private: };