# HG changeset patch # User František Kučera # Date 1576271979 -3600 # Node ID c59363fd805b033ea768ebe12ab60e8b3446c212 # Parent c28c6eda540f3a80b08b9459c05022468a5c7bfa support signed integers, negative numbers; binary format change: encode numbers as SLEB128 diff -r c28c6eda540f -r c59363fd805b src/RecfileCommand.h --- a/src/RecfileCommand.h Wed Oct 30 16:47:42 2019 +0100 +++ b/src/RecfileCommand.h Fri Dec 13 22:19:39 2019 +0100 @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -48,11 +49,24 @@ RelationalWriter* writer; string_t currentRelationName; std::vector currentAttributeMetadata; + std::vector currentTypeHints; std::vector currentRecord; std::vector> currentRecords; size_t prefetchCount = 1; bool headerWritten = false; + TypeId findType(string_t attributeName, TypeId defaultType = TypeId::STRING) { + for (AttributeMetadata m : currentTypeHints) if (m.attributeName == attributeName) return m.typeId; + return defaultType; + } + + TypeId recType2typeId(string_t recType) { + // TODO: support more types + // boolean is currently unsupported, because NULLs are not implemented yet and recfile booleans might be null + if (recType == L"int") return TypeId::INTEGER; + else return TypeId::STRING; + } + void writeHeader() { if (headerWritten) return; @@ -65,7 +79,7 @@ std::vector record = currentRecords[i]; for (int j = 0; j < record.size(); j += 2) { if (uniqueAttributeNames.insert(record[j]).second) { - currentAttributeMetadata.push_back({record[j], TypeId::STRING}); // TODO: type from type hints + currentAttributeMetadata.push_back({record[j], findType(record[j])}); } } } @@ -92,11 +106,13 @@ if (name == L"rec") { currentRelationName = value; currentAttributeMetadata.clear(); + currentTypeHints.clear(); currentRecord.clear(); currentRecords.clear(); headerWritten = false; } else if (name == L"type") { - // TODO: save type hint + std::wsmatch match; + if (regex_search(value, match, std::wregex(L"\\s?(.*)\\s+(.*)\\s?"))) currentTypeHints.push_back({match[1], recType2typeId(match[2])}); } else { // ignore – other recfile metadata like keys or auto-increments }