From d113f4a98872ed3744f4a0db1da62419124efb73 Mon Sep 17 00:00:00 2001 From: "hs.zhang" <22708345+cangfengzhs@users.noreply.github.com> Date: Wed, 26 Jan 2022 10:11:55 +0800 Subject: [PATCH] fix memory increase (#3806) --- src/clients/meta/MetaClient.cpp | 22 +--- src/clients/meta/MetaClient.h | 2 - src/codec/RowWriterV2.cpp | 6 +- src/codec/test/ResultSchemaProvider.cpp | 10 +- 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/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 | 111 ++++++++++++------ src/storage/exec/QueryUtils.h | 4 +- src/storage/exec/UpdateNode.h | 4 +- src/storage/test/IndexWithTTLTest.cpp | 7 +- .../ChainAddEdgesProcessorLocal.cpp | 4 +- 18 files changed, 134 insertions(+), 91 deletions(-) diff --git a/src/clients/meta/MetaClient.cpp b/src/clients/meta/MetaClient.cpp index 6660db4bb7e..df1dac4f89f 100644 --- a/src/clients/meta/MetaClient.cpp +++ b/src/clients/meta/MetaClient.cpp @@ -340,32 +340,20 @@ bool MetaClient::loadSchemas(GraphSpaceID spaceId, EdgeSchemas edgeSchemas; TagID lastTagId = -1; - auto addSchemaField = [&spaceInfoCache](NebulaSchemaProvider* schema, - const cpp2::ColumnDef& col) { + auto 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 defaultValueExprStr = ""; if (hasDef) { - auto encoded = *col.get_default_value(); - defaultValueExpr = Expression::decode(&(spaceInfoCache->pool_), - folly::StringPiece(encoded.data(), encoded.size())); - - if (defaultValueExpr == nullptr) { - LOG(ERROR) << "Wrong expr default value for column name: " << col.get_name(); - hasDef = false; - } + defaultValueExprStr = *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, defaultValueExprStr, geoShape); }; for (auto& tagIt : tagItemVec) { diff --git a/src/clients/meta/MetaClient.h b/src/clients/meta/MetaClient.h index 6149c202012..f82c0c682ac 100644 --- a/src/clients/meta/MetaClient.h +++ b/src/clients/meta/MetaClient.h @@ -79,8 +79,6 @@ struct SpaceInfoCache { Indexes tagIndexes_; Indexes edgeIndexes_; Listeners listeners_; - // objPool used to decode when adding field - ObjectPool pool_; std::unordered_map termOfPartition_; }; diff --git a/src/codec/RowWriterV2.cpp b/src/codec/RowWriterV2.cpp index b4b6874037a..829ae6bd886 100644 --- a/src/codec/RowWriterV2.cpp +++ b/src/codec/RowWriterV2.cpp @@ -783,7 +783,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: @@ -816,7 +818,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 d4cebcee974..d3f0b6a5214 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), @@ -37,13 +37,13 @@ const char* ResultSchemaProvider::ResultSchemaField::name() const { return name_ PropertyType ResultSchemaProvider::ResultSchemaField::type() const { return type_; } -bool ResultSchemaProvider::ResultSchemaField::hasDefault() const { - return defaultValue_ != nullptr; -} +bool ResultSchemaProvider::ResultSchemaField::hasDefault() const { return defaultValue_ != ""; } bool ResultSchemaProvider::ResultSchemaField::nullable() const { return nullable_; } -Expression* ResultSchemaProvider::ResultSchemaField::defaultValue() const { return defaultValue_; } +const std::string& ResultSchemaProvider::ResultSchemaField::defaultValue() const { + return defaultValue_; +} size_t ResultSchemaProvider::ResultSchemaField::size() const { return size_; } diff --git a/src/codec/test/ResultSchemaProvider.h b/src/codec/test/ResultSchemaProvider.h index 54efa873d02..c56a4f01883 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; meta::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 10f046e2b50..64debd5cd39 100644 --- a/src/codec/test/SchemaWriter.cpp +++ b/src/codec/test/SchemaWriter.cpp @@ -87,8 +87,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 548e8565992..0c141da4a6f 100644 --- a/src/common/meta/NebulaSchemaProvider.cpp +++ b/src/common/meta/NebulaSchemaProvider.cpp @@ -90,7 +90,7 @@ void NebulaSchemaProvider::addField(folly::StringPiece name, cpp2::PropertyType type, size_t fixedStrLen, bool nullable, - Expression* defaultValue, + std::string defaultValue, cpp2::GeoShape geoShape) { size_t size = fieldSize(type, fixedStrLen); @@ -108,7 +108,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 068dd9baa38..89d14fe2d32 100644 --- a/src/common/meta/NebulaSchemaProvider.h +++ b/src/common/meta/NebulaSchemaProvider.h @@ -25,7 +25,7 @@ class NebulaSchemaProvider : public SchemaProviderIf { cpp2::PropertyType type, bool nullable, bool hasDefault, - Expression* defaultValue, + std::string defaultValue, size_t size, size_t offset, size_t nullFlagPos, @@ -48,7 +48,7 @@ class NebulaSchemaProvider : public SchemaProviderIf { bool hasDefault() const override { return hasDefault_; } - Expression* defaultValue() const override { return defaultValue_; } + const std::string& defaultValue() const override { return defaultValue_; } size_t size() const override { return size_; } @@ -66,7 +66,7 @@ class NebulaSchemaProvider : public SchemaProviderIf { cpp2::PropertyType type_; bool nullable_; bool hasDefault_; - Expression* defaultValue_; + std::string defaultValue_; size_t size_; size_t offset_; size_t nullFlagPos_; @@ -97,7 +97,7 @@ class NebulaSchemaProvider : public SchemaProviderIf { 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(cpp2::PropertyType type, std::size_t fixedStrLimit); diff --git a/src/common/meta/SchemaProviderIf.h b/src/common/meta/SchemaProviderIf.h index 29b7130b4d5..4f0c1e69eea 100644 --- a/src/common/meta/SchemaProviderIf.h +++ b/src/common/meta/SchemaProviderIf.h @@ -24,7 +24,7 @@ class SchemaProviderIf { virtual 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/graph/util/SchemaUtil.cpp b/src/graph/util/SchemaUtil.cpp index 9398d20a002..c60d8774568 100644 --- a/src/graph/util/SchemaUtil.cpp +++ b/src/graph/util/SchemaUtil.cpp @@ -54,19 +54,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.get_default_value(); } 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 f30cbd19ad7..f34ad1edb3f 100644 --- a/src/graph/util/SchemaUtil.h +++ b/src/graph/util/SchemaUtil.h @@ -30,7 +30,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 8fc51f5bd70..1be911031b0 100644 --- a/src/graph/validator/MaintainValidator.cpp +++ b/src/graph/validator/MaintainValidator.cpp @@ -154,8 +154,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); @@ -177,8 +176,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 9048dab224f..9ccede71f28 100644 --- a/src/graph/validator/MutateValidator.cpp +++ b/src/graph/validator/MutateValidator.cpp @@ -242,9 +242,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 89af0c918d4..db476b159c4 100644 --- a/src/mock/MockData.cpp +++ b/src/mock/MockData.cpp @@ -305,24 +305,48 @@ std::shared_ptr MockData::mockPlayerTagSchema(Object if (!hasProp) { return schema; } - schema->addField( - "name", meta::cpp2::PropertyType::STRING, 0, false, ConstantExpression::make(pool, "")); + schema->addField("name", + meta::cpp2::PropertyType::STRING, + 0, + false, + ConstantExpression::make(pool, "")->encode()); // only age filed has no default value and nullable is false schema->addField("age", meta::cpp2::PropertyType::INT64, 0, false); - schema->addField( - "playing", meta::cpp2::PropertyType::BOOL, 0, false, ConstantExpression::make(pool, true)); - schema->addField( - "career", meta::cpp2::PropertyType::INT64, 0, false, ConstantExpression::make(pool, 10L)); - schema->addField( - "startYear", meta::cpp2::PropertyType::INT64, 0, false, ConstantExpression::make(pool, 0L)); - schema->addField( - "endYear", meta::cpp2::PropertyType::INT64, 0, false, ConstantExpression::make(pool, 0L)); - schema->addField( - "games", meta::cpp2::PropertyType::INT64, 0, false, ConstantExpression::make(pool, 0L)); - schema->addField( - "avgScore", meta::cpp2::PropertyType::DOUBLE, 0, false, ConstantExpression::make(pool, 0.0)); - schema->addField( - "serveTeams", meta::cpp2::PropertyType::INT64, 0, false, ConstantExpression::make(pool, 0L)); + schema->addField("playing", + meta::cpp2::PropertyType::BOOL, + 0, + false, + ConstantExpression::make(pool, true)->encode()); + schema->addField("career", + meta::cpp2::PropertyType::INT64, + 0, + false, + ConstantExpression::make(pool, 10L)->encode()); + schema->addField("startYear", + meta::cpp2::PropertyType::INT64, + 0, + false, + ConstantExpression::make(pool, 0L)->encode()); + schema->addField("endYear", + meta::cpp2::PropertyType::INT64, + 0, + false, + ConstantExpression::make(pool, 0L)->encode()); + schema->addField("games", + meta::cpp2::PropertyType::INT64, + 0, + false, + ConstantExpression::make(pool, 0L)->encode()); + schema->addField("avgScore", + meta::cpp2::PropertyType::DOUBLE, + 0, + false, + ConstantExpression::make(pool, 0.0)->encode()); + schema->addField("serveTeams", + meta::cpp2::PropertyType::INT64, + 0, + false, + ConstantExpression::make(pool, 0L)->encode()); // Set ttl property if (FLAGS_mock_ttl_col) { @@ -330,7 +354,7 @@ std::shared_ptr MockData::mockPlayerTagSchema(Object meta::cpp2::PropertyType::INT64, 0, false, - ConstantExpression::make(pool, 0L)); + ConstantExpression::make(pool, 0L)->encode()); meta::cpp2::SchemaProp prop; prop.set_ttl_col("insertTime"); prop.set_ttl_duration(FLAGS_mock_ttl_duration); @@ -342,7 +366,7 @@ std::shared_ptr MockData::mockPlayerTagSchema(Object meta::cpp2::PropertyType::STRING, 0, false, - ConstantExpression::make(pool, "America")); + ConstantExpression::make(pool, "America")->encode()); // Use nullable schema->addField("champions", meta::cpp2::PropertyType::INT64, 0, true); @@ -366,26 +390,38 @@ std::shared_ptr MockData::mockServeEdgeSchema(Object if (!hasProp) { return schema; } - schema->addField( - "playerName", meta::cpp2::PropertyType::STRING, 0, false, ConstantExpression::make(pool, "")); - schema->addField( - "teamName", meta::cpp2::PropertyType::STRING, 0, false, ConstantExpression::make(pool, "")); + schema->addField("playerName", + meta::cpp2::PropertyType::STRING, + 0, + false, + ConstantExpression::make(pool, "")->encode()); + schema->addField("teamName", + meta::cpp2::PropertyType::STRING, + 0, + false, + ConstantExpression::make(pool, "")->encode()); schema->addField("startYear", meta::cpp2::PropertyType::INT64, 0, false, - ConstantExpression::make(pool, 2020L)); - schema->addField( - "endYear", meta::cpp2::PropertyType::INT64, 0, false, ConstantExpression::make(pool, 2020L)); + ConstantExpression::make(pool, 2020L)->encode()); + schema->addField("endYear", + meta::cpp2::PropertyType::INT64, + 0, + false, + ConstantExpression::make(pool, 2020L)->encode()); // only teamCareer filed has no default value and nullable is false schema->addField("teamCareer", meta::cpp2::PropertyType::INT64, 0, false); - schema->addField( - "teamGames", meta::cpp2::PropertyType::INT64, 0, false, ConstantExpression::make(pool, 1L)); + schema->addField("teamGames", + meta::cpp2::PropertyType::INT64, + 0, + false, + ConstantExpression::make(pool, 1L)->encode()); schema->addField("teamAvgScore", meta::cpp2::PropertyType::DOUBLE, 0, false, - ConstantExpression::make(pool, 0.0)); + ConstantExpression::make(pool, 0.0)->encode()); // Set ttl property if (FLAGS_mock_ttl_col) { @@ -393,7 +429,7 @@ std::shared_ptr MockData::mockServeEdgeSchema(Object meta::cpp2::PropertyType::INT64, 0, false, - ConstantExpression::make(pool, 0L)); + ConstantExpression::make(pool, 0L)->encode()); meta::cpp2::SchemaProp prop; prop.set_ttl_col("insertTime"); prop.set_ttl_duration(FLAGS_mock_ttl_duration); @@ -401,8 +437,11 @@ std::shared_ptr MockData::mockServeEdgeSchema(Object } // Use default value - schema->addField( - "type", meta::cpp2::PropertyType::STRING, 0, false, ConstantExpression::make(pool, "trade")); + schema->addField("type", + meta::cpp2::PropertyType::STRING, + 0, + false, + ConstantExpression::make(pool, "trade")->encode()); // Use nullable schema->addField("champions", meta::cpp2::PropertyType::INT64, 0, true); @@ -558,28 +597,28 @@ std::shared_ptr MockData::mockTypicaSchemaV2(ObjectP meta::cpp2::PropertyType::BOOL, 0, false, - ConstantExpression::make(pool, true)); + ConstantExpression::make(pool, true)->encode()); schema->addField("col_int", meta::cpp2::PropertyType::INT64); schema->addField("col_int_null", meta::cpp2::PropertyType::INT64, 0, true); schema->addField("col_int_default", meta::cpp2::PropertyType::INT64, 0, false, - ConstantExpression::make(pool, 20L)); + ConstantExpression::make(pool, 20L)->encode()); schema->addField("col_float", meta::cpp2::PropertyType::FLOAT); schema->addField("col_float_null", meta::cpp2::PropertyType::FLOAT, 0, true); schema->addField("col_float_default", meta::cpp2::PropertyType::FLOAT, 0, false, - ConstantExpression::make(pool, 2.2F)); + ConstantExpression::make(pool, 2.2F)->encode()); schema->addField("col_str", meta::cpp2::PropertyType::STRING); schema->addField("col_str_null", meta::cpp2::PropertyType::STRING, 0, true); schema->addField("col_str_default", meta::cpp2::PropertyType::STRING, 0, false, - ConstantExpression::make(pool, "sky")); + ConstantExpression::make(pool, "sky")->encode()); schema->addField("col_date", meta::cpp2::PropertyType::DATE); schema->addField("col_date_null", meta::cpp2::PropertyType::DATE, 0, true); @@ -588,7 +627,7 @@ std::shared_ptr MockData::mockTypicaSchemaV2(ObjectP meta::cpp2::PropertyType::DATE, 0, false, - ConstantExpression::make(pool, date)); + ConstantExpression::make(pool, date)->encode()); return schema; } diff --git a/src/storage/exec/QueryUtils.h b/src/storage/exec/QueryUtils.h index 0eb415c767f..2e11a2d9b15 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 e9ef3c9d072..cc4f37b305e 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 ba6c7b126b3..e8cde838ca8 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", meta::cpp2::PropertyType::INT64, 0, false); - schema->addField( - "c2", meta::cpp2::PropertyType::INT64, 0, false, ConstantExpression::make(pool, 0L)); + schema->addField("c2", + meta::cpp2::PropertyType::INT64, + 0, + false, + ConstantExpression::make(pool, 0L)->encode()); meta::cpp2::SchemaProp prop; prop.set_ttl_col("c2"); prop.set_ttl_duration(duration); diff --git a/src/storage/transaction/ChainAddEdgesProcessorLocal.cpp b/src/storage/transaction/ChainAddEdgesProcessorLocal.cpp index 8662fbfbf10..4859826c17c 100644 --- a/src/storage/transaction/ChainAddEdgesProcessorLocal.cpp +++ b/src/storage/transaction/ChainAddEdgesProcessorLocal.cpp @@ -522,7 +522,9 @@ void ChainAddEdgesProcessorLocal::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: