Everything is prepared for code generation for query like MATCH (n:Label {properties}) RETURN n

This commit is contained in:
Marko Budiselic 2016-10-15 20:16:32 +02:00
parent 6cce530b6c
commit 8ff79c3ace
7 changed files with 134 additions and 15 deletions

1
.gitignore vendored
View File

@ -5,6 +5,7 @@
*.swo
*.out
*.so
*.o
*.dSYM/
memgraph
*~

View File

@ -10,8 +10,8 @@ namespace logging
{
namespace format
{
std::string out = "{} {:<5} [{}] {}\n";
std::string err = out;
static const std::string out = "{} {:<5} [{}] {}\n";
static const std::string err = out;
// TODO: configurable formats
}

View File

@ -46,13 +46,19 @@ enum class EntitySource : uint8_t
MainStorage
};
// TODO: reduce copying
class CypherStateData
{
public:
using tags_type = std::vector<std::string>;
using properties_type = std::map<std::string, int64_t>;
private:
std::map<std::string, EntityStatus> entity_status;
std::map<std::string, EntityType> entity_type;
std::map<std::string, EntitySource> entity_source;
std::map<std::string, std::vector<std::string>> entity_tags;
std::map<std::string, tags_type> entity_tags;
std::map<std::string, properties_type> entity_properties;
public:
bool exist(const std::string &name) const
@ -83,13 +89,6 @@ public:
return entity_source.at(name);
}
auto tags(const std::string& name) const
{
if (entity_tags.find(name) == entity_tags.end())
throw CppGeneratorException("No tags for specified entity");
return entity_tags.at(name);
}
const std::map<std::string, EntityType> &all_typed_enteties()
{
return entity_type;
@ -124,7 +123,15 @@ public:
entity_source[name] = source;
}
void tags(const std::string& name, std::vector<std::string> tags)
// entity tags
auto tags(const std::string& name) const
{
if (entity_tags.find(name) == entity_tags.end())
throw CppGeneratorException("No tags for specified entity");
return entity_tags.at(name);
}
void tags(const std::string& name, tags_type tags)
{
entity_tags[name] = tags;
}
@ -137,4 +144,40 @@ public:
}
entity_tags[name].emplace_back(new_tag);
}
// entity properties
auto properties(const std::string& name) const
{
if (entity_properties.find(name) == entity_properties.end())
throw CppGeneratorException("No properties for specified entity");
return entity_properties.at(name);
}
void properties(const std::string& name, properties_type properties)
{
entity_properties[name] = properties;
}
void index(const std::string& entity, const std::string& property, int64_t index)
{
if (entity_properties.find(entity) != entity_properties.end())
{
entity_properties[entity] = properties_type{};
}
entity_properties[entity][property] = index;
}
auto index(const std::string& entity, const std::string& property_name)
{
if (entity_properties.find(entity) != entity_properties.end())
throw CppGeneratorException("No properties for specified entity");
auto properties = entity_properties.at(entity);
if (properties.find(property_name) != properties.end())
throw CppGeneratorException("No property for specified property name");
return properties[property_name];
}
};

View File

@ -48,6 +48,8 @@ auto return_query_action =
code += code_line(code::find_and_write_vertices_by_label,
entity, label);
}
// TODO: 16/10/2016 create match code if properties exist
}
if (cypher_data.source(entity) == EntitySource::TypeIndex)

View File

@ -409,9 +409,14 @@ public:
auto prop = property_state.property_name;
auto index = property_state.property_index;
auto &data = generator.action_data();
data.parameter_index.emplace(ParameterIndexKey(entity, prop), index);
data.add_entitiy_property(entity, prop);
// update action data
auto &action_data = generator.action_data();
action_data.parameter_index.emplace(ParameterIndexKey(entity, prop), index);
action_data.add_entitiy_property(entity, prop);
// update cypher data
auto &cypher_data = generator.cypher_data();
cypher_data.index(entity, prop, index);
clear_state();
}

View File

@ -0,0 +1,48 @@
# compiler
CXX=clang++
# compile flags
CFLAGS=-std=c++1y -pthread -g2 # -D_GLIBCXX_DEBUG
# includes and libraries
INCLUDE_PATHS=-I../../../include -I../../../libs/fmt -I../../../src
LIB_PATHS=-L../../../libs/fmt/fmt
LDFLAGS=-lfmt
# source and executable
LOG_SRC_PATH=../../..
SOURCES=main.cpp async_log.o sync_log.o stderr.o stdout.o default.o levels.o log.o
EXECUTABLE=a.out
# release target
all: $(EXECUTABLE)
$(EXECUTABLE): $(SOURCES)
$(CXX) $(CFLAGS) $(INCLUDE_PATHS) $(SOURCES) -o $(EXECUTABLE) $(LIB_PATHS) $(LDFLAGS)
# TODO: auto
async_log.o: ../../../src/logging/logs/async_log.cpp
$(CXX) $(CFLAGS) $(INCLUDE_PATHS) -c ../../../src/logging/logs/async_log.cpp
sync_log.o: ../../../src/logging/logs/sync_log.cpp
$(CXX) $(CFLAGS) $(INCLUDE_PATHS) -c ../../../src/logging/logs/sync_log.cpp
stderr.o: ../../../src/logging/streams/stderr.cpp
$(CXX) $(CFLAGS) $(INCLUDE_PATHS) -c ../../../src/logging/streams/stderr.cpp
stdout.o: ../../../src/logging/streams/stdout.cpp
$(CXX) $(CFLAGS) $(INCLUDE_PATHS) -c ../../../src/logging/streams/stdout.cpp
default.o: ../../../src/logging/default.cpp
$(CXX) $(CFLAGS) $(INCLUDE_PATHS) -c ../../../src/logging/default.cpp
levels.o: ../../../src/logging/levels.cpp
$(CXX) $(CFLAGS) $(INCLUDE_PATHS) -c ../../../src/logging/levels.cpp
log.o: ../../../src/logging/log.cpp
$(CXX) $(CFLAGS) $(INCLUDE_PATHS) -c ../../../src/logging/log.cpp
.PHONY:
clean:
rm -f a.out
rm -f *.o

View File

@ -0,0 +1,20 @@
#include <iostream>
#include "logging/default.hpp"
#include "logging/streams/stdout.hpp"
int main(void)
{
// init logging
logging::init_sync();
logging::log->pipe(std::make_unique<Stdout>());
// get Main logger
Logger logger;
logger = logging::log->logger("Main");
logger.info("{}", logging::log->type());
std::string* test = new std::string("test_value");
return 0;
}