Merge with dev.
This commit is contained in:
@@ -42,6 +42,7 @@ enum class EntitySource : uint8_t
|
||||
None,
|
||||
InternalId,
|
||||
LabelIndex,
|
||||
TypeIndex,
|
||||
MainStorage
|
||||
};
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ using cost_t = uint64_t;
|
||||
constexpr cost_t internal_id_cost = 10;
|
||||
constexpr cost_t property_cost = 100;
|
||||
constexpr cost_t label_cost = 1000;
|
||||
constexpr cost_t type_cost = 1000;
|
||||
constexpr cost_t max_cost = max<cost_t>();
|
||||
|
||||
template <typename T>
|
||||
@@ -36,6 +37,7 @@ public:
|
||||
{
|
||||
internal_id,
|
||||
label_index,
|
||||
type_index,
|
||||
property_index,
|
||||
main_storage
|
||||
};
|
||||
@@ -47,6 +49,7 @@ public:
|
||||
{
|
||||
costs[SearchPlace::internal_id] = max<T>();
|
||||
costs[SearchPlace::label_index] = max<T>();
|
||||
costs[SearchPlace::type_index] = max<T>();
|
||||
costs[SearchPlace::property_index] = max<T>();
|
||||
costs[SearchPlace::main_storage] = max<T>();
|
||||
}
|
||||
@@ -80,6 +83,7 @@ using search_cost_t = SearchCost<cost_t>;
|
||||
|
||||
constexpr auto search_internal_id = search_cost_t::SearchPlace::internal_id;
|
||||
constexpr auto search_label_index = search_cost_t::SearchPlace::label_index;
|
||||
constexpr auto search_type_index = search_cost_t::SearchPlace::type_index;
|
||||
constexpr auto search_property_index =
|
||||
search_cost_t::SearchPlace::property_index;
|
||||
constexpr auto search_main_storage = search_cost_t::SearchPlace::main_storage;
|
||||
|
||||
@@ -32,6 +32,7 @@ auto match_query_action =
|
||||
|
||||
auto name = kv.first;
|
||||
|
||||
// TODO: duplicated code -> BIG PROBLEM
|
||||
// find node
|
||||
if (kv.second == ClauseAction::MatchNode) {
|
||||
if (already_matched(cypher_data, name, EntityType::Node))
|
||||
@@ -69,6 +70,13 @@ auto match_query_action =
|
||||
if (place == entity_search::search_main_storage) {
|
||||
cypher_data.source(name, EntitySource::MainStorage);
|
||||
}
|
||||
if (place == entity_search::search_type_index) {
|
||||
if (action_data.entity_data.at(name).tags.size() > 1) {
|
||||
throw SemanticError("Multiple type match (currently NOT supported)");
|
||||
}
|
||||
cypher_data.source(name, EntitySource::TypeIndex);
|
||||
cypher_data.tags(name, action_data.entity_data.at(name).tags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,12 +43,23 @@ auto return_query_action =
|
||||
{
|
||||
if (cypher_data.type(entity) == EntityType::Node) {
|
||||
if (cypher_data.tags(entity).size() == 0)
|
||||
throw CppGeneratorException("entity has no tags");
|
||||
throw CppGeneratorException("node has no labels");
|
||||
auto label = cypher_data.tags(entity).at(0);
|
||||
code += code_line(code::fine_and_write_vertices_by_label,
|
||||
code += code_line(code::find_and_write_vertices_by_label,
|
||||
entity, label);
|
||||
}
|
||||
}
|
||||
|
||||
if (cypher_data.source(entity) == EntitySource::TypeIndex)
|
||||
{
|
||||
if (cypher_data.type(entity) == EntityType::Relationship) {
|
||||
if (cypher_data.tags(entity).size() == 0)
|
||||
throw CppGeneratorException("edge has no tag");
|
||||
auto type = cypher_data.tags(entity).at(0);
|
||||
code += code_line(code::find_and_write_edges_by_type,
|
||||
entity, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (element.is_projection())
|
||||
{
|
||||
|
||||
@@ -344,13 +344,13 @@ auto load_queries(Db &db)
|
||||
if (it_type.count() > it_vertex.count()) {
|
||||
// Going through vertices wiil probably be faster
|
||||
it_vertex.to().for_all([&](auto m) {
|
||||
// PRINT n,m
|
||||
// PRINT n, m
|
||||
});
|
||||
|
||||
} else {
|
||||
// Going through edges wiil probably be faster
|
||||
it_type.to().for_all([&](auto m) {
|
||||
// PRINT n,m
|
||||
// PRINT n, m
|
||||
});
|
||||
}
|
||||
|
||||
@@ -361,35 +361,42 @@ auto load_queries(Db &db)
|
||||
auto match_label_type_return = [&db](const properties_t &args) {
|
||||
DbAccessor t(db);
|
||||
|
||||
auto &type = t.type_find_or_create("TYPE");
|
||||
auto &label = t.label_find_or_create("LABEL");
|
||||
try {
|
||||
auto &type = t.type_find_or_create("TYPE");
|
||||
auto &label = t.label_find_or_create("LABEL");
|
||||
|
||||
Option<const VertexAccessor> bt;
|
||||
Option<const VertexAccessor> bt;
|
||||
|
||||
auto it_type = type.index().for_range(t).from().label(label);
|
||||
auto it_type = type.index().for_range(t).from().label(label);
|
||||
|
||||
auto it_vertex = t.vertex_access()
|
||||
.fill()
|
||||
.label(label)
|
||||
.clone_to(bt) // Savepoint
|
||||
.out()
|
||||
.type(type)
|
||||
.replace(bt); // Load savepoint
|
||||
auto it_vertex = t.vertex_access()
|
||||
.fill()
|
||||
.label(label)
|
||||
.clone_to(bt) // Savepoint
|
||||
.out()
|
||||
.type(type)
|
||||
.replace(bt); // Load savepoint
|
||||
|
||||
if (it_type.count() > it_vertex.count()) {
|
||||
// Going through vertices wiil probably be faster
|
||||
it_vertex.for_all([&](auto n) {
|
||||
// PRINT n
|
||||
});
|
||||
if (it_type.count() > it_vertex.count()) {
|
||||
// Going through vertices wiil probably be faster
|
||||
it_vertex.for_all([&](auto n) {
|
||||
// PRINT n
|
||||
});
|
||||
|
||||
} else {
|
||||
// Going through edges wiil probably be faster
|
||||
it_type.for_all([&](auto n) {
|
||||
// PRINT n
|
||||
});
|
||||
} else {
|
||||
// Going through edges wiil probably be faster
|
||||
it_type.for_all([&](auto n) {
|
||||
// PRINT n
|
||||
});
|
||||
}
|
||||
return t.commit();
|
||||
} catch (...) {
|
||||
// Catch all exceptions
|
||||
// Print something to logger
|
||||
t.abort();
|
||||
return false;
|
||||
}
|
||||
|
||||
return t.commit();
|
||||
};
|
||||
|
||||
// Blueprint:
|
||||
|
||||
@@ -71,7 +71,7 @@ const std::string write_all_vertices =
|
||||
" }});\n"
|
||||
" stream.write_meta(\"rw\");\n";
|
||||
|
||||
const std::string fine_and_write_vertices_by_label =
|
||||
const std::string find_and_write_vertices_by_label =
|
||||
"auto &label = t.label_find_or_create(\"{1}\");\n"
|
||||
" stream.write_field(\"{0}\");\n"
|
||||
" label.index().for_range(t)->for_all([&](auto vertex) {{\n"
|
||||
@@ -94,6 +94,17 @@ const std::string write_all_edges =
|
||||
" }});\n"
|
||||
" stream.write_meta(\"rw\");\n";
|
||||
|
||||
const std::string find_and_write_edges_by_type =
|
||||
"auto &type = t.type_find_or_create(\"{1}\");\n"
|
||||
" stream.write_field(\"{0}\");\n"
|
||||
" type.index().for_range(t)->for_all([&](auto edge) {{\n"
|
||||
" stream.write_record();\n"
|
||||
" stream.write_list_header(1);\n"
|
||||
" stream.write(edge);\n"
|
||||
" stream.chunk();\n"
|
||||
" }});\n"
|
||||
" stream.write_meta(\"rw\");\n";
|
||||
|
||||
const std::string return_true = "return true;";
|
||||
|
||||
const std::string todo = "// TODO: {}";
|
||||
|
||||
@@ -358,11 +358,14 @@ public:
|
||||
|
||||
void visit(ast::RelationshipTypeList &ast_relationship_type_list) override
|
||||
{
|
||||
auto &data = generator.action_data();
|
||||
auto &action_data = generator.action_data();
|
||||
|
||||
if (ast_relationship_type_list.has_value()) {
|
||||
auto type = ast_relationship_type_list.value->name;
|
||||
data.add_entity_tag(entity, type);
|
||||
action_data.add_entity_tag(entity, type);
|
||||
action_data.csm.search_cost(
|
||||
entity, entity_search::search_type_index,
|
||||
entity_search::type_cost);
|
||||
}
|
||||
|
||||
Traverser::visit(ast_relationship_type_list);
|
||||
|
||||
Reference in New Issue
Block a user