diff options
author | Geir Storli <geirst@yahoo-inc.com> | 2016-10-27 14:16:45 +0200 |
---|---|---|
committer | Geir Storli <geirst@yahoo-inc.com> | 2016-10-27 14:16:45 +0200 |
commit | 883bc687b3aaa1ae34247c995bd35e22163bcc6b (patch) | |
tree | b83191f7314994e061e75d47dc63b553c78abe63 /searchcore | |
parent | 94c0eee78ebb755ab867bd7c4be7c020542946f0 (diff) |
Add validation of tensor attribute tensor type changes.
Diffstat (limited to 'searchcore')
3 files changed, 50 insertions, 12 deletions
diff --git a/searchcore/src/tests/proton/documentdb/configvalidator/configvalidator_test.cpp b/searchcore/src/tests/proton/documentdb/configvalidator/configvalidator_test.cpp index cbcc97bdf68..7957600195d 100644 --- a/searchcore/src/tests/proton/documentdb/configvalidator/configvalidator_test.cpp +++ b/searchcore/src/tests/proton/documentdb/configvalidator/configvalidator_test.cpp @@ -23,6 +23,7 @@ const ConfigValidator::ResultType AAA = ConfigValidator::ATTRIBUTE_ASPECT_ADDED; const ConfigValidator::ResultType AAR = ConfigValidator::ATTRIBUTE_ASPECT_REMOVED; const ConfigValidator::ResultType AFAA = ConfigValidator::ATTRIBUTE_FAST_ACCESS_ADDED; const ConfigValidator::ResultType AFAR = ConfigValidator::ATTRIBUTE_FAST_ACCESS_REMOVED; +const ConfigValidator::ResultType ATTC = ConfigValidator::ATTRIBUTE_TENSOR_TYPE_CHANGED; enum FType { INDEX, @@ -325,24 +326,39 @@ createAttribute(const vespalib::string &name, bool fastAccess) return attr; } -TEST("require that adding attribute fast-access is discovered") +AttributesConfigBuilder +createAttributesConfig(const AttributesConfigBuilder::Attribute &attribute) { - AttributesConfigBuilder oldCfg; - oldCfg.attribute.push_back(createAttribute("a1", false)); - AttributesConfigBuilder newCfg; - newCfg.attribute.push_back(createAttribute("a1", true)); + AttributesConfigBuilder result; + result.attribute.push_back(attribute); + return result; +} - EXPECT_EQUAL(AFAA, checkAttribute(newCfg, oldCfg)); +TEST("require that adding attribute fast-access is discovered") +{ + EXPECT_EQUAL(AFAA, checkAttribute(createAttributesConfig(createAttribute("a1", true)), + createAttributesConfig(createAttribute("a1", false)))); } TEST("require that removing attribute fast-access is discovered") { - AttributesConfigBuilder oldCfg; - oldCfg.attribute.push_back(createAttribute("a1", true)); - AttributesConfigBuilder newCfg; - newCfg.attribute.push_back(createAttribute("a1", false)); + EXPECT_EQUAL(AFAR, checkAttribute(createAttributesConfig(createAttribute("a1", false)), + createAttributesConfig(createAttribute("a1", true)))); +} - EXPECT_EQUAL(AFAR, checkAttribute(newCfg, oldCfg)); +AttributesConfigBuilder::Attribute +createTensorAttribute(const vespalib::string &name, const vespalib::string &tensorType) +{ + AttributesConfigBuilder::Attribute attr; + attr.name = name; + attr.tensortype = tensorType; + return attr; +} + +TEST("require that changing attribute tensor type is discovered") +{ + EXPECT_EQUAL(ATTC, checkAttribute(createAttributesConfig(createTensorAttribute("a1", "tensor(x[10])")), + createAttributesConfig(createTensorAttribute("a1", "tensor(x[11])")))); } TEST_MAIN() diff --git a/searchcore/src/vespa/searchcore/proton/server/attribute_config_validator.cpp b/searchcore/src/vespa/searchcore/proton/server/attribute_config_validator.cpp index 666a40cac9c..0219cabba2a 100644 --- a/searchcore/src/vespa/searchcore/proton/server/attribute_config_validator.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/attribute_config_validator.cpp @@ -4,10 +4,12 @@ #include <vespa/log/log.h> LOG_SETUP(".proton.server.attribute_config_validator"); #include "attribute_config_validator.h" +#include <vespa/vespalib/eval/value_type.h> #include <vespa/vespalib/util/stringfmt.h> using vespa::config::search::AttributesConfig; using vespalib::make_string; +using vespalib::eval::ValueType; namespace proton { @@ -49,6 +51,24 @@ checkFastAccessRemoved(const AttributesConfig &newCfg, return checkFastAccess(oldCfg, newCfg, CV::ATTRIBUTE_FAST_ACCESS_REMOVED, "remove"); } +CV::Result +checkTensorTypeChanged(const AttributesConfig &newCfg, + const AttributesConfig &oldCfg) +{ + for (const auto &newAttr : newCfg.attribute) { + for (const auto &oldAttr : oldCfg.attribute) { + if ((newAttr.name == oldAttr.name) && + (ValueType::from_spec(newAttr.tensortype) != ValueType::from_spec(oldAttr.tensortype))) + { + return CV::Result(CV::ATTRIBUTE_TENSOR_TYPE_CHANGED, + make_string("Tensor type has changed from '%s' -> '%s' for attribute '%s'", + oldAttr.tensortype.c_str(), newAttr.tensortype.c_str(), newAttr.name.c_str())); + } + } + } + return CV::Result(); +} + } CV::Result @@ -58,6 +78,7 @@ AttributeConfigValidator::validate(const AttributesConfig &newCfg, CV::Result res; if (!(res = checkFastAccessAdded(newCfg, oldCfg)).ok()) return res; if (!(res = checkFastAccessRemoved(newCfg, oldCfg)).ok()) return res; + if (!(res = checkTensorTypeChanged(newCfg, oldCfg)).ok()) return res; return CV::Result(); } diff --git a/searchcore/src/vespa/searchcore/proton/server/configvalidator.h b/searchcore/src/vespa/searchcore/proton/server/configvalidator.h index 5e700234041..c4a189dd756 100644 --- a/searchcore/src/vespa/searchcore/proton/server/configvalidator.h +++ b/searchcore/src/vespa/searchcore/proton/server/configvalidator.h @@ -26,7 +26,8 @@ public: ATTRIBUTE_ASPECT_ADDED, ATTRIBUTE_ASPECT_REMOVED, ATTRIBUTE_FAST_ACCESS_ADDED, - ATTRIBUTE_FAST_ACCESS_REMOVED + ATTRIBUTE_FAST_ACCESS_REMOVED, + ATTRIBUTE_TENSOR_TYPE_CHANGED }; class Result |