Skip to content

Commit

Permalink
Remove virtual interface in SchemaProviderIf (#5410)
Browse files Browse the repository at this point in the history
* Make SchemaProviderIf alone

* Remove SchemaProviderIf

---------

Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com>
  • Loading branch information
critical27 and Sophie-Xie authored Mar 20, 2023
1 parent 9fee385 commit 5cb0bff
Show file tree
Hide file tree
Showing 53 changed files with 330 additions and 1,669 deletions.
4 changes: 2 additions & 2 deletions src/codec/NebulaCodecImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
namespace nebula {

std::string NebulaCodecImpl::encode(std::vector<Value> values,
std::shared_ptr<const meta::SchemaProviderIf> schema) {
std::shared_ptr<const meta::NebulaSchemaProvider> schema) {
RowWriter writer(schema);
for (auto& value : values) {
if (value.type() == typeid(int32_t)) {
Expand All @@ -47,7 +47,7 @@ std::string NebulaCodecImpl::encode(std::vector<Value> values,
}

StatusOr<std::unordered_map<std::string, Value>> NebulaCodecImpl::decode(
std::string encoded, std::shared_ptr<const meta::SchemaProviderIf> schema) {
std::string encoded, std::shared_ptr<const meta::NebulaSchemaProvider> schema) {
if (encoded.empty()) {
return Status::Error("encoded string is empty");
}
Expand Down
2 changes: 1 addition & 1 deletion src/codec/RowReaderV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace nebula {

using nebula::cpp2::PropertyType;

bool RowReaderV2::resetImpl(meta::SchemaProviderIf const* schema, folly::StringPiece row) {
bool RowReaderV2::resetImpl(meta::NebulaSchemaProvider const* schema, folly::StringPiece row) {
schema_ = schema;
data_ = row;

Expand Down
8 changes: 4 additions & 4 deletions src/codec/RowReaderV2.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <gtest/gtest_prod.h>

#include "common/base/Base.h"
#include "common/meta/SchemaProviderIf.h"
#include "common/meta/NebulaSchemaProvider.h"

namespace nebula {

Expand All @@ -34,7 +34,7 @@ class RowReaderV2 {
return headerLen_;
}

const meta::SchemaProviderIf* getSchema() const {
const meta::NebulaSchemaProvider* getSchema() const {
return schema_;
}

Expand All @@ -51,10 +51,10 @@ class RowReaderV2 {
}

private:
bool resetImpl(meta::SchemaProviderIf const* schema, folly::StringPiece row);
bool resetImpl(meta::NebulaSchemaProvider const* schema, folly::StringPiece row);

private:
meta::SchemaProviderIf const* schema_;
meta::NebulaSchemaProvider const* schema_;
folly::StringPiece data_;
size_t headerLen_;
size_t numNullBytes_;
Expand Down
8 changes: 4 additions & 4 deletions src/codec/RowReaderWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ RowReaderWrapper RowReaderWrapper::getEdgePropReader(meta::SchemaManager* schema
}

// static
RowReaderWrapper RowReaderWrapper::getRowReader(const meta::SchemaProviderIf* schema,
RowReaderWrapper RowReaderWrapper::getRowReader(const meta::NebulaSchemaProvider* schema,
folly::StringPiece row) {
SchemaVer schemaVer;
int32_t readerVer;
Expand All @@ -77,7 +77,7 @@ RowReaderWrapper RowReaderWrapper::getRowReader(
return RowReaderWrapper(schemas[schemaVer].get(), row, readerVer);
}

RowReaderWrapper::RowReaderWrapper(const meta::SchemaProviderIf* schema,
RowReaderWrapper::RowReaderWrapper(const meta::NebulaSchemaProvider* schema,
const folly::StringPiece& row,
int32_t& readerVer) {
CHECK_EQ(readerVer, 2);
Expand All @@ -86,7 +86,7 @@ RowReaderWrapper::RowReaderWrapper(const meta::SchemaProviderIf* schema,
currReader_ = &readerV2_;
}

bool RowReaderWrapper::reset(meta::SchemaProviderIf const* schema,
bool RowReaderWrapper::reset(meta::NebulaSchemaProvider const* schema,
folly::StringPiece row,
int32_t readerVer) {
CHECK_EQ(readerVer, 2);
Expand All @@ -96,7 +96,7 @@ bool RowReaderWrapper::reset(meta::SchemaProviderIf const* schema,
return true;
}

bool RowReaderWrapper::reset(meta::SchemaProviderIf const* schema, folly::StringPiece row) {
bool RowReaderWrapper::reset(meta::NebulaSchemaProvider const* schema, folly::StringPiece row) {
currReader_ = nullptr;
if (schema == nullptr) {
return false;
Expand Down
12 changes: 6 additions & 6 deletions src/codec/RowReaderWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include "codec/RowReaderV2.h"
#include "common/base/Base.h"
#include "common/datatypes/Value.h"
#include "common/meta/NebulaSchemaProvider.h"
#include "common/meta/SchemaManager.h"
#include "common/meta/SchemaProviderIf.h"

namespace nebula {

Expand Down Expand Up @@ -86,7 +86,7 @@ class RowReaderWrapper {
* @param row
* @return RowReaderWrapper
*/
static RowReaderWrapper getRowReader(meta::SchemaProviderIf const* schema,
static RowReaderWrapper getRowReader(meta::NebulaSchemaProvider const* schema,
folly::StringPiece row);

/**
Expand All @@ -109,7 +109,7 @@ class RowReaderWrapper {
* @param row
* @param readerVer Row reader version
*/
RowReaderWrapper(const meta::SchemaProviderIf* schema,
RowReaderWrapper(const meta::NebulaSchemaProvider* schema,
const folly::StringPiece& row,
int32_t& readerVer);

Expand All @@ -121,7 +121,7 @@ class RowReaderWrapper {
* @param readVer
* @return Whether reset succeed
*/
bool reset(meta::SchemaProviderIf const* schema, folly::StringPiece row, int32_t readVer);
bool reset(meta::NebulaSchemaProvider const* schema, folly::StringPiece row, int32_t readVer);

/**
* @brief Reset current row reader wrapper to of given schema and data
Expand All @@ -130,7 +130,7 @@ class RowReaderWrapper {
* @param row
* @return Whether reset succeed
*/
bool reset(meta::SchemaProviderIf const* schema, folly::StringPiece row);
bool reset(meta::NebulaSchemaProvider const* schema, folly::StringPiece row);

/**
* @brief Reset current row reader wrapper of given schemas and data, the schemas are stored in
Expand Down Expand Up @@ -174,7 +174,7 @@ class RowReaderWrapper {
return currReader_->numFields();
}

const meta::SchemaProviderIf* getSchema() const {
const meta::NebulaSchemaProvider* getSchema() const {
DCHECK(!!currReader_);
return currReader_->getSchema();
}
Expand Down
6 changes: 3 additions & 3 deletions src/codec/RowWriterV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace nebula {

using nebula::cpp2::PropertyType;

RowWriterV2::RowWriterV2(const meta::SchemaProviderIf* schema)
RowWriterV2::RowWriterV2(const meta::NebulaSchemaProvider* schema)
: schema_(schema), numNullBytes_(0), approxStrLen_(0), finished_(false), outOfSpaceStr_(false) {
CHECK(!!schema_);

Expand Down Expand Up @@ -88,14 +88,14 @@ RowWriterV2::RowWriterV2(const meta::SchemaProviderIf* schema)
isSet_.resize(schema_->getNumFields(), false);
}

RowWriterV2::RowWriterV2(const meta::SchemaProviderIf* schema, std::string&& encoded)
RowWriterV2::RowWriterV2(const meta::NebulaSchemaProvider* schema, std::string&& encoded)
: schema_(schema), finished_(false), outOfSpaceStr_(false) {
auto len = encoded.size();
buf_ = std::move(encoded).substr(0, len - sizeof(int64_t));
processV2EncodedStr();
}

RowWriterV2::RowWriterV2(const meta::SchemaProviderIf* schema, const std::string& encoded)
RowWriterV2::RowWriterV2(const meta::NebulaSchemaProvider* schema, const std::string& encoded)
: schema_(schema),
buf_(encoded.substr(0, encoded.size() - sizeof(int64_t))),
finished_(false),
Expand Down
14 changes: 7 additions & 7 deletions src/codec/RowWriterV2.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "codec/RowReaderWrapper.h"
#include "common/base/Base.h"
#include "common/meta/SchemaProviderIf.h"
#include "common/meta/NebulaSchemaProvider.h"

namespace nebula {

Expand Down Expand Up @@ -85,11 +85,11 @@ enum class WriteResult {
********************************************************************************/
class RowWriterV2 {
public:
explicit RowWriterV2(const meta::SchemaProviderIf* schema);
explicit RowWriterV2(const meta::NebulaSchemaProvider* schema);
// This constructor only takes a V2 encoded string
RowWriterV2(const meta::SchemaProviderIf* schema, std::string&& encoded);
RowWriterV2(const meta::NebulaSchemaProvider* schema, std::string&& encoded);
// This constructor only takes a V2 encoded string
RowWriterV2(const meta::SchemaProviderIf* schema, const std::string& encoded);
RowWriterV2(const meta::NebulaSchemaProvider* schema, const std::string& encoded);
// This constructor can handle constructed from RowReaderWrapper, which is V2 reader
explicit RowWriterV2(RowReaderWrapper& reader);

Expand All @@ -107,9 +107,9 @@ class RowWriterV2 {
/**
* @brief Return the related schema
*
* @return const meta::SchemaProviderIf*
* @return const meta::NebulaSchemaProvider*
*/
const meta::SchemaProviderIf* schema() const {
const meta::NebulaSchemaProvider* schema() const {
return schema_;
}

Expand Down Expand Up @@ -213,7 +213,7 @@ class RowWriterV2 {
WriteResult setNull(const std::string& name);

private:
const meta::SchemaProviderIf* schema_;
const meta::NebulaSchemaProvider* schema_;
std::string buf_;
std::vector<bool> isSet_;
// The number of bytes occupied by header and the schema version
Expand Down
9 changes: 5 additions & 4 deletions src/codec/include/NebulaCodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define CODEC_INCLUDE_NEBULACODEC_H

#include "common/base/StatusOr.h"
#include "common/meta/SchemaProviderIf.h"
#include "common/meta/NebulaSchemaProvider.h"

namespace nebula {

Expand All @@ -17,11 +17,12 @@ class NebulaCodec {

virtual ~NebulaCodec() = default;

virtual std::string encode(std::vector<Value> values,
std::shared_ptr<const meta::SchemaProviderIf> schema = nullptr) = 0;
virtual std::string encode(
std::vector<Value> values,
std::shared_ptr<const meta::NebulaSchemaProvider> schema = nullptr) = 0;

virtual StatusOr<std::unordered_map<std::string, Value>> decode(
std::string encoded, std::shared_ptr<const meta::SchemaProviderIf> schema) = 0;
std::string encoded, std::shared_ptr<const meta::NebulaSchemaProvider> schema) = 0;
};

} // namespace nebula
Expand Down
14 changes: 0 additions & 14 deletions src/codec/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,8 @@
#
# This source code is licensed under Apache 2.0 License.

nebula_add_library(
codec_test_obj OBJECT
ResultSchemaProvider.cpp
SchemaWriter.cpp
)

set(CODEC_TEST_LIBS
$<TARGET_OBJECTS:codec_obj>
$<TARGET_OBJECTS:codec_test_obj>
$<TARGET_OBJECTS:datatypes_obj>
$<TARGET_OBJECTS:thrift_obj>
$<TARGET_OBJECTS:meta_thrift_obj>
Expand Down Expand Up @@ -83,10 +76,3 @@ nebula_add_executable(
wangle
boost_regex
)

#nebula_add_test(
# NAME nebula_codec_test
# SOURCES NebulaCodecTest.cpp
# OBJECTS ${CODEC_TEST_LIBS}
# LIBRARIES ${THRIFT_LIBRARIES} wangle gtest
#)
Loading

0 comments on commit 5cb0bff

Please sign in to comment.