Fix naming for schemaproperty type to schema type

This commit is contained in:
jbajic 2022-06-15 09:01:55 +02:00
parent 8eb136bc82
commit 7f81fda1c6
6 changed files with 55 additions and 61 deletions

View File

@ -14,6 +14,6 @@
#include <cstdint>
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

View File

@ -2677,7 +2677,7 @@ cpp<#
#>cpp
${dest} = storage->GetLabelIx(${source}.name);
cpp<#))
(schema_property_map "std::unordered_map<PropertyIx, common::SchemaPropertyType>"
(schema_type_map "std::unordered_map<PropertyIx, common::SchemaType>"
: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;

View File

@ -2365,34 +2365,31 @@ antlrcpp::Any CypherMainVisitor::visitCreateSchema(MemgraphCypher::CreateSchemaC
auto *schema_query = storage_->Create<SchemaQuery>();
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<PropertyIx, common::SchemaPropertyType> 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<PropertyIx, common::SchemaType> 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;

View File

@ -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 ;

View File

@ -853,7 +853,7 @@ Callback HandleSchemaQuery(SchemaQuery *schema_query, const Parameters &paramete
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 &paramete
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 &paramete
}
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<storage::SchemaProperty> 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<storage::SchemaProperty> 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<std::vector<TypedValue>>{};
};
return callback;

View File

@ -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<common::SchemaPropertyType> PropertyTypeToSchemaType(const PropertyValue &property_value) {
inline std::optional<common::SchemaType> 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<common::SchemaPropertyType> 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";
}
}