aboutsummaryrefslogtreecommitdiffstats
path: root/document/src
diff options
context:
space:
mode:
authorArnstein Ressem <aressem@gmail.com>2020-08-19 17:54:54 +0200
committerGitHub <noreply@github.com>2020-08-19 17:54:54 +0200
commit3a9f8a641d5312e83a34f6aa293f98182c90adfe (patch)
tree4267692e9ed8a798ea0817798c2f16f3a406fc42 /document/src
parentff1749fab8abcb2201f662098552f3aa00e6300f (diff)
Revert "Balder/use an actual fieldset repo"
Diffstat (limited to 'document/src')
-rw-r--r--document/src/tests/fieldsettest.cpp17
-rw-r--r--document/src/vespa/document/base/field.h1
-rw-r--r--document/src/vespa/document/datatype/documenttype.h7
-rw-r--r--document/src/vespa/document/fieldset/fieldset.h8
-rw-r--r--document/src/vespa/document/fieldset/fieldsetrepo.cpp45
-rw-r--r--document/src/vespa/document/fieldset/fieldsetrepo.h11
-rw-r--r--document/src/vespa/document/fieldset/fieldsets.h17
7 files changed, 48 insertions, 58 deletions
diff --git a/document/src/tests/fieldsettest.cpp b/document/src/tests/fieldsettest.cpp
index af23e713735..29581ff4549 100644
--- a/document/src/tests/fieldsettest.cpp
+++ b/document/src/tests/fieldsettest.cpp
@@ -31,7 +31,7 @@ TEST_F(FieldSetTest, testParsing)
(void) dynamic_cast<NoFields&>(*FieldSetRepo::parse(docRepo, NoFields::NAME));
(void) dynamic_cast<DocIdOnly&>(*FieldSetRepo::parse(docRepo, DocIdOnly::NAME));
- auto set = FieldSetRepo::parse(docRepo, "testdoctype1:headerval,content");
+ FieldSet::UP set = FieldSetRepo::parse(docRepo, "testdoctype1:headerval,content");
auto & coll = dynamic_cast<FieldCollection&>(*set);
std::ostringstream ost;
@@ -46,8 +46,8 @@ namespace {
bool checkContains(const DocumentTypeRepo& repo,
const std::string& str1, const std::string & str2) {
- auto set1 = FieldSetRepo::parse(repo, str1);
- auto set2 = FieldSetRepo::parse(repo, str2);
+ FieldSet::UP set1 = FieldSetRepo::parse(repo, str1);
+ FieldSet::UP set2 = FieldSetRepo::parse(repo, str2);
return set1->contains(*set2);
}
@@ -141,7 +141,7 @@ FieldSetTest::doCopyFields(const Document& src,
if (!dest) {
dest = &destDoc;
}
- auto fset = FieldSetRepo::parse(docRepo, fieldSetStr);
+ FieldSet::UP fset = FieldSetRepo::parse(docRepo, fieldSetStr);
FieldSet::copyFields(*dest, src, *fset);
return stringifyFields(*dest);
}
@@ -152,7 +152,7 @@ FieldSetTest::doStripFields(const Document& doc,
const std::string& fieldSetStr)
{
Document::UP copy(doc.clone());
- auto fset = FieldSetRepo::parse(docRepo, fieldSetStr);
+ FieldSet::UP fset = FieldSetRepo::parse(docRepo, fieldSetStr);
FieldSet::stripFields(*copy, *fset);
return stringifyFields(*copy);
}
@@ -198,7 +198,7 @@ FieldSetTest::doCopyDocument(const Document& src,
const DocumentTypeRepo& docRepo,
const std::string& fieldSetStr)
{
- auto fset = FieldSetRepo::parse(docRepo, fieldSetStr);
+ FieldSet::UP fset = FieldSetRepo::parse(docRepo, fieldSetStr);
Document::UP doc(FieldSet::createDocumentSubsetCopy(src, *fset));
return stringifyFields(*doc);
}
@@ -244,9 +244,10 @@ TEST_F(FieldSetTest, testSerialize)
"testdoctype1:content,hstringval"
};
+ FieldSetRepo repo;
for (const char * fieldSet : fieldSets) {
- auto fs = FieldSetRepo::parse(docRepo, fieldSet);
- EXPECT_EQ(vespalib::string(fieldSet), FieldSetRepo::serialize(*fs));
+ FieldSet::UP fs = FieldSetRepo::parse(docRepo, fieldSet);
+ EXPECT_EQ(vespalib::string(fieldSet), repo.serialize(*fs));
}
}
diff --git a/document/src/vespa/document/base/field.h b/document/src/vespa/document/base/field.h
index 305021ef29a..7580b2b692f 100644
--- a/document/src/vespa/document/base/field.h
+++ b/document/src/vespa/document/base/field.h
@@ -88,6 +88,7 @@ public:
*/
Field(vespalib::stringref name, const DataType &dataType);
+ Field* clone() const override { return new Field(*this); }
std::unique_ptr<FieldValue> createValue() const;
// Note that only id is checked for equality.
diff --git a/document/src/vespa/document/datatype/documenttype.h b/document/src/vespa/document/datatype/documenttype.h
index fae65addb48..ed6e9e66ab5 100644
--- a/document/src/vespa/document/datatype/documenttype.h
+++ b/document/src/vespa/document/datatype/documenttype.h
@@ -61,10 +61,12 @@ public:
DocumentType();
DocumentType(vespalib::stringref name, int32_t id);
- DocumentType(vespalib::stringref name, int32_t id, const StructDataType& fields);
+ DocumentType(vespalib::stringref name, int32_t id,
+ const StructDataType& fields);
explicit DocumentType(vespalib::stringref name);
- DocumentType(vespalib::stringref name, const StructDataType& fields);
+ DocumentType(vespalib::stringref name,
+ const StructDataType& fields);
~DocumentType() override;
@@ -99,7 +101,6 @@ public:
DocumentType & addFieldSet(const vespalib::string & name, FieldSet::Fields fields);
const FieldSet * getFieldSet(const vespalib::string & name) const;
- const FieldSetMap & getFieldSets() const { return _fieldSets; }
const ImportedFieldNames& imported_field_names() const noexcept {
return _imported_field_names;
diff --git a/document/src/vespa/document/fieldset/fieldset.h b/document/src/vespa/document/fieldset/fieldset.h
index 3d74659ebf5..35c912c5e45 100644
--- a/document/src/vespa/document/fieldset/fieldset.h
+++ b/document/src/vespa/document/fieldset/fieldset.h
@@ -23,8 +23,7 @@ public:
DOCID
};
- using SP = std::shared_ptr<FieldSet>;
- using UP = std::unique_ptr<FieldSet>;
+ typedef std::unique_ptr<FieldSet> UP;
virtual ~FieldSet() = default;
@@ -40,6 +39,11 @@ public:
virtual Type getType() const = 0;
/**
+ * @return Returns a copy of this object.
+ */
+ virtual FieldSet* clone() const = 0;
+
+ /**
* Copy all fields from src into dest that are contained within the
* given field set. If any copied field pre-exists in dest, it will
* be overwritten.
diff --git a/document/src/vespa/document/fieldset/fieldsetrepo.cpp b/document/src/vespa/document/fieldset/fieldsetrepo.cpp
index 5bde291c8dd..33cbf6185c4 100644
--- a/document/src/vespa/document/fieldset/fieldsetrepo.cpp
+++ b/document/src/vespa/document/fieldset/fieldsetrepo.cpp
@@ -5,7 +5,6 @@
#include <vespa/vespalib/util/exceptions.h>
#include <vespa/vespalib/stllike/asciistream.h>
#include <vespa/document/repo/documenttyperepo.h>
-#include <vespa/vespalib/stllike/hash_map.hpp>
using vespalib::StringTokenizer;
@@ -13,25 +12,27 @@ namespace document {
namespace {
-FieldSet::SP
+FieldSet::UP
parseSpecialValues(vespalib::stringref name)
{
+ FieldSet::UP fs;
if ((name.size() == 4) && (name[1] == 'i') && (name[2] == 'd') && (name[3] == ']')) {
- return std::make_shared<DocIdOnly>();
+ fs = std::make_unique<DocIdOnly>();
} else if ((name.size() == 5) && (name[1] == 'a') && (name[2] == 'l') && (name[3] == 'l') && (name[4] == ']')) {
- return std::make_shared<AllFields>();
+ fs = std::make_unique<AllFields>();
} else if ((name.size() == 6) && (name[1] == 'n') && (name[2] == 'o') && (name[3] == 'n') && (name[4] == 'e') && (name[5] == ']')) {
- return std::make_shared<NoFields>();
+ fs = std::make_unique<NoFields>();
} else if ((name.size() == 7) && (name[1] == 'd') && (name[2] == 'o') && (name[3] == 'c') && (name[4] == 'i') && (name[5] == 'd') && (name[6] == ']')) {
- return std::make_shared<DocIdOnly>();
+ fs = std::make_unique<DocIdOnly>();
} else {
throw vespalib::IllegalArgumentException(
"The only special names (enclosed in '[]') allowed are "
"id, all, none, not '" + name + "'.");
}
+ return fs;
}
-FieldSet::SP
+FieldSet::UP
parseFieldCollection(const DocumentTypeRepo& repo,
vespalib::stringref docType,
vespalib::stringref fieldNames)
@@ -54,12 +55,12 @@ parseFieldCollection(const DocumentTypeRepo& repo,
builder.add(&type.getField(token));
}
}
- return std::make_shared<FieldCollection>(type, builder.build());
+ return std::make_unique<FieldCollection>(type, builder.build());
}
}
-FieldSet::SP
+FieldSet::UP
FieldSetRepo::parse(const DocumentTypeRepo& repo, vespalib::stringref str)
{
if (str[0] == '[') {
@@ -110,31 +111,5 @@ FieldSetRepo::serialize(const FieldSet& fieldSet)
}
}
-
-FieldSetRepo::FieldSetRepo(const DocumentTypeRepo& repo)
- : _doumentTyperepo(repo),
- _configuredFieldSets()
-{
- repo.forEachDocumentType(*vespalib::makeClosure(this, &FieldSetRepo::configureDocumentType));
-}
-FieldSetRepo::~FieldSetRepo() = default;
-
-void
-FieldSetRepo::configureDocumentType(const DocumentType & documentType) {
- for (const auto & entry : documentType.getFieldSets()) {
- vespalib::string fieldSetName(documentType.getName());
- fieldSetName.append(':').append(entry.first);
- _configuredFieldSets[fieldSetName] = parse(_doumentTyperepo, fieldSetName);
- }
-}
-FieldSet::SP
-FieldSetRepo::getFieldSet(vespalib::stringref fieldSetString) const {
- auto found = _configuredFieldSets.find(fieldSetString);
- if (found != _configuredFieldSets.end()) {
- return found->second;
- }
- return parse(_doumentTyperepo, fieldSetString);
-}
-
}
diff --git a/document/src/vespa/document/fieldset/fieldsetrepo.h b/document/src/vespa/document/fieldset/fieldsetrepo.h
index d213230848a..a744aa572e5 100644
--- a/document/src/vespa/document/fieldset/fieldsetrepo.h
+++ b/document/src/vespa/document/fieldset/fieldsetrepo.h
@@ -16,17 +16,10 @@ class DocumentTypeRepo;
class FieldSetRepo
{
public:
- FieldSetRepo(const DocumentTypeRepo& repo);
- ~FieldSetRepo();
+ static FieldSet::UP parse(const DocumentTypeRepo& repo,
+ vespalib::stringref fieldSetString);
- FieldSet::SP getFieldSet(vespalib::stringref fieldSetString) const;
-
- static FieldSet::SP parse(const DocumentTypeRepo& repo, vespalib::stringref fieldSetString);
static vespalib::string serialize(const FieldSet& fs);
-private:
- void configureDocumentType(const DocumentType & documentType);
- const DocumentTypeRepo & _doumentTyperepo;
- vespalib::hash_map<vespalib::string, FieldSet::SP> _configuredFieldSets;
};
}
diff --git a/document/src/vespa/document/fieldset/fieldsets.h b/document/src/vespa/document/fieldset/fieldsets.h
index e71a96e5a7e..9537a5bdf61 100644
--- a/document/src/vespa/document/fieldset/fieldsets.h
+++ b/document/src/vespa/document/fieldset/fieldsets.h
@@ -13,6 +13,7 @@ public:
static constexpr const char * NAME = "[all]";
bool contains(const FieldSet&) const override { return true; }
Type getType() const override { return Type::ALL; }
+ FieldSet* clone() const override { return new AllFields(); }
};
class NoFields final : public FieldSet
@@ -21,6 +22,7 @@ public:
static constexpr const char * NAME = "[none]";
bool contains(const FieldSet& f) const override { return f.getType() == Type::NONE; }
Type getType() const override { return Type::NONE; }
+ FieldSet* clone() const override { return new NoFields(); }
};
class DocIdOnly final : public FieldSet
@@ -31,6 +33,7 @@ public:
return fields.getType() == Type::DOCID || fields.getType() == Type::NONE;
}
Type getType() const override { return Type::DOCID; }
+ FieldSet* clone() const override { return new DocIdOnly(); }
};
class FieldCollection : public FieldSet
@@ -46,8 +49,20 @@ public:
bool contains(const FieldSet& fields) const override;
Type getType() const override { return Type::SET; }
- const DocumentType& getDocumentType() const { return _docType; }
+ /**
+ * @return Returns the document type the collection is associated with.
+ */
+ const DocumentType& getDocumentType() const {
+ return _docType;
+ }
+
+ /**
+ * Returns all the fields contained in this collection.
+ */
const Field::Set& getFields() const { return _set; }
+
+ FieldSet* clone() const override { return new FieldCollection(*this); }
+
uint64_t hash() const { return _hash; }
private:
Field::Set _set;