summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@oath.com>2018-08-06 11:57:40 +0000
committerTor Egge <Tor.Egge@oath.com>2018-08-06 11:57:40 +0000
commit4555f4d71dcb13d4fb7bfb361b2d04bde9f12e73 (patch)
treeb02de2d892a70e9bb3dad748362ddec4ae74f13a /document
parent62afbc82f21f1ffe0ea56d7f9d661df5497bbbe2 (diff)
Consider parse error as invalid selection expression.
Diffstat (limited to 'document')
-rw-r--r--document/src/tests/fieldpathupdatetestcase.cpp13
-rw-r--r--document/src/vespa/document/update/fieldpathupdate.cpp20
2 files changed, 26 insertions, 7 deletions
diff --git a/document/src/tests/fieldpathupdatetestcase.cpp b/document/src/tests/fieldpathupdatetestcase.cpp
index fb3ba3f7e40..f5db5831912 100644
--- a/document/src/tests/fieldpathupdatetestcase.cpp
+++ b/document/src/tests/fieldpathupdatetestcase.cpp
@@ -33,6 +33,7 @@ struct FieldPathUpdateTestCase : public CppUnit::TestFixture {
void tearDown() override;
void testWhereClause();
+ void testBrokenWhereClause();
void testNoIterateMapValues();
void testRemoveField();
void testApplyRemoveEntireListField();
@@ -73,6 +74,7 @@ struct FieldPathUpdateTestCase : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(FieldPathUpdateTestCase);
CPPUNIT_TEST(testWhereClause);
+ CPPUNIT_TEST(testBrokenWhereClause);
CPPUNIT_TEST(testNoIterateMapValues);
CPPUNIT_TEST(testRemoveField);
CPPUNIT_TEST(testApplyRemoveEntireListField);
@@ -356,6 +358,17 @@ FieldPathUpdateTestCase::testWhereClause()
}
void
+FieldPathUpdateTestCase::testBrokenWhereClause()
+{
+ DocumentTypeRepo repo(getRepoConfig());
+ Document::UP doc(createTestDocument(repo));
+ std::string where = "l1s1.structmap.value.smap{$x} == \"dicaprio\"";
+ TestFieldPathUpdate update("l1s1.structmap.value.smap{$x}", where);
+ update.applyTo(*doc);
+ CPPUNIT_ASSERT_EQUAL(std::string(""), update._str);
+}
+
+void
FieldPathUpdateTestCase::testNoIterateMapValues()
{
DocumentTypeRepo repo(getRepoConfig());
diff --git a/document/src/vespa/document/update/fieldpathupdate.cpp b/document/src/vespa/document/update/fieldpathupdate.cpp
index e7d5824b6e0..1af648d343e 100644
--- a/document/src/vespa/document/update/fieldpathupdate.cpp
+++ b/document/src/vespa/document/update/fieldpathupdate.cpp
@@ -4,6 +4,7 @@
#include <vespa/document/fieldvalue/document.h>
#include <vespa/document/fieldvalue/iteratorhandler.h>
#include <vespa/document/select/parser.h>
+#include <vespa/document/select/parsing_failed_exception.h>
#include <vespa/document/util/serializableexceptions.h>
#include <vespa/vespalib/objects/nbostream.h>
#include <ostream>
@@ -11,6 +12,7 @@
#include <vespa/log/log.h>
LOG_SETUP(".document.update.fieldpathupdate");
+using document::select::ParsingFailedException;
using vespalib::make_string;
using vespalib::IllegalArgumentException;
@@ -64,14 +66,18 @@ FieldPathUpdate::applyTo(Document& doc) const
if (_originalWhereClause.empty()) {
doc.iterateNested(path, *handler);
} else {
- std::unique_ptr<select::Node> whereClause = parseDocumentSelection(_originalWhereClause, *doc.getRepo());
- select::ResultList results = whereClause->contains(doc);
- for (select::ResultList::const_iterator i = results.begin(); i != results.end(); ++i) {
- LOG(spam, "vars = %s", handler->getVariables().toString().c_str());
- if (*i->second == select::Result::True) {
- handler->setVariables(i->first);
- doc.iterateNested(path, *handler);
+ try {
+ std::unique_ptr<select::Node> whereClause = parseDocumentSelection(_originalWhereClause, *doc.getRepo());
+ select::ResultList results = whereClause->contains(doc);
+ for (select::ResultList::const_iterator i = results.begin(); i != results.end(); ++i) {
+ LOG(spam, "vars = %s", handler->getVariables().toString().c_str());
+ if (*i->second == select::Result::True) {
+ handler->setVariables(i->first);
+ doc.iterateNested(path, *handler);
+ }
}
+ } catch (const ParsingFailedException &e) {
+ LOG(warning, "Failed to parse selection for field path update: %s", e.getMessage().c_str());
}
}
}