From f888fcb902d747b3261ae95b152cb47a3aa460c7 Mon Sep 17 00:00:00 2001 From: "hs.zhang" <22708345+cangfengzhs@users.noreply.github.com> Date: Fri, 14 Jan 2022 17:58:03 +0800 Subject: [PATCH] fix issue 3601 (#3666) --- src/clients/meta/MetaClient.cpp | 38 +++----- src/clients/meta/MetaClient.h | 8 +- src/codec/RowWriterV2.cpp | 6 +- src/codec/test/ResultSchemaProvider.cpp | 6 +- src/codec/test/ResultSchemaProvider.h | 6 +- src/codec/test/SchemaWriter.cpp | 10 +- src/common/meta/NebulaSchemaProvider.cpp | 4 +- src/common/meta/NebulaSchemaProvider.h | 8 +- src/common/meta/SchemaProviderIf.h | 2 +- src/common/utils/IndexKeyUtils.cpp | 5 +- src/common/utils/test/CMakeLists.txt | 15 +++ src/graph/util/SchemaUtil.cpp | 8 +- src/graph/util/SchemaUtil.h | 2 +- src/graph/validator/MaintainValidator.cpp | 6 +- src/graph/validator/MutateValidator.cpp | 9 +- src/mock/MockData.cpp | 91 +++++++++++++------ src/storage/exec/QueryUtils.h | 4 +- src/storage/exec/UpdateNode.h | 4 +- src/storage/test/IndexWithTTLTest.cpp | 7 +- .../ChainAddEdgesLocalProcessor.cpp | 4 +- 20 files changed, 148 insertions(+), 95 deletions(-) diff --git a/src/clients/meta/MetaClient.cpp b/src/clients/meta/MetaClient.cpp index 0e4fb05d239..7c50f8ab120 100644 --- a/src/clients/meta/MetaClient.cpp +++ b/src/clients/meta/MetaClient.cpp @@ -364,8 +364,8 @@ bool MetaClient::loadData() { GraphSpaceID spaceId = spaceInfo.first; std::shared_ptr info = spaceInfo.second; std::shared_ptr infoDeepCopy = std::make_shared(*info); - infoDeepCopy->tagSchemas_ = buildTagSchemas(infoDeepCopy->tagItemVec_, &infoDeepCopy->pool_); - infoDeepCopy->edgeSchemas_ = buildEdgeSchemas(infoDeepCopy->edgeItemVec_, &infoDeepCopy->pool_); + infoDeepCopy->tagSchemas_ = buildTagSchemas(infoDeepCopy->tagItemVec_); + infoDeepCopy->edgeSchemas_ = buildEdgeSchemas(infoDeepCopy->edgeItemVec_); infoDeepCopy->tagIndexes_ = buildIndexes(infoDeepCopy->tagIndexItemVec_); infoDeepCopy->edgeIndexes_ = buildIndexes(infoDeepCopy->edgeIndexItemVec_); newMetaData->localCache_[spaceId] = infoDeepCopy; @@ -396,14 +396,14 @@ bool MetaClient::loadData() { return true; } -TagSchemas MetaClient::buildTagSchemas(std::vector tagItemVec, ObjectPool* pool) { +TagSchemas MetaClient::buildTagSchemas(std::vector tagItemVec) { TagSchemas tagSchemas; TagID lastTagId = -1; for (auto& tagIt : tagItemVec) { // meta will return the different version from new to old auto schema = std::make_shared(tagIt.get_version()); for (const auto& colIt : tagIt.get_schema().get_columns()) { - addSchemaField(schema.get(), colIt, pool); + addSchemaField(schema.get(), colIt); } // handle schema property schema->setProp(tagIt.get_schema().get_schema_prop()); @@ -417,8 +417,7 @@ TagSchemas MetaClient::buildTagSchemas(std::vector tagItemVec, Ob return tagSchemas; } -EdgeSchemas MetaClient::buildEdgeSchemas(std::vector edgeItemVec, - ObjectPool* pool) { +EdgeSchemas MetaClient::buildEdgeSchemas(std::vector edgeItemVec) { EdgeSchemas edgeSchemas; std::unordered_set> edges; EdgeType lastEdgeType = -1; @@ -426,7 +425,7 @@ EdgeSchemas MetaClient::buildEdgeSchemas(std::vector edgeItemVec // meta will return the different version from new to old auto schema = std::make_shared(edgeIt.get_version()); for (const auto& col : edgeIt.get_schema().get_columns()) { - MetaClient::addSchemaField(schema.get(), col, pool); + MetaClient::addSchemaField(schema.get(), col); } // handle shcem property schema->setProp(edgeIt.get_schema().get_schema_prop()); @@ -440,32 +439,19 @@ EdgeSchemas MetaClient::buildEdgeSchemas(std::vector edgeItemVec return edgeSchemas; } -void MetaClient::addSchemaField(NebulaSchemaProvider* schema, - const cpp2::ColumnDef& col, - ObjectPool* pool) { +void MetaClient::addSchemaField(NebulaSchemaProvider* schema, const cpp2::ColumnDef& col) { bool hasDef = col.default_value_ref().has_value(); auto& colType = col.get_type(); size_t len = colType.type_length_ref().has_value() ? *colType.get_type_length() : 0; cpp2::GeoShape geoShape = colType.geo_shape_ref().has_value() ? *colType.get_geo_shape() : cpp2::GeoShape::ANY; bool nullable = col.nullable_ref().has_value() ? *col.get_nullable() : false; - Expression* defaultValueExpr = nullptr; + std::string encoded; if (hasDef) { - auto encoded = *col.get_default_value(); - defaultValueExpr = Expression::decode(pool, folly::StringPiece(encoded.data(), encoded.size())); - - if (defaultValueExpr == nullptr) { - LOG(ERROR) << "Wrong expr default value for column name: " << col.get_name(); - hasDef = false; - } + encoded = *col.get_default_value(); } - schema->addField(col.get_name(), - colType.get_type(), - len, - nullable, - hasDef ? defaultValueExpr : nullptr, - geoShape); + schema->addField(col.get_name(), colType.get_type(), len, nullable, encoded, geoShape); } bool MetaClient::loadSchemas(GraphSpaceID spaceId, @@ -493,9 +479,9 @@ bool MetaClient::loadSchemas(GraphSpaceID spaceId, auto edgeItemVec = edgeRet.value(); allEdgeMap[spaceId] = {}; spaceInfoCache->tagItemVec_ = tagItemVec; - spaceInfoCache->tagSchemas_ = buildTagSchemas(tagItemVec, &spaceInfoCache->pool_); + spaceInfoCache->tagSchemas_ = buildTagSchemas(tagItemVec); spaceInfoCache->edgeItemVec_ = edgeItemVec; - spaceInfoCache->edgeSchemas_ = buildEdgeSchemas(edgeItemVec, &spaceInfoCache->pool_); + spaceInfoCache->edgeSchemas_ = buildEdgeSchemas(edgeItemVec); for (auto& tagIt : tagItemVec) { tagNameIdMap.emplace(std::make_pair(spaceId, tagIt.get_tag_name()), tagIt.get_tag_id()); diff --git a/src/clients/meta/MetaClient.h b/src/clients/meta/MetaClient.h index 8ac7e42ff02..3504898aba1 100644 --- a/src/clients/meta/MetaClient.h +++ b/src/clients/meta/MetaClient.h @@ -91,8 +91,6 @@ struct SpaceInfoCache { std::vector edgeIndexItemVec_; Indexes edgeIndexes_; Listeners listeners_; - // objPool used to decode when adding field - ObjectPool pool_; std::unordered_map termOfPartition_; SpaceInfoCache() = default; @@ -816,10 +814,10 @@ class MetaClient { ServiceClientsList serviceClientList_; }; - void addSchemaField(NebulaSchemaProvider* schema, const cpp2::ColumnDef& col, ObjectPool* pool); + void addSchemaField(NebulaSchemaProvider* schema, const cpp2::ColumnDef& col); - TagSchemas buildTagSchemas(std::vector tagItemVec, ObjectPool* pool); - EdgeSchemas buildEdgeSchemas(std::vector edgeItemVec, ObjectPool* pool); + TagSchemas buildTagSchemas(std::vector tagItemVec); + EdgeSchemas buildEdgeSchemas(std::vector edgeItemVec); std::unique_ptr bgThread_; SpaceNameIdMap spaceIndexByName_; diff --git a/src/codec/RowWriterV2.cpp b/src/codec/RowWriterV2.cpp index 639b4854965..9e0818521e5 100644 --- a/src/codec/RowWriterV2.cpp +++ b/src/codec/RowWriterV2.cpp @@ -815,7 +815,9 @@ WriteResult RowWriterV2::checkUnsetFields() noexcept { WriteResult r = WriteResult::SUCCEEDED; if (field->hasDefault()) { - auto expr = field->defaultValue()->clone(); + ObjectPool pool; + auto& exprStr = field->defaultValue(); + auto expr = Expression::decode(&pool, folly::StringPiece(exprStr.data(), exprStr.size())); auto defVal = Expression::eval(expr, expCtx); switch (defVal.type()) { case Value::Type::NULLVALUE: @@ -851,7 +853,7 @@ WriteResult RowWriterV2::checkUnsetFields() noexcept { default: LOG(FATAL) << "Unsupported default value type: " << defVal.typeName() << ", default value: " << defVal - << ", default value expr: " << field->defaultValue()->toString(); + << ", default value expr: " << field->defaultValue(); } } else { // Set NULL diff --git a/src/codec/test/ResultSchemaProvider.cpp b/src/codec/test/ResultSchemaProvider.cpp index 7d1037dca1b..20acd6dd071 100644 --- a/src/codec/test/ResultSchemaProvider.cpp +++ b/src/codec/test/ResultSchemaProvider.cpp @@ -22,7 +22,7 @@ ResultSchemaProvider::ResultSchemaField::ResultSchemaField(std::string name, bool nullable, int32_t offset, size_t nullFlagPos, - Expression* defaultValue, + std::string defaultValue, meta::cpp2::GeoShape geoShape) : name_(std::move(name)), type_(type), @@ -42,14 +42,14 @@ PropertyType ResultSchemaProvider::ResultSchemaField::type() const { } bool ResultSchemaProvider::ResultSchemaField::hasDefault() const { - return defaultValue_ != nullptr; + return defaultValue_ != ""; } bool ResultSchemaProvider::ResultSchemaField::nullable() const { return nullable_; } -Expression* ResultSchemaProvider::ResultSchemaField::defaultValue() const { +const std::string& ResultSchemaProvider::ResultSchemaField::defaultValue() const { return defaultValue_; } diff --git a/src/codec/test/ResultSchemaProvider.h b/src/codec/test/ResultSchemaProvider.h index c0c043f6cd4..c780cf34eb5 100644 --- a/src/codec/test/ResultSchemaProvider.h +++ b/src/codec/test/ResultSchemaProvider.h @@ -21,14 +21,14 @@ class ResultSchemaProvider : public meta::SchemaProviderIf { bool nullable, int32_t offset, size_t nullFlagPos, - Expression* defaultValue = nullptr, + std::string defaultValue = "", meta::cpp2::GeoShape = meta::cpp2::GeoShape::ANY); const char* name() const override; nebula::cpp2::PropertyType type() const override; bool nullable() const override; bool hasDefault() const override; - Expression* defaultValue() const override; + const std::string& defaultValue() const override; size_t size() const override; size_t offset() const override; size_t nullFlagPos() const override; @@ -41,7 +41,7 @@ class ResultSchemaProvider : public meta::SchemaProviderIf { bool nullable_; int32_t offset_; size_t nullFlagPos_; - Expression* defaultValue_; + std::string defaultValue_; meta::cpp2::GeoShape geoShape_; }; diff --git a/src/codec/test/SchemaWriter.cpp b/src/codec/test/SchemaWriter.cpp index 9731319c8fd..d5c4ddf76bf 100644 --- a/src/codec/test/SchemaWriter.cpp +++ b/src/codec/test/SchemaWriter.cpp @@ -90,8 +90,14 @@ SchemaWriter& SchemaWriter::appendCol(folly::StringPiece name, nullFlagPos = numNullableFields_++; } - columns_.emplace_back( - name.toString(), type, size, nullable, offset, nullFlagPos, defaultValue, geoShape); + columns_.emplace_back(name.toString(), + type, + size, + nullable, + offset, + nullFlagPos, + defaultValue ? defaultValue->encode() : "", + geoShape); nameIndex_.emplace(std::make_pair(hash, columns_.size() - 1)); return *this; diff --git a/src/common/meta/NebulaSchemaProvider.cpp b/src/common/meta/NebulaSchemaProvider.cpp index 535766e5a06..a6499db99e8 100644 --- a/src/common/meta/NebulaSchemaProvider.cpp +++ b/src/common/meta/NebulaSchemaProvider.cpp @@ -98,7 +98,7 @@ void NebulaSchemaProvider::addField(folly::StringPiece name, PropertyType type, size_t fixedStrLen, bool nullable, - Expression* defaultValue, + std::string defaultValue, cpp2::GeoShape geoShape) { size_t size = fieldSize(type, fixedStrLen); @@ -116,7 +116,7 @@ void NebulaSchemaProvider::addField(folly::StringPiece name, fields_.emplace_back(name.toString(), type, nullable, - defaultValue != nullptr, + defaultValue != "", defaultValue, size, offset, diff --git a/src/common/meta/NebulaSchemaProvider.h b/src/common/meta/NebulaSchemaProvider.h index 1a30952b11f..1dc841ddee6 100644 --- a/src/common/meta/NebulaSchemaProvider.h +++ b/src/common/meta/NebulaSchemaProvider.h @@ -25,7 +25,7 @@ class NebulaSchemaProvider : public SchemaProviderIf { nebula::cpp2::PropertyType type, bool nullable, bool hasDefault, - Expression* defaultValue, + std::string defaultValue, size_t size, size_t offset, size_t nullFlagPos, @@ -56,7 +56,7 @@ class NebulaSchemaProvider : public SchemaProviderIf { return hasDefault_; } - Expression* defaultValue() const override { + const std::string& defaultValue() const override { return defaultValue_; } @@ -82,7 +82,7 @@ class NebulaSchemaProvider : public SchemaProviderIf { nebula::cpp2::PropertyType type_; bool nullable_; bool hasDefault_; - Expression* defaultValue_; + std::string defaultValue_; size_t size_; size_t offset_; size_t nullFlagPos_; @@ -113,7 +113,7 @@ class NebulaSchemaProvider : public SchemaProviderIf { nebula::cpp2::PropertyType type, size_t fixedStrLen = 0, bool nullable = false, - Expression* defaultValue = nullptr, + std::string defaultValue = "", cpp2::GeoShape geoShape = cpp2::GeoShape::ANY); static std::size_t fieldSize(nebula::cpp2::PropertyType type, std::size_t fixedStrLimit); diff --git a/src/common/meta/SchemaProviderIf.h b/src/common/meta/SchemaProviderIf.h index 294fad85f24..3120412cd88 100644 --- a/src/common/meta/SchemaProviderIf.h +++ b/src/common/meta/SchemaProviderIf.h @@ -24,7 +24,7 @@ class SchemaProviderIf { virtual nebula::cpp2::PropertyType type() const = 0; virtual bool nullable() const = 0; virtual bool hasDefault() const = 0; - virtual Expression* defaultValue() const = 0; + virtual const std::string& defaultValue() const = 0; // This method returns the number of bytes the field will occupy // when the field is persisted on the storage medium // For the variant length string, the size will return 8 diff --git a/src/common/utils/IndexKeyUtils.cpp b/src/common/utils/IndexKeyUtils.cpp index 29b34fb7913..3707d85f52e 100644 --- a/src/common/utils/IndexKeyUtils.cpp +++ b/src/common/utils/IndexKeyUtils.cpp @@ -7,6 +7,7 @@ #include +#include "common/expression/Expression.h" #include "common/geo/GeoIndex.h" #include "common/utils/DefaultValueContext.h" @@ -212,7 +213,9 @@ StatusOr IndexKeyUtils::readValueWithLatestSche(RowReader* reader, } if (field->hasDefault()) { DefaultValueContext expCtx; - auto expr = field->defaultValue()->clone(); + ObjectPool pool; + auto& exprStr = field->defaultValue(); + auto expr = Expression::decode(&pool, folly::StringPiece(exprStr.data(), exprStr.size())); return Expression::eval(expr, expCtx); } else if (field->nullable()) { return NullType::__NULL__; diff --git a/src/common/utils/test/CMakeLists.txt b/src/common/utils/test/CMakeLists.txt index 7cbc4c2b045..dcbb1ff0533 100644 --- a/src/common/utils/test/CMakeLists.txt +++ b/src/common/utils/test/CMakeLists.txt @@ -13,6 +13,11 @@ nebula_add_test( $ $ $ + $ + $ + $ + $ + $ LIBRARIES gtest ${THRIFT_LIBRARIES} @@ -33,6 +38,11 @@ nebula_add_test( $ $ $ + $ + $ + $ + $ + $ LIBRARIES gtest ${THRIFT_LIBRARIES} @@ -56,6 +66,11 @@ nebula_add_test( $ $ $ + $ + $ + $ + $ + $ LIBRARIES gtest ${THRIFT_LIBRARIES} diff --git a/src/graph/util/SchemaUtil.cpp b/src/graph/util/SchemaUtil.cpp index d5b5e5e3934..37ac63e4053 100644 --- a/src/graph/util/SchemaUtil.cpp +++ b/src/graph/util/SchemaUtil.cpp @@ -55,19 +55,19 @@ Status SchemaUtil::validateProps(const std::vector &schemaProp // static std::shared_ptr SchemaUtil::generateSchemaProvider( - ObjectPool *pool, const SchemaVer ver, const meta::cpp2::Schema &schema) { + const SchemaVer ver, const meta::cpp2::Schema &schema) { auto schemaPtr = std::make_shared(ver); for (auto col : schema.get_columns()) { bool hasDef = col.default_value_ref().has_value(); - Expression *defaultValueExpr = nullptr; + std::string exprStr; if (hasDef) { - defaultValueExpr = Expression::decode(pool, *col.default_value_ref()); + exprStr = *col.default_value_ref(); } schemaPtr->addField(col.get_name(), col.get_type().get_type(), col.type.type_length_ref().value_or(0), col.nullable_ref().value_or(false), - hasDef ? defaultValueExpr : nullptr, + exprStr, col.type.geo_shape_ref().value_or(meta::cpp2::GeoShape::ANY)); } return schemaPtr; diff --git a/src/graph/util/SchemaUtil.h b/src/graph/util/SchemaUtil.h index b32e461d130..a93755eb444 100644 --- a/src/graph/util/SchemaUtil.h +++ b/src/graph/util/SchemaUtil.h @@ -29,7 +29,7 @@ class SchemaUtil final { meta::cpp2::Schema& schema); static std::shared_ptr generateSchemaProvider( - ObjectPool* pool, const SchemaVer ver, const meta::cpp2::Schema& schema); + const SchemaVer ver, const meta::cpp2::Schema& schema); static Status setTTLDuration(SchemaPropItem* schemaProp, meta::cpp2::Schema& schema); diff --git a/src/graph/validator/MaintainValidator.cpp b/src/graph/validator/MaintainValidator.cpp index b7ec3d20024..1559bd464b7 100644 --- a/src/graph/validator/MaintainValidator.cpp +++ b/src/graph/validator/MaintainValidator.cpp @@ -157,8 +157,7 @@ Status CreateTagValidator::validateImpl() { NG_RETURN_IF_ERROR(validateColumns(sentence->columnSpecs(), schema)); NG_RETURN_IF_ERROR(SchemaUtil::validateProps(sentence->getSchemaProps(), schema)); // Save the schema in validateContext - auto pool = qctx_->objPool(); - auto schemaPro = SchemaUtil::generateSchemaProvider(pool, 0, schema); + auto schemaPro = SchemaUtil::generateSchemaProvider(0, schema); vctx_->addSchema(name, schemaPro); createCtx_->name = std::move(name); createCtx_->schema = std::move(schema); @@ -180,8 +179,7 @@ Status CreateEdgeValidator::validateImpl() { NG_RETURN_IF_ERROR(validateColumns(sentence->columnSpecs(), schema)); NG_RETURN_IF_ERROR(SchemaUtil::validateProps(sentence->getSchemaProps(), schema)); // Save the schema in validateContext - auto pool = qctx_->objPool(); - auto schemaPro = SchemaUtil::generateSchemaProvider(pool, 0, schema); + auto schemaPro = SchemaUtil::generateSchemaProvider(0, schema); vctx_->addSchema(name, schemaPro); createCtx_->name = std::move(name); createCtx_->schema = std::move(schema); diff --git a/src/graph/validator/MutateValidator.cpp b/src/graph/validator/MutateValidator.cpp index ee32fc00f44..c41e2c03a5e 100644 --- a/src/graph/validator/MutateValidator.cpp +++ b/src/graph/validator/MutateValidator.cpp @@ -251,9 +251,12 @@ Status InsertEdgesValidator::prepareEdges() { auto iter = std::find(propNames_.begin(), propNames_.end(), propName); if (iter == propNames_.end()) { if (field->hasDefault()) { - auto *defaultValue = field->defaultValue(); - DCHECK(!!defaultValue); - auto v = defaultValue->eval(QueryExpressionContext()(nullptr)); + auto &defaultValue = field->defaultValue(); + DCHECK(!defaultValue.empty()); + ObjectPool pool; + auto expr = Expression::decode( + &pool, folly::StringPiece(defaultValue.data(), defaultValue.size())); + auto v = expr->eval(QueryExpressionContext()(nullptr)); entirePropValues.emplace_back(v); } else { if (!field->nullable()) { diff --git a/src/mock/MockData.cpp b/src/mock/MockData.cpp index 78811aead2f..664f6582de9 100644 --- a/src/mock/MockData.cpp +++ b/src/mock/MockData.cpp @@ -307,21 +307,29 @@ std::shared_ptr MockData::mockPlayerTagSchema(Object if (!hasProp) { return schema; } - schema->addField("name", PropertyType::STRING, 0, false, ConstantExpression::make(pool, "")); + schema->addField( + "name", PropertyType::STRING, 0, false, ConstantExpression::make(pool, "")->encode()); // only age filed has no default value and nullable is false schema->addField("age", PropertyType::INT64, 0, false); - schema->addField("playing", PropertyType::BOOL, 0, false, ConstantExpression::make(pool, true)); - schema->addField("career", PropertyType::INT64, 0, false, ConstantExpression::make(pool, 10L)); - schema->addField("startYear", PropertyType::INT64, 0, false, ConstantExpression::make(pool, 0L)); - schema->addField("endYear", PropertyType::INT64, 0, false, ConstantExpression::make(pool, 0L)); - schema->addField("games", PropertyType::INT64, 0, false, ConstantExpression::make(pool, 0L)); - schema->addField("avgScore", PropertyType::DOUBLE, 0, false, ConstantExpression::make(pool, 0.0)); - schema->addField("serveTeams", PropertyType::INT64, 0, false, ConstantExpression::make(pool, 0L)); + schema->addField( + "playing", PropertyType::BOOL, 0, false, ConstantExpression::make(pool, true)->encode()); + schema->addField( + "career", PropertyType::INT64, 0, false, ConstantExpression::make(pool, 10L)->encode()); + schema->addField( + "startYear", PropertyType::INT64, 0, false, ConstantExpression::make(pool, 0L)->encode()); + schema->addField( + "endYear", PropertyType::INT64, 0, false, ConstantExpression::make(pool, 0L)->encode()); + schema->addField( + "games", PropertyType::INT64, 0, false, ConstantExpression::make(pool, 0L)->encode()); + schema->addField( + "avgScore", PropertyType::DOUBLE, 0, false, ConstantExpression::make(pool, 0.0)->encode()); + schema->addField( + "serveTeams", PropertyType::INT64, 0, false, ConstantExpression::make(pool, 0L)->encode()); // Set ttl property if (FLAGS_mock_ttl_col) { schema->addField( - "insertTime", PropertyType::INT64, 0, false, ConstantExpression::make(pool, 0L)); + "insertTime", PropertyType::INT64, 0, false, ConstantExpression::make(pool, 0L)->encode()); meta::cpp2::SchemaProp prop; prop.ttl_col_ref() = "insertTime"; prop.ttl_duration_ref() = FLAGS_mock_ttl_duration; @@ -329,8 +337,11 @@ std::shared_ptr MockData::mockPlayerTagSchema(Object } // Use default value - schema->addField( - "country", PropertyType::STRING, 0, false, ConstantExpression::make(pool, "America")); + schema->addField("country", + PropertyType::STRING, + 0, + false, + ConstantExpression::make(pool, "America")->encode()); // Use nullable schema->addField("champions", PropertyType::INT64, 0, true); @@ -355,21 +366,27 @@ std::shared_ptr MockData::mockServeEdgeSchema(Object return schema; } schema->addField( - "playerName", PropertyType::STRING, 0, false, ConstantExpression::make(pool, "")); - schema->addField("teamName", PropertyType::STRING, 0, false, ConstantExpression::make(pool, "")); + "playerName", PropertyType::STRING, 0, false, ConstantExpression::make(pool, "")->encode()); schema->addField( - "startYear", PropertyType::INT64, 0, false, ConstantExpression::make(pool, 2020L)); - schema->addField("endYear", PropertyType::INT64, 0, false, ConstantExpression::make(pool, 2020L)); + "teamName", PropertyType::STRING, 0, false, ConstantExpression::make(pool, "")->encode()); + schema->addField( + "startYear", PropertyType::INT64, 0, false, ConstantExpression::make(pool, 2020L)->encode()); + schema->addField( + "endYear", PropertyType::INT64, 0, false, ConstantExpression::make(pool, 2020L)->encode()); // only teamCareer filed has no default value and nullable is false schema->addField("teamCareer", PropertyType::INT64, 0, false); - schema->addField("teamGames", PropertyType::INT64, 0, false, ConstantExpression::make(pool, 1L)); schema->addField( - "teamAvgScore", PropertyType::DOUBLE, 0, false, ConstantExpression::make(pool, 0.0)); + "teamGames", PropertyType::INT64, 0, false, ConstantExpression::make(pool, 1L)->encode()); + schema->addField("teamAvgScore", + PropertyType::DOUBLE, + 0, + false, + ConstantExpression::make(pool, 0.0)->encode()); // Set ttl property if (FLAGS_mock_ttl_col) { schema->addField( - "insertTime", PropertyType::INT64, 0, false, ConstantExpression::make(pool, 0L)); + "insertTime", PropertyType::INT64, 0, false, ConstantExpression::make(pool, 0L)->encode()); meta::cpp2::SchemaProp prop; prop.ttl_col_ref() = "insertTime"; prop.ttl_duration_ref() = FLAGS_mock_ttl_duration; @@ -377,7 +394,8 @@ std::shared_ptr MockData::mockServeEdgeSchema(Object } // Use default value - schema->addField("type", PropertyType::STRING, 0, false, ConstantExpression::make(pool, "trade")); + schema->addField( + "type", PropertyType::STRING, 0, false, ConstantExpression::make(pool, "trade")->encode()); // Use nullable schema->addField("champions", PropertyType::INT64, 0, true); @@ -530,26 +548,41 @@ std::shared_ptr MockData::mockTypicaSchemaV2(ObjectP std::shared_ptr schema(new meta::NebulaSchemaProvider(0)); schema->addField("col_bool", PropertyType::BOOL); schema->addField("col_bool_null", PropertyType::BOOL, 0, true); - schema->addField( - "col_bool_default", PropertyType::BOOL, 0, false, ConstantExpression::make(pool, true)); + schema->addField("col_bool_default", + PropertyType::BOOL, + 0, + false, + ConstantExpression::make(pool, true)->encode()); schema->addField("col_int", PropertyType::INT64); schema->addField("col_int_null", PropertyType::INT64, 0, true); - schema->addField( - "col_int_default", PropertyType::INT64, 0, false, ConstantExpression::make(pool, 20L)); + schema->addField("col_int_default", + PropertyType::INT64, + 0, + false, + ConstantExpression::make(pool, 20L)->encode()); schema->addField("col_float", PropertyType::FLOAT); schema->addField("col_float_null", PropertyType::FLOAT, 0, true); - schema->addField( - "col_float_default", PropertyType::FLOAT, 0, false, ConstantExpression::make(pool, 2.2F)); + schema->addField("col_float_default", + PropertyType::FLOAT, + 0, + false, + ConstantExpression::make(pool, 2.2F)->encode()); schema->addField("col_str", PropertyType::STRING); schema->addField("col_str_null", PropertyType::STRING, 0, true); - schema->addField( - "col_str_default", PropertyType::STRING, 0, false, ConstantExpression::make(pool, "sky")); + schema->addField("col_str_default", + PropertyType::STRING, + 0, + false, + ConstantExpression::make(pool, "sky")->encode()); schema->addField("col_date", PropertyType::DATE); schema->addField("col_date_null", PropertyType::DATE, 0, true); const Date date = {2020, 2, 20}; - schema->addField( - "col_date_default", PropertyType::DATE, 0, false, ConstantExpression::make(pool, date)); + schema->addField("col_date_default", + PropertyType::DATE, + 0, + false, + ConstantExpression::make(pool, date)->encode()); return schema; } diff --git a/src/storage/exec/QueryUtils.h b/src/storage/exec/QueryUtils.h index 20a8b5685b6..948235802b9 100644 --- a/src/storage/exec/QueryUtils.h +++ b/src/storage/exec/QueryUtils.h @@ -57,7 +57,9 @@ class QueryUtils final { VLOG(1) << "Fail to read prop " << propName; if (field->hasDefault()) { DefaultValueContext expCtx; - auto expr = field->defaultValue()->clone(); + ObjectPool pool; + auto& exprStr = field->defaultValue(); + auto expr = Expression::decode(&pool, folly::StringPiece(exprStr.data(), exprStr.size())); return Expression::eval(expr, expCtx); } else if (field->nullable()) { return NullType::__NULL__; diff --git a/src/storage/exec/UpdateNode.h b/src/storage/exec/UpdateNode.h index f000c21e87d..b2114e05878 100644 --- a/src/storage/exec/UpdateNode.h +++ b/src/storage/exec/UpdateNode.h @@ -54,7 +54,9 @@ class UpdateNode : public RelNode { nebula::cpp2::ErrorCode getDefaultOrNullValue(const meta::SchemaProviderIf::Field* field, const std::string& name) { if (field->hasDefault()) { - auto expr = field->defaultValue()->clone(); + ObjectPool pool; + auto& exprStr = field->defaultValue(); + auto expr = Expression::decode(&pool, folly::StringPiece(exprStr.data(), exprStr.size())); props_[field->name()] = Expression::eval(expr, *expCtx_); } else if (field->nullable()) { props_[name] = Value::kNullValue; diff --git a/src/storage/test/IndexWithTTLTest.cpp b/src/storage/test/IndexWithTTLTest.cpp index b5142e3517b..30b525e247d 100644 --- a/src/storage/test/IndexWithTTLTest.cpp +++ b/src/storage/test/IndexWithTTLTest.cpp @@ -67,8 +67,11 @@ void createSchema(meta::SchemaManager* schemaMan, auto* sm = reinterpret_cast(schemaMan); std::shared_ptr schema(new meta::NebulaSchemaProvider(0)); schema->addField("c1", nebula::cpp2::PropertyType::INT64, 0, false); - schema->addField( - "c2", nebula::cpp2::PropertyType::INT64, 0, false, ConstantExpression::make(pool, 0L)); + schema->addField("c2", + nebula::cpp2::PropertyType::INT64, + 0, + false, + ConstantExpression::make(pool, 0L)->encode()); meta::cpp2::SchemaProp prop; prop.ttl_col_ref() = "c2"; prop.ttl_duration_ref() = duration; diff --git a/src/storage/transaction/ChainAddEdgesLocalProcessor.cpp b/src/storage/transaction/ChainAddEdgesLocalProcessor.cpp index 0a3eed149db..1e58236c370 100644 --- a/src/storage/transaction/ChainAddEdgesLocalProcessor.cpp +++ b/src/storage/transaction/ChainAddEdgesLocalProcessor.cpp @@ -497,7 +497,9 @@ void ChainAddEdgesLocalProcessor::replaceNullWithDefaultValue(cpp2::AddEdgesRequ for (auto i = vals.size(); i < idxVec.size(); ++i) { auto field = schema->field(idxVec[i]); if (field->hasDefault()) { - auto expr = field->defaultValue()->clone(); + auto exprStr = field->defaultValue(); + ObjectPool pool; + auto expr = Expression::decode(&pool, folly::StringPiece(exprStr.data(), exprStr.size())); auto defVal = Expression::eval(expr, expCtx); switch (defVal.type()) { case Value::Type::BOOL: