diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-10-18 22:46:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-18 22:46:54 +0200 |
commit | cec0bc17d431f4a96ce470d691b0471a79112967 (patch) | |
tree | f5374902ef59d1bae07385896b0761d3e350c8b4 | |
parent | c967345262c44804d01938608c6f84a8bdee34f5 (diff) | |
parent | ab393107b2ec5ddbbbba1a92616bfb375dd9d2c4 (diff) |
Merge pull request #3815 from vespa-engine/geirst/do-not-require-fields-in-field-sets-to-be-part-of-doc-type
Do not require that fields in a field set must be part of the documen…
-rw-r--r-- | document/src/tests/documenttypetestcase.cpp | 30 | ||||
-rw-r--r-- | document/src/vespa/document/datatype/documenttype.cpp | 11 |
2 files changed, 19 insertions, 22 deletions
diff --git a/document/src/tests/documenttypetestcase.cpp b/document/src/tests/documenttypetestcase.cpp index dfca4a67e31..311a841e75e 100644 --- a/document/src/tests/documenttypetestcase.cpp +++ b/document/src/tests/documenttypetestcase.cpp @@ -21,7 +21,7 @@ struct DocumentTypeTest : public CppUnit::TestFixture { void testSetGet(); void testHeaderContent(); - void testFieldSet(); + void testFieldSetCanContainFieldsNotInDocType(); void testInheritance(); void testInheritanceConfig(); void testMultipleInheritance(); @@ -29,7 +29,7 @@ struct DocumentTypeTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE( DocumentTypeTest); CPPUNIT_TEST(testSetGet); - CPPUNIT_TEST(testFieldSet); + CPPUNIT_TEST(testFieldSetCanContainFieldsNotInDocType); CPPUNIT_TEST(testInheritance); CPPUNIT_TEST(testInheritanceConfig); CPPUNIT_TEST(testMultipleInheritance); @@ -162,20 +162,28 @@ void DocumentTypeTest::testMultipleInheritance() doc.getValue(doc.getField("tmp"))->getAsString()); } -void DocumentTypeTest::testFieldSet() -{ +namespace { + +bool containsField(const DocumentType::FieldSet &fieldSet, const vespalib::string &field) { + return fieldSet.getFields().find(field) != fieldSet.getFields().end(); +} + +} + +void DocumentTypeTest::testFieldSetCanContainFieldsNotInDocType() { DocumentType docType("test1"); docType.addField(Field("stringattr", 3, *DataType::STRING, false)); docType.addField(Field("nalle", 0, *DataType::INT, false)); - DocumentType::FieldSet::Fields tmp; - tmp.insert("nalle"); - tmp.insert("nulle"); - try { + { + DocumentType::FieldSet::Fields tmp; + tmp.insert("nalle"); + tmp.insert("nulle"); docType.addFieldSet("a", tmp); - CPPUNIT_ASSERT(false); - } catch (const vespalib::IllegalArgumentException & e) { - CPPUNIT_ASSERT_EQUAL(vespalib::string("Fieldset 'a': No field with name 'nulle' in document type 'test1'."), e.getMessage()); } + auto fieldSet = docType.getFieldSet("a"); + CPPUNIT_ASSERT_EQUAL((size_t)2, fieldSet->getFields().size()); + CPPUNIT_ASSERT(containsField(*fieldSet, "nalle")); + CPPUNIT_ASSERT(containsField(*fieldSet, "nulle")); } void DocumentTypeTest::testInheritance() diff --git a/document/src/vespa/document/datatype/documenttype.cpp b/document/src/vespa/document/datatype/documenttype.cpp index 61bfba3b028..c7eaf42b50b 100644 --- a/document/src/vespa/document/datatype/documenttype.cpp +++ b/document/src/vespa/document/datatype/documenttype.cpp @@ -75,17 +75,6 @@ DocumentType::~DocumentType() DocumentType & DocumentType::addFieldSet(const vespalib::string & name, const FieldSet::Fields & fields) { - for (FieldSet::Fields::const_iterator it(fields.begin()), mt(fields.end()); it != mt; it++) { - if ( ! _fields->hasField(*it) ) { - FieldPath fieldPath; - try { - _fields->buildFieldPath(fieldPath, *it); - } catch (FieldNotFoundException & e) { - throw IllegalArgumentException("Fieldset '" + name + "': No field with name '" + *it + - "' in document type '" + getName() + "'.", VESPA_STRLOC); - } - } - } _fieldSets[name] = FieldSet(name, fields); return *this; } |