From 7f81fda1c63c3fcb93b661a2a862f01a1571b6d6 Mon Sep 17 00:00:00 2001 From: jbajic Date: Wed, 15 Jun 2022 09:01:55 +0200 Subject: [PATCH] Fix naming for schemaproperty type to schema type --- src/common/types.hpp | 2 +- src/query/frontend/ast/ast.lcp | 5 +- .../frontend/ast/cypher_main_visitor.cpp | 47 +++++++++---------- .../opencypher/grammar/MemgraphCypher.g4 | 4 +- src/query/interpreter.cpp | 20 ++++---- src/storage/v2/schemas.hpp | 38 +++++++-------- 6 files changed, 55 insertions(+), 61 deletions(-) diff --git a/src/common/types.hpp b/src/common/types.hpp index ac4ff27f2..9751bc4ac 100644 --- a/src/common/types.hpp +++ b/src/common/types.hpp @@ -14,6 +14,6 @@ #include namespace memgraph::common { -enum class SchemaPropertyType : uint8_t { BOOL, INT, FLOAT, STRING, DATE, LOCALTIME, LOCALDATETIME, DURATION }; +enum class SchemaType : uint8_t { BOOL, INT, FLOAT, STRING, DATE, LOCALTIME, LOCALDATETIME, DURATION }; } // namespace memgraph::common diff --git a/src/query/frontend/ast/ast.lcp b/src/query/frontend/ast/ast.lcp index 42afeaaad..d8f9245c7 100644 --- a/src/query/frontend/ast/ast.lcp +++ b/src/query/frontend/ast/ast.lcp @@ -2677,7 +2677,7 @@ cpp<# #>cpp ${dest} = storage->GetLabelIx(${source}.name); cpp<#)) - (schema_property_map "std::unordered_map" + (schema_type_map "std::unordered_map" :slk-save #'slk-save-property-map :slk-load #'slk-load-property-map :scope :public)) @@ -2686,9 +2686,6 @@ cpp<# (lcp:define-enum action (create-schema drop-schema show-schema show-schemas) (:serialize)) - (lcp:define-enum schema-type - (bool integer float string duration date localtime localdatetime) - (:serialize)) #>cpp SchemaQuery() = default; diff --git a/src/query/frontend/ast/cypher_main_visitor.cpp b/src/query/frontend/ast/cypher_main_visitor.cpp index db2e92974..4662228d0 100644 --- a/src/query/frontend/ast/cypher_main_visitor.cpp +++ b/src/query/frontend/ast/cypher_main_visitor.cpp @@ -2365,34 +2365,31 @@ antlrcpp::Any CypherMainVisitor::visitCreateSchema(MemgraphCypher::CreateSchemaC auto *schema_query = storage_->Create(); schema_query->action_ = SchemaQuery::Action::CREATE_SCHEMA; schema_query->label_ = AddLabel(ctx->labelName()->accept(this)); - if (!ctx->schemaPropertyMap()) { + if (!ctx->schemaTypeMap()) { throw SemanticException("Schema property map must exist!"); } - std::unordered_map schema_property_map; - // for (auto *property_pair : ctx->schemaPropertyMap()->propertyKeyTypePair()) { - // if (property_pair->propertyType()->getAltNumber()) { - // schema_property_map.insert({property_pair->propertyKeyName()->accept(this), common::SchemaPropertyType::BOOL}); - // } else if (property_pair->propertyType()->STRING()) { - // schema_property_map.insert({property_pair->propertyKeyName()->accept(this), common::SchemaPropertyType::STRING}); - // } else if (property_pair->propertyType()->INTEGER()) { - // schema_property_map.insert({property_pair->propertyKeyName()->accept(this), common::SchemaPropertyType::INT}); - // } else if (property_pair->propertyType()->FLOAT()) { - // schema_property_map.insert({property_pair->propertyKeyName()->accept(this), common::SchemaPropertyType::FLOAT}); - // } else if (property_pair->propertyType()->DATE()) { - // schema_property_map.insert({property_pair->propertyKeyName()->accept(this), common::SchemaPropertyType::DATE}); - // } else if (property_pair->propertyType()->DURATION()) { - // schema_property_map.insert( - // {property_pair->propertyKeyName()->accept(this), common::SchemaPropertyType::DURATION}); - // } else if (property_pair->propertyType()->LOCALDATETIME()) { - // schema_property_map.insert( - // {property_pair->propertyKeyName()->accept(this), common::SchemaPropertyType::LOCALDATETIME}); - // } else if (property_pair->propertyType()->LOCALTIME()) { - // schema_property_map.insert( - // {property_pair->propertyKeyName()->accept(this), common::SchemaPropertyType::LOCALTIME}); - // } - // } - schema_query->schema_property_map_ = std::move(schema_property_map); + std::unordered_map schema_property_map; + for (auto *property_pair : ctx->schemaTypeMap()->propertyKeyTypePair()) { + if (property_pair->propertyType()) { + schema_property_map.insert({property_pair->propertyKeyName()->accept(this), common::SchemaType::BOOL}); + } else if (property_pair->propertyType()->STRING()) { + schema_property_map.insert({property_pair->propertyKeyName()->accept(this), common::SchemaType::STRING}); + } else if (property_pair->propertyType()->INTEGER()) { + schema_property_map.insert({property_pair->propertyKeyName()->accept(this), common::SchemaType::INT}); + } else if (property_pair->propertyType()->FLOAT()) { + schema_property_map.insert({property_pair->propertyKeyName()->accept(this), common::SchemaType::FLOAT}); + } else if (property_pair->propertyType()->DATE()) { + schema_property_map.insert({property_pair->propertyKeyName()->accept(this), common::SchemaType::DATE}); + } else if (property_pair->propertyType()->DURATION()) { + schema_property_map.insert({property_pair->propertyKeyName()->accept(this), common::SchemaType::DURATION}); + } else if (property_pair->propertyType()->LOCALDATETIME()) { + schema_property_map.insert({property_pair->propertyKeyName()->accept(this), common::SchemaType::LOCALDATETIME}); + } else if (property_pair->propertyType()->LOCALTIME()) { + schema_property_map.insert({property_pair->propertyKeyName()->accept(this), common::SchemaType::LOCALTIME}); + } + } + schema_query->schema_type_map_ = std::move(schema_property_map); query_ = schema_query; return schema_query; diff --git a/src/query/frontend/opencypher/grammar/MemgraphCypher.g4 b/src/query/frontend/opencypher/grammar/MemgraphCypher.g4 index 665bde5c3..3e4c7497e 100644 --- a/src/query/frontend/opencypher/grammar/MemgraphCypher.g4 +++ b/src/query/frontend/opencypher/grammar/MemgraphCypher.g4 @@ -401,8 +401,8 @@ propertyType : BOOL propertyKeyTypePair : propertyKeyName propertyType ; -schemaPropertyMap : '(' ( propertyKeyTypePair ( ',' propertyKeyTypePair )* )? ')' ; +schemaTypeMap : '(' ( propertyKeyTypePair ( ',' propertyKeyTypePair )* )? ')' ; -createSchema : CREATE SCHEMA ON ':' labelName schemaPropertyMap ; +createSchema : CREATE SCHEMA ON ':' labelName schemaTypeMap ; dropSchema : DROP SCHEMA ON ':' labelName ; diff --git a/src/query/interpreter.cpp b/src/query/interpreter.cpp index c7c347969..deae6adf4 100644 --- a/src/query/interpreter.cpp +++ b/src/query/interpreter.cpp @@ -853,7 +853,7 @@ Callback HandleSchemaQuery(SchemaQuery *schema_query, const Parameters ¶mete std::transform(schema_types.begin(), schema_types.end(), std::back_inserter(primary_key_properties), [&db](const auto &schema_type) { return db->PropertyToName(schema_type.property_id) + - "::" + storage::SchemaPropertyToString(schema_type.type); + "::" + storage::SchemaTypeToString(schema_type.type); }); schema_info_row.emplace_back(utils::Join(primary_key_properties, ", ")); @@ -881,7 +881,7 @@ Callback HandleSchemaQuery(SchemaQuery *schema_query, const Parameters ¶mete schema_info_row.reserve(2); schema_info_row.emplace_back(db->PropertyToName(schema_property.property_id)); - schema_info_row.emplace_back(SchemaPropertyToString(schema_property.type)); + schema_info_row.emplace_back(storage::SchemaTypeToString(schema_property.type)); results.push_back(std::move(schema_info_row)); } @@ -892,14 +892,14 @@ Callback HandleSchemaQuery(SchemaQuery *schema_query, const Parameters ¶mete } case SchemaQuery::Action::CREATE_SCHEMA: { callback.fn = [interpreter_context, schema_query]() { - // auto *db = interpreter_context->db; - // const auto label = db->NameToLabel(schema_query->label_.name); - // std::vector schemas_types; - // for (const auto &schema_property : schema_query->properties_type_map_) { - // spdlog::info("sasa {}", db->PropertyToName(db->NameToProperty(schema_property.first.name))); - // // schemas_types.emplace_back(db->NameToProperty(schema_property.first.name), schema_property.second); - // } - // const auto res = db->CreateSchema(label, schemas_types); + auto *db = interpreter_context->db; + const auto label = db->NameToLabel(schema_query->label_.name); + std::vector schemas_types; + // for (const auto &schema_property : schema_query->) { + // spdlog::info("sasa {}", db->PropertyToName(db->NameToProperty(schema_property.first.name))); + // // schemas_types.emplace_back(db->NameToProperty(schema_property.first.name), schema_property.second); + // } + // const auto res = db->CreateSchema(label, schemas_types); return std::vector>{}; }; return callback; diff --git a/src/storage/v2/schemas.hpp b/src/storage/v2/schemas.hpp index 1889fcc4b..c5cd74076 100644 --- a/src/storage/v2/schemas.hpp +++ b/src/storage/v2/schemas.hpp @@ -33,7 +33,7 @@ class SchemaViolationException : public utils::BasicException { }; struct SchemaProperty { - common::SchemaPropertyType type; + common::SchemaType type; PropertyId property_id; }; @@ -87,33 +87,33 @@ class Schemas { SchemasMap schemas_; }; -inline std::optional PropertyTypeToSchemaType(const PropertyValue &property_value) { +inline std::optional PropertyTypeToSchemaType(const PropertyValue &property_value) { switch (property_value.type()) { case PropertyValue::Type::Bool: { - return common::SchemaPropertyType::BOOL; + return common::SchemaType::BOOL; } case PropertyValue::Type::Int: { - return common::SchemaPropertyType::INT; + return common::SchemaType::INT; } case PropertyValue::Type::Double: { - return common::SchemaPropertyType::FLOAT; + return common::SchemaType::FLOAT; } case PropertyValue::Type::String: { - return common::SchemaPropertyType::STRING; + return common::SchemaType::STRING; } case PropertyValue::Type::TemporalData: { switch (property_value.ValueTemporalData().type) { case TemporalType::Date: { - return common::SchemaPropertyType::DATE; + return common::SchemaType::DATE; } case TemporalType::LocalDateTime: { - return common::SchemaPropertyType::LOCALDATETIME; + return common::SchemaType::LOCALDATETIME; } case TemporalType::LocalTime: { - return common::SchemaPropertyType::LOCALTIME; + return common::SchemaType::LOCALTIME; } case TemporalType::Duration: { - return common::SchemaPropertyType::DURATION; + return common::SchemaType::DURATION; } } } @@ -125,30 +125,30 @@ inline std::optional PropertyTypeToSchemaType(const } } -inline std::string SchemaPropertyToString(const common::SchemaPropertyType type) { +inline std::string SchemaTypeToString(const common::SchemaType type) { switch (type) { - case common::SchemaPropertyType::BOOL: { + case common::SchemaType::BOOL: { return "Bool"; } - case common::SchemaPropertyType::INT: { + case common::SchemaType::INT: { return "Integer"; } - case common::SchemaPropertyType::FLOAT: { + case common::SchemaType::FLOAT: { return "Float"; } - case common::SchemaPropertyType::STRING: { + case common::SchemaType::STRING: { return "String"; } - case common::SchemaPropertyType::DATE: { + case common::SchemaType::DATE: { return "Date"; } - case common::SchemaPropertyType::LOCALTIME: { + case common::SchemaType::LOCALTIME: { return "LocalTime"; } - case common::SchemaPropertyType::LOCALDATETIME: { + case common::SchemaType::LOCALDATETIME: { return "LocalDateTime"; } - case common::SchemaPropertyType::DURATION: { + case common::SchemaType::DURATION: { return "Duration"; } }