diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-03-16 10:55:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-16 10:55:09 +0100 |
commit | 62d76a280ae1f7a3b395ef48b55aca03b70a995c (patch) | |
tree | bd777c4ff9454643617bd393b40026bce5c38e64 | |
parent | 86213d4d9eb1c7256ea322a2c91f6a7e55df6e40 (diff) | |
parent | 878e9b0ba053b703494654fa29056aa422f3dea9 (diff) |
Merge pull request #2015 from yahoo/balder/implement-iterator-handler-interface-for-summary-generation
Balder/implement iterator handler interface for summary generation
-rw-r--r-- | document/src/vespa/document/base/fieldpath.h | 5 | ||||
-rw-r--r-- | document/src/vespa/document/fieldvalue/fieldvalue.cpp | 9 | ||||
-rw-r--r-- | document/src/vespa/document/fieldvalue/fieldvalue.h | 6 | ||||
-rw-r--r-- | document/src/vespa/document/fieldvalue/structfieldvalue.h | 1 | ||||
-rw-r--r-- | document/src/vespa/document/fieldvalue/structuredfieldvalue.cpp | 23 | ||||
-rw-r--r-- | document/src/vespa/document/fieldvalue/structuredfieldvalue.h | 8 | ||||
-rw-r--r-- | document/src/vespa/document/repo/configbuilder.h | 1 | ||||
-rw-r--r-- | document/src/vespa/document/repo/fixedtyperepo.cpp | 1 | ||||
-rw-r--r-- | storage/src/vespa/storage/visiting/dumpvisitor.cpp | 2 | ||||
-rw-r--r-- | storage/src/vespa/storage/visiting/recoveryvisitor.cpp | 2 | ||||
-rw-r--r-- | vsm/src/tests/docsum/docsum.cpp | 55 | ||||
-rw-r--r-- | vsm/src/vespa/vsm/common/storagedocument.cpp | 1 | ||||
-rw-r--r-- | vsm/src/vespa/vsm/common/storagedocument.h | 3 | ||||
-rw-r--r-- | vsm/src/vespa/vsm/vsm/docsumfilter.cpp | 3 | ||||
-rw-r--r-- | vsm/src/vespa/vsm/vsm/slimefieldwriter.cpp | 50 | ||||
-rw-r--r-- | vsm/src/vespa/vsm/vsm/slimefieldwriter.h | 10 |
16 files changed, 84 insertions, 96 deletions
diff --git a/document/src/vespa/document/base/fieldpath.h b/document/src/vespa/document/base/fieldpath.h index f1dcde77331..db009f57e43 100644 --- a/document/src/vespa/document/base/fieldpath.h +++ b/document/src/vespa/document/base/fieldpath.h @@ -1,11 +1,10 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include <vector> #include <vespa/vespalib/objects/cloneable.h> -#include <vespa/vespalib/util/linkedptr.h> -#include <memory> #include <vespa/document/util/identifiableid.h> +#include <memory> +#include <vector> namespace vespalib { class ObjectVisitor; diff --git a/document/src/vespa/document/fieldvalue/fieldvalue.cpp b/document/src/vespa/document/fieldvalue/fieldvalue.cpp index b8b3e2d0308..5901ea8b4bf 100644 --- a/document/src/vespa/document/fieldvalue/fieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/fieldvalue.cpp @@ -231,10 +231,8 @@ std::string FieldValue::IteratorHandler::toString(const VariableMap& vars) { std::ostringstream out; out << "[ "; - for (FieldValue::IteratorHandler::VariableMap::const_iterator iter = vars.begin(); - iter != vars.end(); - iter++) { - out << iter->first << "=" << iter->second.toString() << " "; + for (const auto & entry : vars) { + out << entry.first << "=" << entry.second.toString() << " "; } out << "]"; return out.str(); @@ -286,9 +284,6 @@ FieldValue::createArray(const DataType & baseType) } } -bool operator != (const FieldValue::LP & a, const FieldValue::LP & b) { return *a != *b; } -bool operator < (const FieldValue::LP & a, const FieldValue::LP & b) { return *a < *b; } - std::ostream& operator<<(std::ostream& out, const FieldValue & p) { p.print(out); return out; diff --git a/document/src/vespa/document/fieldvalue/fieldvalue.h b/document/src/vespa/document/fieldvalue/fieldvalue.h index a6e4b3e868f..e2557725854 100644 --- a/document/src/vespa/document/fieldvalue/fieldvalue.h +++ b/document/src/vespa/document/fieldvalue/fieldvalue.h @@ -11,13 +11,13 @@ */ #pragma once -#include <vespa/vespalib/objects/cloneable.h> #include "fieldvaluevisitor.h" #include <vespa/document/datatype/datatype.h> #include <vespa/document/util/xmlserializable.h> #include <vespa/vespalib/util/polymorphicarrays.h> #include <vespa/document/util/bytebuffer.h> +#include <vespa/vespalib/objects/cloneable.h> #include <map> namespace vespalib { @@ -37,7 +37,6 @@ protected: public: typedef std::unique_ptr<FieldValue> UP; typedef std::shared_ptr<FieldValue> SP; - typedef vespalib::LinkedPtr<FieldValue> LP; typedef vespalib::CloneablePtr<FieldValue> CP; class IteratorHandler { @@ -313,9 +312,6 @@ private: IteratorHandler & handler) const; }; -bool operator != (const FieldValue::LP & a, const FieldValue::LP & b); -bool operator < (const FieldValue::LP & a, const FieldValue::LP & b); - std::ostream& operator<<(std::ostream& out, const FieldValue & p); XmlOutputStream & operator<<(XmlOutputStream & out, const FieldValue & p); diff --git a/document/src/vespa/document/fieldvalue/structfieldvalue.h b/document/src/vespa/document/fieldvalue/structfieldvalue.h index 3bb32fc9690..bc5f1087f5a 100644 --- a/document/src/vespa/document/fieldvalue/structfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/structfieldvalue.h @@ -65,7 +65,6 @@ private: public: typedef std::unique_ptr<StructFieldValue> UP; - typedef vespalib::LinkedPtr<StructFieldValue> LP; StructFieldValue(const DataType &type); ~StructFieldValue(); void swap(StructFieldValue & rhs); diff --git a/document/src/vespa/document/fieldvalue/structuredfieldvalue.cpp b/document/src/vespa/document/fieldvalue/structuredfieldvalue.cpp index 1fc54b8325f..d343f9d5845 100644 --- a/document/src/vespa/document/fieldvalue/structuredfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/structuredfieldvalue.cpp @@ -1,9 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/document/fieldvalue/structuredfieldvalue.hpp> -#include <vespa/document/base/field.h> -#include <vespa/document/fieldvalue/fieldvalues.h> -#include <vespa/vespalib/util/exceptions.h> +#include "structuredfieldvalue.hpp" +#include "fieldvalues.h" #include <vespa/log/log.h> LOG_SETUP(".document.fieldvalue.structured"); @@ -27,14 +25,6 @@ StructuredFieldValue::Iterator::Iterator(const StructuredFieldValue& owner, { } -StructuredFieldValue::Iterator -StructuredFieldValue::Iterator::operator++(int) // postfix -{ - StructuredFieldValue::Iterator it(*this); - operator++(); - return it; -} - StructuredFieldValue::StructuredFieldValue(const StructuredFieldValue& other) : FieldValue(other), _type(other._type) @@ -149,7 +139,7 @@ StructuredFieldValue::onIterateNested( if (handler.handleComplex(*this)) { LOG(spam, "handleComplex"); std::vector<const Field*> fieldsToRemove; - for (const_iterator it(begin()), mt(end()); it != mt; it++) { + for (const_iterator it(begin()), mt(end()); it != mt; ++it) { IteratorHandler::ModificationStatus currStatus = getValue(it.field())->iterateNested(start, end_, handler); if (currStatus == IteratorHandler::REMOVED) { @@ -160,11 +150,8 @@ StructuredFieldValue::onIterateNested( } } - for (std::vector<const Field*>::iterator - i = fieldsToRemove.begin(), last = fieldsToRemove.end(); - i != last; ++i) - { - const_cast<StructuredFieldValue&>(*this).remove(**i); + for (const Field * toRemove : fieldsToRemove){ + const_cast<StructuredFieldValue&>(*this).remove(*toRemove); } } diff --git a/document/src/vespa/document/fieldvalue/structuredfieldvalue.h b/document/src/vespa/document/fieldvalue/structuredfieldvalue.h index e0534a6d037..ae888f3e262 100644 --- a/document/src/vespa/document/fieldvalue/structuredfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/structuredfieldvalue.h @@ -10,8 +10,8 @@ */ #pragma once +#include "fieldvalue.h" #include <vespa/document/base/field.h> -#include <vespa/document/fieldvalue/fieldvalue.h> namespace document { @@ -51,8 +51,8 @@ protected: }; class Iterator { const StructuredFieldValue* _owner; - vespalib::LinkedPtr<StructuredIterator> _iterator; - const Field* _field; + StructuredIterator::UP _iterator; + const Field * _field; public: Iterator(); // Generate end iterator @@ -66,7 +66,7 @@ protected: _field = _iterator->getNextField(); return *this; } - Iterator operator++(int); // postfix + bool operator==(const Iterator& other) const { if (_field == 0 && other._field == 0) // both at end() diff --git a/document/src/vespa/document/repo/configbuilder.h b/document/src/vespa/document/repo/configbuilder.h index 5a2932f4663..8c4a48afd95 100644 --- a/document/src/vespa/document/repo/configbuilder.h +++ b/document/src/vespa/document/repo/configbuilder.h @@ -7,6 +7,7 @@ #include <vespa/document/datatype/datatype.h> #include <vespa/document/datatype/structdatatype.h> #include <vespa/vespalib/stllike/string.h> +#include <cassert> namespace document { namespace config_builder { diff --git a/document/src/vespa/document/repo/fixedtyperepo.cpp b/document/src/vespa/document/repo/fixedtyperepo.cpp index 681b7a927db..8344a44921f 100644 --- a/document/src/vespa/document/repo/fixedtyperepo.cpp +++ b/document/src/vespa/document/repo/fixedtyperepo.cpp @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "fixedtyperepo.h" +#include <cassert> namespace document { diff --git a/storage/src/vespa/storage/visiting/dumpvisitor.cpp b/storage/src/vespa/storage/visiting/dumpvisitor.cpp index bbb23d295f1..271217fb7e7 100644 --- a/storage/src/vespa/storage/visiting/dumpvisitor.cpp +++ b/storage/src/vespa/storage/visiting/dumpvisitor.cpp @@ -90,7 +90,7 @@ void DumpVisitor::handleDocuments(const document::BucketId& bucketId, { if (_requestedFields.get()) { for (document::Document::const_iterator docIter - = d->begin(); docIter != d->end(); docIter++) + = d->begin(); docIter != d->end(); ++docIter) { if (_requestedFields->find(docIter.field().getName()) == _requestedFields->end()) diff --git a/storage/src/vespa/storage/visiting/recoveryvisitor.cpp b/storage/src/vespa/storage/visiting/recoveryvisitor.cpp index 705b3f8d45e..b6fcc0a97c8 100644 --- a/storage/src/vespa/storage/visiting/recoveryvisitor.cpp +++ b/storage/src/vespa/storage/visiting/recoveryvisitor.cpp @@ -61,7 +61,7 @@ RecoveryVisitor::handleDocuments(const document::BucketId& bid, } else { for (document::Document::const_iterator docIter = doc->begin(); docIter != doc->end(); - docIter++) { + ++docIter) { if (_requestedFields.find(docIter.field().getName()) == _requestedFields.end()) { diff --git a/vsm/src/tests/docsum/docsum.cpp b/vsm/src/tests/docsum/docsum.cpp index 51894ec3eb1..8a1697ab099 100644 --- a/vsm/src/tests/docsum/docsum.cpp +++ b/vsm/src/tests/docsum/docsum.cpp @@ -58,7 +58,7 @@ private: void assertFlattenDocsumWriter(FlattenDocsumWriter & fdw, const FieldValue & fv, const std::string & exp); void assertSlimeFieldWriter(const FieldValue & fv, const std::string & exp) { SlimeFieldWriter sfw; - assertSlimeFieldWriter(sfw, fv, exp); + TEST_DO(assertSlimeFieldWriter(sfw, fv, exp)); } void assertSlimeFieldWriter(SlimeFieldWriter & sfw, const FieldValue & fv, const std::string & exp); @@ -123,30 +123,29 @@ void DocsumTest::testFlattenDocsumWriter() { { // basic tests - assertFlattenDocsumWriter(StringFieldValue("foo bar"), "foo bar"); - assertFlattenDocsumWriter(RawFieldValue("foo bar"), "foo bar"); - assertFlattenDocsumWriter(LongFieldValue(123456789), "123456789"); - assertFlattenDocsumWriter(createFieldValue(StringList().add("foo bar").add("baz").add(" qux ")), - "foo bar baz qux "); + TEST_DO(assertFlattenDocsumWriter(StringFieldValue("foo bar"), "foo bar")); + TEST_DO(assertFlattenDocsumWriter(RawFieldValue("foo bar"), "foo bar")); + TEST_DO(assertFlattenDocsumWriter(LongFieldValue(123456789), "123456789")); + TEST_DO(assertFlattenDocsumWriter(createFieldValue(StringList().add("foo bar").add("baz").add(" qux ")), + "foo bar baz qux ")); } { // test mulitple invokations FlattenDocsumWriter fdw("#"); - assertFlattenDocsumWriter(fdw, StringFieldValue("foo"), "foo"); - assertFlattenDocsumWriter(fdw, StringFieldValue("bar"), "foo#bar"); + TEST_DO(assertFlattenDocsumWriter(fdw, StringFieldValue("foo"), "foo")); + TEST_DO(assertFlattenDocsumWriter(fdw, StringFieldValue("bar"), "foo#bar")); fdw.clear(); - assertFlattenDocsumWriter(fdw, StringFieldValue("baz"), "baz"); - assertFlattenDocsumWriter(fdw, StringFieldValue("qux"), "baz qux"); + TEST_DO(assertFlattenDocsumWriter(fdw, StringFieldValue("baz"), "baz")); + TEST_DO(assertFlattenDocsumWriter(fdw, StringFieldValue("qux"), "baz qux")); } { // test resizing FlattenDocsumWriter fdw("#"); EXPECT_EQUAL(fdw.getResult().getPos(), 0u); EXPECT_EQUAL(fdw.getResult().getLength(), 32u); - assertFlattenDocsumWriter(fdw, StringFieldValue("aaaabbbbccccddddeeeeffffgggghhhh"), - "aaaabbbbccccddddeeeeffffgggghhhh"); + TEST_DO(assertFlattenDocsumWriter(fdw, StringFieldValue("aaaabbbbccccddddeeeeffffgggghhhh"), + "aaaabbbbccccddddeeeeffffgggghhhh")); EXPECT_EQUAL(fdw.getResult().getPos(), 32u); EXPECT_EQUAL(fdw.getResult().getLength(), 32u); - assertFlattenDocsumWriter(fdw, StringFieldValue("aaaa"), - "aaaabbbbccccddddeeeeffffgggghhhh#aaaa"); + TEST_DO(assertFlattenDocsumWriter(fdw, StringFieldValue("aaaa"), "aaaabbbbccccddddeeeeffffgggghhhh#aaaa")); EXPECT_EQUAL(fdw.getResult().getPos(), 37u); EXPECT_TRUE(fdw.getResult().getLength() >= 37u); fdw.clear(); @@ -197,23 +196,21 @@ DocsumTest::testSlimeFieldWriter() { // select a subset and then all SlimeFieldWriter sfw; DocsumFieldSpec::FieldIdentifierVector fields; - fields.push_back(DocsumFieldSpec::FieldIdentifier( - 0, *type.buildFieldPath("a"))); - fields.push_back(DocsumFieldSpec::FieldIdentifier( - 0, *type.buildFieldPath("c.e"))); + fields.push_back(DocsumFieldSpec::FieldIdentifier(0, *type.buildFieldPath("a"))); + fields.push_back(DocsumFieldSpec::FieldIdentifier(0, *type.buildFieldPath("c.e"))); sfw.setInputFields(fields); - assertSlimeFieldWriter(sfw, value, "{\"a\":\"foo\",\"c\":{\"e\":\"qux\"}}"); + TEST_DO(assertSlimeFieldWriter(sfw, value, "{\"a\":\"foo\",\"c\":{\"e\":\"qux\"}}")); sfw.clear(); - assertSlimeFieldWriter(sfw, value, "{\"a\":\"foo\",\"b\":\"bar\",\"c\":{\"d\":\"baz\",\"e\":\"qux\"}}"); + TEST_DO(assertSlimeFieldWriter(sfw, value, "{\"a\":\"foo\",\"b\":\"bar\",\"c\":{\"d\":\"baz\",\"e\":\"qux\"}}")); } { // multiple invocations SlimeFieldWriter sfw; - assertSlimeFieldWriter(sfw, StringFieldValue("foo"), "\"foo\""); + TEST_DO(assertSlimeFieldWriter(sfw, StringFieldValue("foo"), "\"foo\"")); sfw.clear(); - assertSlimeFieldWriter(sfw, StringFieldValue("bar"), "\"bar\""); + TEST_DO(assertSlimeFieldWriter(sfw, StringFieldValue("bar"), "\"bar\"")); sfw.clear(); - assertSlimeFieldWriter(sfw, StringFieldValue("baz"), "\"baz\""); + TEST_DO(assertSlimeFieldWriter(sfw, StringFieldValue("baz"), "\"baz\"")); } } @@ -246,13 +243,13 @@ DocsumTest::requireThatSlimeFieldWriterHandlesMap() DocsumFieldSpec::FieldIdentifierVector fields; fields.push_back(DocsumFieldSpec::FieldIdentifier(0, *mapType.buildFieldPath("value.b"))); sfw.setInputFields(fields); - assertSlimeFieldWriter(sfw, mapfv, "[{\"key\":\"k1\",\"value\":{\"b\":\"bar\"}}]"); + TEST_DO(assertSlimeFieldWriter(sfw, mapfv, "[{\"key\":\"k1\",\"value\":{\"b\":\"bar\"}}]")); fields[0] = DocsumFieldSpec::FieldIdentifier(0, *mapType.buildFieldPath("{k1}.a")); sfw.clear(); sfw.setInputFields(fields); - assertSlimeFieldWriter(sfw, mapfv, "[{\"key\":\"k1\",\"value\":{\"a\":\"foo\"}}]"); + TEST_DO(assertSlimeFieldWriter(sfw, mapfv, "[{\"key\":\"k1\",\"value\":{\"a\":\"foo\"}}]")); sfw.clear(); // all fields implicit - assertSlimeFieldWriter(sfw, mapfv, "[{\"key\":\"k1\",\"value\":{\"a\":\"foo\",\"b\":\"bar\"}}]"); + TEST_DO(assertSlimeFieldWriter(sfw, mapfv, "[{\"key\":\"k1\",\"value\":{\"a\":\"foo\",\"b\":\"bar\"}}]")); } } } @@ -262,9 +259,9 @@ DocsumTest::Main() { TEST_INIT("docsum_test"); - testFlattenDocsumWriter(); - testSlimeFieldWriter(); - requireThatSlimeFieldWriterHandlesMap(); + TEST_DO(testFlattenDocsumWriter()); + TEST_DO(testSlimeFieldWriter()); + TEST_DO(requireThatSlimeFieldWriterHandlesMap()); TEST_DONE(); } diff --git a/vsm/src/vespa/vsm/common/storagedocument.cpp b/vsm/src/vespa/vsm/common/storagedocument.cpp index 1cb636a80c7..83eae8a2403 100644 --- a/vsm/src/vespa/vsm/common/storagedocument.cpp +++ b/vsm/src/vespa/vsm/common/storagedocument.cpp @@ -1,4 +1,5 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + #include "storagedocument.h" #include <vespa/document/fieldvalue/arrayfieldvalue.h> #include <vespa/document/fieldvalue/weightedsetfieldvalue.h> diff --git a/vsm/src/vespa/vsm/common/storagedocument.h b/vsm/src/vespa/vsm/common/storagedocument.h index 3c1f2ddc375..688d1d9d0f8 100644 --- a/vsm/src/vespa/vsm/common/storagedocument.h +++ b/vsm/src/vespa/vsm/common/storagedocument.h @@ -1,8 +1,9 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once +#include "document.h" #include <vespa/document/fieldvalue/document.h> -#include <vespa/vsm/common/document.h> +#include <vespa/vespalib/util/linkedptr.h> namespace vsm { diff --git a/vsm/src/vespa/vsm/vsm/docsumfilter.cpp b/vsm/src/vespa/vsm/vsm/docsumfilter.cpp index e858c8ca8a6..edf737c09cf 100644 --- a/vsm/src/vespa/vsm/vsm/docsumfilter.cpp +++ b/vsm/src/vespa/vsm/vsm/docsumfilter.cpp @@ -2,10 +2,9 @@ #include "docsumfilter.h" #include "slimefieldwriter.h" -#include <vespa/searchsummary/docsummary/resultclass.h> #include <vespa/searchsummary/docsummary/summaryfieldconverter.h> -#include <vespa/document/fieldvalue/literalfieldvalue.h> #include <vespa/document/base/exceptions.h> + #include <vespa/log/log.h> LOG_SETUP(".vsm.docsumfilter"); diff --git a/vsm/src/vespa/vsm/vsm/slimefieldwriter.cpp b/vsm/src/vespa/vsm/vsm/slimefieldwriter.cpp index a0abf8b7a07..61820a3d8f2 100644 --- a/vsm/src/vespa/vsm/vsm/slimefieldwriter.cpp +++ b/vsm/src/vespa/vsm/vsm/slimefieldwriter.cpp @@ -1,9 +1,6 @@ // Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "slimefieldwriter.h" -#include <vespa/vespalib/data/slime/slime.h> -#include <vespa/vespalib/data/slime/convenience.h> -#include <vespa/vespalib/data/slime/binary_format.h> #include <vespa/searchlib/util/slime_output_raw_buf_adapter.h> #include <vespa/vespalib/stllike/asciistream.h> @@ -13,14 +10,27 @@ LOG_SETUP(".vsm.slimefieldwriter"); namespace { vespalib::string -toString(const vsm::FieldPath & fp) +toString(const vsm::FieldPath & fieldPath) { vespalib::asciistream oss; - for (size_t i = 0; i < fp.size(); ++i) { + for (size_t i = 0; i < fieldPath.size(); ++i) { if (i > 0) { oss << "."; } - oss << fp[i].getName(); + oss << fieldPath[i].getName(); + } + return oss.str(); +} + +vespalib::string +toString(const std::vector<vespalib::string> & fieldPath) +{ + vespalib::asciistream oss; + for (size_t i = 0; i < fieldPath.size(); ++i) { + if (i > 0) { + oss << "."; + } + oss << fieldPath[i]; } return oss.str(); } @@ -69,7 +79,6 @@ SlimeFieldWriter::traverseRecursive(const document::FieldValue & fv, } else if (fv.getClass().inherits(document::MapFieldValue::classId)) { const document::MapFieldValue & mfv = static_cast<const document::MapFieldValue &>(fv); - const document::MapDataType& mapType = static_cast<const document::MapDataType &>(*mfv.getDataType()); Cursor &a = inserter.insertArray(); Symbol keysym = a.resolve("key"); Symbol valsym = a.resolve("value"); @@ -77,10 +86,7 @@ SlimeFieldWriter::traverseRecursive(const document::FieldValue & fv, Cursor &o = a.addObject(); ObjectSymbolInserter ki(o, keysym); traverseRecursive(*entry.first, ki); - document::FieldPathEntry valueEntry( - mapType, mapType.getKeyType(), mapType.getValueType(), - false, true); - _currPath.push_back(valueEntry); + _currPath.push_back("value"); ObjectSymbolInserter vi(o, valsym); traverseRecursive(*entry.second, vi); _currPath.pop_back(); @@ -89,16 +95,14 @@ SlimeFieldWriter::traverseRecursive(const document::FieldValue & fv, const document::StructuredFieldValue & sfv = static_cast<const document::StructuredFieldValue &>(fv); Cursor &o = inserter.insertObject(); for (const document::Field & entry : sfv) { - // TODO: Why do we have to iterate like this? - document::FieldPathEntry fi(sfv.getField(entry.getName())); - _currPath.push_back(fi); - if (explorePath()) { + if (explorePath(entry.getName())) { + _currPath.push_back(entry.getName()); Memory keymem(entry.getName()); ObjectInserter oi(o, keymem); document::FieldValue::UP fval(sfv.getValue(entry)); traverseRecursive(*fval, oi); + _currPath.pop_back(); } - _currPath.pop_back(); } } else { if (fv.getClass().inherits(document::LiteralFieldValueB::classId)) { @@ -128,7 +132,7 @@ SlimeFieldWriter::traverseRecursive(const document::FieldValue & fv, } bool -SlimeFieldWriter::explorePath() +SlimeFieldWriter::explorePath(vespalib::stringref candidate) { if (_inputFields == NULL) { return true; @@ -139,11 +143,15 @@ SlimeFieldWriter::explorePath() if (_currPath.size() <= fp.size()) { bool equal = true; for (size_t j = 0; j < _currPath.size() && equal; ++j) { - equal = (fp[j].getName() == _currPath[j].getName()); + equal = (fp[j].getName() == _currPath[j]); } if (equal) { - // the current path matches one of the input field paths - return true; + if (_currPath.size() == fp.size()) { + return true; + } else if (fp[_currPath.size()].getName() == candidate) { + // the current path matches one of the input field paths + return true; + } } } } @@ -158,6 +166,8 @@ SlimeFieldWriter::SlimeFieldWriter() : { } +SlimeFieldWriter::~SlimeFieldWriter() {} + void SlimeFieldWriter::convert(const document::FieldValue & fv) { diff --git a/vsm/src/vespa/vsm/vsm/slimefieldwriter.h b/vsm/src/vespa/vsm/vsm/slimefieldwriter.h index ac540b2ccfe..596a106f370 100644 --- a/vsm/src/vespa/vsm/vsm/slimefieldwriter.h +++ b/vsm/src/vespa/vsm/vsm/slimefieldwriter.h @@ -1,9 +1,9 @@ // Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include <vespa/document/fieldvalue/fieldvalues.h> +#include "docsumfieldspec.h" #include <vespa/vsm/common/storagedocument.h> -#include <vespa/vsm/vsm/docsumfieldspec.h> +#include <vespa/document/fieldvalue/fieldvalues.h> #include <vespa/vespalib/data/slime/slime.h> #include <vespa/searchlib/util/rawbuf.h> @@ -20,13 +20,15 @@ private: search::RawBuf _rbuf; vespalib::Slime _slime; const DocsumFieldSpec::FieldIdentifierVector * _inputFields; - FieldPath _currPath; + std::vector<vespalib::string> _currPath; void traverseRecursive(const document::FieldValue & fv, vespalib::slime::Inserter & inserter); - bool explorePath(); + bool explorePath(vespalib::stringref candidate); public: SlimeFieldWriter(); + ~SlimeFieldWriter(); + /** * Specifies the subset of the field value that should be written. |