Add index to schema
This commit is contained in:
parent
01618fb0f2
commit
f8e1d8c3f6
@ -14,12 +14,14 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "storage/v2/property_value.hpp"
|
||||
#include "storage/v2/schemas.hpp"
|
||||
|
||||
namespace memgraph::storage {
|
||||
|
||||
Schemas::CreationStatus Schemas::AddSchema(const LabelId label, const std::vector<PropertyId> &property_ids) {
|
||||
auto res = schemas_.insert({std::move(label), property_ids}).second;
|
||||
Schemas::CreationStatus Schemas::CreateSchema(const LabelId label,
|
||||
const std::pair<PropertyId, PropertyValue::Type> &property_ids) {
|
||||
auto res = schemas_.insert({label, property_ids}).second;
|
||||
return res ? Schemas::CreationStatus::SUCCESS : Schemas::CreationStatus::FAIL;
|
||||
}
|
||||
|
||||
@ -33,7 +35,22 @@ Schemas::ValidationStatus ValidateVertex(const LabelId primary_label, const Vert
|
||||
if (!schemas_.contains(primary_label)) {
|
||||
return Schemas::ValidationStatus::NO_SCHEMA_DEFINED_FOR_LABEL;
|
||||
}
|
||||
auto &[schema_label, schema_properties] = schemas_[primary_label];
|
||||
if (!utils::Contains(vertex.labels, primary_label)) {
|
||||
return Schemas::ValidationStatus::VERTEX_HAS_NO_PRIMARY_LABEL;
|
||||
}
|
||||
|
||||
auto &[property_id, property_type] = schemas_[primary_label];
|
||||
// Property existence check
|
||||
if (!vertex.properties.HasProperty(property_id)) {
|
||||
return Schemas::ValidationStatus::VERTEX_HAS_NO_PROPERTY;
|
||||
}
|
||||
// Property type check
|
||||
if (vertex.properties.GetProperty(property_id).type_() != property_type) {
|
||||
return Schemas::ValidationStatus::VERTEX_PROPERTY_WRONG_TYPE;
|
||||
}
|
||||
|
||||
// TODO after the introduction of vertex hashing introduce check for vertex
|
||||
// primary key uniqueness
|
||||
|
||||
return Schemas::ValidationStatus::SUCCESS;
|
||||
}
|
||||
|
@ -12,8 +12,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "storage/v2/indices.hpp"
|
||||
#include "storage/v2/property_value.hpp"
|
||||
#include "storage/v2/transaction.hpp"
|
||||
#include "storage/v2/vertex.hpp"
|
||||
@ -38,17 +40,22 @@ class Schemas {
|
||||
enum class ValidationStatus : uint8_t {
|
||||
SUCCESS,
|
||||
VERTEX_DELETED,
|
||||
VERTEX_HAS_NO_PRIMARY_LABEL,
|
||||
VERTEX_HAS_NO_PROPERTY,
|
||||
NO_SCHEMA_DEFINED_FOR_LABEL,
|
||||
VERTEX_HAS_NO_PRIMARY_LABEL
|
||||
VERTEX_PROPERTY_WRONG_TYPE
|
||||
};
|
||||
|
||||
CreationStatus AddSchema(LabelId label, const std::vector<PropertyId> &property_ids);
|
||||
CreationStatus CreateSchema(LabelId label, const std::vector<PropertyId> &property_ids);
|
||||
|
||||
DeletionStatus DeleteSchema(LabelId label);
|
||||
|
||||
ValidationStatus ValidateVertex(LabelId primary_label, const Vertex &vertex, const Transaction &tx,
|
||||
uint64_t commit_timestamp);
|
||||
|
||||
private:
|
||||
std::unordered_map<LabelId, std::vector<PropertyId>> schemas_;
|
||||
std::unordered_map<LabelId, std::pair<PropertyId, PropertyValue::Type>> schemas_;
|
||||
std::unordered_map<LabelId, LabelPropertyIndex> label_property_indices_;
|
||||
};
|
||||
|
||||
} // namespace memgraph::storage
|
||||
|
Loading…
Reference in New Issue
Block a user