# HG changeset patch # User František Kučera # Date 1549216970 -3600 # Node ID 1e6206284c6cfba1c92a6f4719e744542ef4f9e8 # Parent 61fc569b77e6bb5b136e97cd5768b0f5a8808bd4 Guile can now process multiple relations in the stream diff -r 61fc569b77e6 -r 1e6206284c6c src/GuileHandler.h --- a/src/GuileHandler.h Sun Feb 03 12:35:17 2019 +0100 +++ b/src/GuileHandler.h Sun Feb 03 19:02:50 2019 +0100 @@ -56,15 +56,12 @@ Configuration configuration; writer::RelationalWriter* relationalWriter; - wregex relationNameRegEx; - + RelationConfiguration* currentRelationConfiguration = nullptr; vector currentReaderMetadata; vector currentWriterMetadata; vector currentRecord; integer_t currentAttributeIndex = 0; boolean_t includeCurrentRecord = false; - boolean_t filterCurrentRelation = false; - string_t guileCodeWhereCondition; /** * @param attributeName name from relational pipe @@ -147,15 +144,6 @@ public: GuileHandler(writer::RelationalWriter* relationalWriter, Configuration& configuration, const vector& arguments) : relationalWriter(relationalWriter), configuration(configuration) { - - // FIXME: remove and work directly with configuration in startRelation() and attribute() - // i.e. support multiple relationConfigurations - if (configuration.relationConfigurations.size() == 1) { - relationNameRegEx = wregex(configuration.relationConfigurations[0].relation); - guileCodeWhereCondition = configuration.relationConfigurations[0].guileWhere; - } else { - throw cli::RelpipeCLIException(L"FIXME: only single relationConfiguration is currently supported", cli::CLI::EXIT_CODE_UNKNOWN_COMMAND); - } } void startRelation(string_t name, vector attributes) override { @@ -163,27 +151,32 @@ currentReaderMetadata = attributes; // TODO: move to a reusable method (or use same metadata on both reader and writer side?) // TODO: allow structural changes during transformation - // TODO: clear Guile variables for attributes from previous relation currentWriterMetadata.clear(); for (AttributeMetadata readerMetadata : attributes) { currentWriterMetadata.push_back({readerMetadata.getAttributeName(), relationalWriter->toTypeId(readerMetadata.getTypeName())}); } currentRecord.resize(attributes.size()); - filterCurrentRelation = regex_match(name, relationNameRegEx); + + for (int i = 0; i < configuration.relationConfigurations.size(); i++) { + if (regex_match(name, wregex(configuration.relationConfigurations[i].relation))) { + currentRelationConfiguration = &configuration.relationConfigurations[i]; + break; // it there are multiple matches, only the first configuration is used + } + } relationalWriter->startRelation(name, currentWriterMetadata, true); } void attribute(const void* value, const std::type_info& type) override { - if (filterCurrentRelation) { + if (currentRelationConfiguration) { defineGuileVariable(a2v(currentReaderMetadata[currentAttributeIndex].getAttributeName()), value, type, currentReaderMetadata[currentAttributeIndex].getTypeId()); currentAttributeIndex++; // TODO: > 0 ?: if (currentAttributeIndex > 0 && currentAttributeIndex % currentReaderMetadata.size() == 0) { - includeCurrentRecord = scm_to_bool(evalGuileCode(guileCodeWhereCondition)); + includeCurrentRecord = scm_to_bool(evalGuileCode(currentRelationConfiguration->guileWhere)); if (includeCurrentRecord) for (auto attribute : currentWriterMetadata) writeGuileValueToAttribute(attribute); includeCurrentRecord = false; }