aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--document/src/vespa/document/fieldvalue/fieldvalue.cpp81
-rw-r--r--vsm/src/tests/docsum/docsum.cpp4
-rw-r--r--vsm/src/vespa/vsm/vsm/docsumfilter.cpp38
-rw-r--r--vsm/src/vespa/vsm/vsm/flattendocsumwriter.cpp9
-rw-r--r--vsm/src/vespa/vsm/vsm/flattendocsumwriter.h4
-rw-r--r--vsm/src/vespa/vsm/vsm/slimefieldwriter.cpp31
-rw-r--r--vsm/src/vespa/vsm/vsm/slimefieldwriter.h4
7 files changed, 90 insertions, 81 deletions
diff --git a/document/src/vespa/document/fieldvalue/fieldvalue.cpp b/document/src/vespa/document/fieldvalue/fieldvalue.cpp
index 037baaffe5f..999747688eb 100644
--- a/document/src/vespa/document/fieldvalue/fieldvalue.cpp
+++ b/document/src/vespa/document/fieldvalue/fieldvalue.cpp
@@ -21,7 +21,9 @@
using vespalib::FieldBase;
using vespalib::nbostream;
+using vespalib::IllegalArgumentException;
using namespace vespalib::xml;
+
namespace document {
using namespace fieldvalue;
@@ -82,7 +84,7 @@ FieldValue::fastCompare(const FieldValue& other) const {
FieldValue&
FieldValue::assign(const FieldValue& value)
{
- throw vespalib::IllegalArgumentException(
+ throw IllegalArgumentException(
"Cannot assign value of type " + value.getDataType()->toString()
+ " to value of type " + value.getDataType()->toString(), VESPA_STRLOC);
}
@@ -106,81 +108,76 @@ FieldValue::toXml(const std::string& indent) const
// Subtypes should implement the conversion functions that make sense
-FieldValue& FieldValue::operator=(vespalib::stringref)
+FieldValue&
+FieldValue::operator=(vespalib::stringref)
{
- throw vespalib::IllegalArgumentException(
- "Cannot assign string to datatype " + getDataType()->toString(),
- VESPA_STRLOC);
+ throw IllegalArgumentException("Cannot assign string to datatype " + getDataType()->toString(), VESPA_STRLOC);
}
-FieldValue& FieldValue::operator=(int32_t)
+FieldValue&
+FieldValue::operator=(int32_t)
{
- throw vespalib::IllegalArgumentException(
- "Cannot assign int to datatype " + getDataType()->toString(),
- VESPA_STRLOC);
+ throw IllegalArgumentException("Cannot assign int to datatype " + getDataType()->toString(), VESPA_STRLOC);
}
-FieldValue& FieldValue::operator=(int64_t)
+FieldValue&
+FieldValue::operator=(int64_t)
{
- throw vespalib::IllegalArgumentException(
- "Cannot assign long to datatype " + getDataType()->toString(),
- VESPA_STRLOC);
+ throw IllegalArgumentException("Cannot assign long to datatype " + getDataType()->toString(), VESPA_STRLOC);
}
-FieldValue& FieldValue::operator=(float)
+FieldValue&
+FieldValue::operator=(float)
{
- throw vespalib::IllegalArgumentException(
- "Cannot assign float to datatype " + getDataType()->toString(),
- VESPA_STRLOC);
+ throw IllegalArgumentException("Cannot assign float to datatype " + getDataType()->toString(), VESPA_STRLOC);
}
-FieldValue& FieldValue::operator=(double)
+FieldValue&
+FieldValue::operator=(double)
{
- throw vespalib::IllegalArgumentException(
- "Cannot assign double to datatype " + getDataType()->toString(),
- VESPA_STRLOC);
+ throw IllegalArgumentException("Cannot assign double to datatype " + getDataType()->toString(), VESPA_STRLOC);
}
-char FieldValue::getAsByte() const
+char
+FieldValue::getAsByte() const
{
- throw InvalidDataTypeConversionException(
- *getDataType(), *DataType::BYTE, VESPA_STRLOC);
+ throw InvalidDataTypeConversionException(*getDataType(), *DataType::BYTE, VESPA_STRLOC);
}
-int32_t FieldValue::getAsInt() const
+int32_t
+FieldValue::getAsInt() const
{
- throw InvalidDataTypeConversionException(
- *getDataType(), *DataType::INT, VESPA_STRLOC);
+ throw InvalidDataTypeConversionException(*getDataType(), *DataType::INT, VESPA_STRLOC);
}
-int64_t FieldValue::getAsLong() const
+int64_t
+FieldValue::getAsLong() const
{
- throw InvalidDataTypeConversionException(
- *getDataType(), *DataType::LONG, VESPA_STRLOC);
+ throw InvalidDataTypeConversionException(*getDataType(), *DataType::LONG, VESPA_STRLOC);
}
-float FieldValue::getAsFloat() const
+float
+FieldValue::getAsFloat() const
{
- throw InvalidDataTypeConversionException(
- *getDataType(), *DataType::FLOAT, VESPA_STRLOC);
+ throw InvalidDataTypeConversionException(*getDataType(), *DataType::FLOAT, VESPA_STRLOC);
}
-double FieldValue::getAsDouble() const
+double
+FieldValue::getAsDouble() const
{
- throw InvalidDataTypeConversionException(
- *getDataType(), *DataType::DOUBLE, VESPA_STRLOC);
+ throw InvalidDataTypeConversionException(*getDataType(), *DataType::DOUBLE, VESPA_STRLOC);
}
-vespalib::string FieldValue::getAsString() const
+vespalib::string
+FieldValue::getAsString() const
{
- throw InvalidDataTypeConversionException(
- *getDataType(), *DataType::STRING, VESPA_STRLOC);
+ throw InvalidDataTypeConversionException(*getDataType(), *DataType::STRING, VESPA_STRLOC);
}
-std::pair<const char*, size_t> FieldValue::getAsRaw() const
+std::pair<const char*, size_t>
+FieldValue::getAsRaw() const
{
- throw InvalidDataTypeConversionException(
- *getDataType(), *DataType::RAW, VESPA_STRLOC);
+ throw InvalidDataTypeConversionException(*getDataType(), *DataType::RAW, VESPA_STRLOC);
}
FieldValue::UP
diff --git a/vsm/src/tests/docsum/docsum.cpp b/vsm/src/tests/docsum/docsum.cpp
index 4409c5f6215..3333b8d7718 100644
--- a/vsm/src/tests/docsum/docsum.cpp
+++ b/vsm/src/tests/docsum/docsum.cpp
@@ -126,6 +126,8 @@ DocsumTest::testFlattenDocsumWriter()
{ // basic tests
TEST_DO(assertFlattenDocsumWriter(StringFieldValue("foo bar"), "foo bar"));
TEST_DO(assertFlattenDocsumWriter(RawFieldValue("foo bar"), "foo bar"));
+ TEST_DO(assertFlattenDocsumWriter(BoolFieldValue(true), "true"));
+ TEST_DO(assertFlattenDocsumWriter(BoolFieldValue(false), "false"));
TEST_DO(assertFlattenDocsumWriter(LongFieldValue(123456789), "123456789"));
TEST_DO(assertFlattenDocsumWriter(createFieldValue(StringList().add("foo bar").add("baz").add(" qux ")),
"foo bar baz qux "));
@@ -160,6 +162,8 @@ DocsumTest::testSlimeFieldWriter()
{
{ // basic types
assertSlimeFieldWriter(LongFieldValue(123456789), "123456789");
+ assertSlimeFieldWriter(BoolFieldValue(true), "true");
+ assertSlimeFieldWriter(BoolFieldValue(false), "false");
assertSlimeFieldWriter(DoubleFieldValue(12.34), "12.34");
assertSlimeFieldWriter(StringFieldValue("foo bar"), "\"foo bar\"");
}
diff --git a/vsm/src/vespa/vsm/vsm/docsumfilter.cpp b/vsm/src/vespa/vsm/vsm/docsumfilter.cpp
index 034c3c57bde..872ccf6acf8 100644
--- a/vsm/src/vespa/vsm/vsm/docsumfilter.cpp
+++ b/vsm/src/vespa/vsm/vsm/docsumfilter.cpp
@@ -93,7 +93,7 @@ public:
const document::FieldValue & fv = c.getValue();
try {
std::pair<const char *, size_t> buf = fv.getAsRaw();
- if (buf.first != NULL) {
+ if (buf.first != nullptr) {
switch (_type) {
case RES_DATA:
_packer.AddData(buf.first, buf.second);
@@ -184,14 +184,14 @@ DocsumFilter::getFieldValue(const DocsumFieldSpec::FieldIdentifier & fieldId,
{
FieldIdT fId = fieldId.getId();
const document::FieldValue * fv = docsum.getField(fId);
- if (fv == NULL) {
- return NULL;
+ if (fv == nullptr) {
+ return nullptr;
}
switch (command) {
case VsmsummaryConfig::Fieldmap::FLATTENJUNIPER:
- if (_snippetModifiers != NULL) {
+ if (_snippetModifiers != nullptr) {
FieldModifier * mod = _snippetModifiers->getModifier(fId);
- if (mod != NULL) {
+ if (mod != nullptr) {
_cachedValue = mod->modify(*fv, fieldId.getPath());
modified = true;
return _cachedValue.get();
@@ -209,9 +209,9 @@ DocsumFilter::DocsumFilter(const DocsumToolsPtr &tools, const IDocSumCache & doc
_tools(tools),
_fields(),
_highestFieldNo(0),
- _packer(tools.get() ? tools->getResultConfig() : NULL),
+ _packer(tools ? tools->getResultConfig() : nullptr),
_flattenWriter(),
- _snippetModifiers(NULL),
+ _snippetModifiers(nullptr),
_cachedValue(),
_emptyFieldPath()
{ }
@@ -223,7 +223,7 @@ void DocsumFilter::init(const FieldMap & fieldMap, const FieldPathMapT & fieldPa
if (_tools.get()) {
const ResultClass *resClass = _tools->getResultClass();
const std::vector<DocsumTools::FieldSpec> & inputSpecs = _tools->getFieldSpecs();
- if (resClass != NULL) {
+ if (resClass != nullptr) {
uint32_t entryCnt = resClass->GetNumEntries();
assert(entryCnt == inputSpecs.size());
for (uint32_t i = 0; i < entryCnt; ++i) {
@@ -266,6 +266,12 @@ DocsumFilter::writeField(const document::FieldValue & fv, const FieldPath & path
uint8_t val = rh.value;
packer.AddByte(val);
break; }
+ case RES_BOOL: {
+ IntResultHandler rh;
+ fv.iterateNested(path, rh);
+ uint8_t val = rh.value;
+ packer.AddByte(val);
+ break; }
case RES_FLOAT: {
FloatResultHandler rh;
fv.iterateNested(path, rh);
@@ -301,9 +307,7 @@ DocsumFilter::writeField(const document::FieldValue & fv, const FieldPath & path
}
break;
default:
- LOG(warning,
- "Unknown docsum field type: %s",
- ResultConfig::GetResTypeName(type));
+ LOG(warning, "Unknown docsum field type: %s", ResultConfig::GetResTypeName(type));
packer.AddEmpty(); // unhandled output type
break;
}
@@ -318,7 +322,7 @@ DocsumFilter::writeSlimeField(const DocsumFieldSpec & fieldSpec,
if (fieldSpec.getCommand() == VsmsummaryConfig::Fieldmap::NONE) {
const DocsumFieldSpec::FieldIdentifier & fieldId = fieldSpec.getOutputField();
const document::FieldValue * fv = docsum.getField(fieldId.getId());
- if (fv != NULL) {
+ if (fv != nullptr) {
LOG(debug, "writeSlimeField: About to write field '%d' as Slime: field value = '%s'",
fieldId.getId(), fv->toString().c_str());
SlimeFieldWriter writer;
@@ -369,7 +373,7 @@ DocsumFilter::writeFlattenField(const DocsumFieldSpec & fieldSpec,
const DocsumFieldSpec::FieldIdentifier & fieldId = inputFields[i];
bool modified = false;
const document::FieldValue * fv = getFieldValue(fieldId, fieldSpec.getCommand(), docsum, modified);
- if (fv != NULL) {
+ if (fv != nullptr) {
LOG(debug, "writeFlattenField: About to flatten field '%d' with field value (%s) '%s'",
fieldId.getId(), modified ? "modified" : "original", fv->toString().c_str());
if (modified) {
@@ -436,8 +440,8 @@ DocsumStoreValue
DocsumFilter::getMappedDocsum(uint32_t id)
{
const ResultClass *resClass = _tools->getResultClass();
- if (resClass == NULL) {
- return DocsumStoreValue(NULL, 0);
+ if (resClass == nullptr) {
+ return DocsumStoreValue(nullptr, 0);
}
const Document & doc = _docsumCache->getDocSum(id);
@@ -452,7 +456,7 @@ DocsumFilter::getMappedDocsum(uint32_t id)
if (it->getInputFields().size() == 1 && it->getCommand() == VsmsummaryConfig::Fieldmap::NONE) {
const DocsumFieldSpec::FieldIdentifier & fieldId = it->getInputFields()[0];
const document::FieldValue * field = doc.getField(fieldId.getId());
- if (field != NULL) {
+ if (field != nullptr) {
writeField(*field, fieldId.getPath(), type, _packer);
} else {
writeEmpty(type, _packer); // void input
@@ -472,7 +476,7 @@ DocsumFilter::getMappedDocsum(uint32_t id)
if (ok) {
return DocsumStoreValue(buf, buflen);
} else {
- return DocsumStoreValue(NULL, 0);
+ return DocsumStoreValue(nullptr, 0);
}
}
diff --git a/vsm/src/vespa/vsm/vsm/flattendocsumwriter.cpp b/vsm/src/vespa/vsm/vsm/flattendocsumwriter.cpp
index 080723e1dbd..5bf50b81c3a 100644
--- a/vsm/src/vespa/vsm/vsm/flattendocsumwriter.cpp
+++ b/vsm/src/vespa/vsm/vsm/flattendocsumwriter.cpp
@@ -18,11 +18,14 @@ FlattenDocsumWriter::onPrimitive(uint32_t, const Content & c)
{
considerSeparator();
const document::FieldValue & fv = c.getValue();
- if (fv.getClass().inherits(document::LiteralFieldValueB::classId)) {
+ const auto & clazz = fv.getClass();
+ if (clazz.inherits(document::LiteralFieldValueB::classId)) {
const document::LiteralFieldValueB & lfv = static_cast<const document::LiteralFieldValueB &>(fv);
vespalib::stringref value = lfv.getValueRef();
_output.put(value.data(), value.size());
- } else if (fv.getClass().inherits(document::NumericFieldValueBase::classId)) {
+ } else if (clazz.inherits(document::NumericFieldValueBase::classId) ||
+ clazz.inherits(document::BoolFieldValue::classId))
+ {
vespalib::string value = fv.getAsString();
_output.put(value.data(), value.size());
} else {
@@ -38,6 +41,6 @@ FlattenDocsumWriter::FlattenDocsumWriter(const vespalib::string & separator) :
_useSeparator(false)
{ }
-FlattenDocsumWriter::~FlattenDocsumWriter() {}
+FlattenDocsumWriter::~FlattenDocsumWriter() = default;
}
diff --git a/vsm/src/vespa/vsm/vsm/flattendocsumwriter.h b/vsm/src/vespa/vsm/vsm/flattendocsumwriter.h
index 826e3f76f75..df04b8a7cdf 100644
--- a/vsm/src/vespa/vsm/vsm/flattendocsumwriter.h
+++ b/vsm/src/vespa/vsm/vsm/flattendocsumwriter.h
@@ -13,9 +13,9 @@ namespace vsm {
**/
class FlattenDocsumWriter : public document::fieldvalue::IteratorHandler {
private:
- CharBuffer _output;
+ CharBuffer _output;
vespalib::string _separator;
- bool _useSeparator;
+ bool _useSeparator;
void considerSeparator();
void onPrimitive(uint32_t, const Content & c) override;
diff --git a/vsm/src/vespa/vsm/vsm/slimefieldwriter.cpp b/vsm/src/vespa/vsm/vsm/slimefieldwriter.cpp
index 772360cef17..0ecfcb1b462 100644
--- a/vsm/src/vespa/vsm/vsm/slimefieldwriter.cpp
+++ b/vsm/src/vespa/vsm/vsm/slimefieldwriter.cpp
@@ -43,13 +43,13 @@ using namespace vespalib::slime::convenience;
namespace vsm {
void
-SlimeFieldWriter::traverseRecursive(const document::FieldValue & fv,
- Inserter &inserter)
+SlimeFieldWriter::traverseRecursive(const document::FieldValue & fv, Inserter &inserter)
{
+ const auto & clazz = fv.getClass();
LOG(debug, "traverseRecursive: class(%s), fieldValue(%s), currentPath(%s)",
- fv.getClass().name(), fv.toString().c_str(), toString(_currPath).c_str());
+ clazz.name(), fv.toString().c_str(), toString(_currPath).c_str());
- if (fv.getClass().inherits(document::CollectionFieldValue::classId)) {
+ if (clazz.inherits(document::CollectionFieldValue::classId)) {
const document::CollectionFieldValue & cfv = static_cast<const document::CollectionFieldValue &>(fv);
if (cfv.inherits(document::ArrayFieldValue::classId)) {
const document::ArrayFieldValue & afv = static_cast<const document::ArrayFieldValue &>(cfv);
@@ -73,11 +73,9 @@ SlimeFieldWriter::traverseRecursive(const document::FieldValue & fv,
o.setLong(wsym, weight);
}
} else {
- LOG(warning, "traverseRecursive: Cannot handle collection field value of type '%s'",
- fv.getClass().name());
+ LOG(warning, "traverseRecursive: Cannot handle collection field value of type '%s'", clazz.name());
}
-
- } else if (fv.getClass().inherits(document::MapFieldValue::classId)) {
+ } else if (clazz.inherits(document::MapFieldValue::classId)) {
const document::MapFieldValue & mfv = static_cast<const document::MapFieldValue &>(fv);
Cursor &a = inserter.insertArray();
Symbol keysym = a.resolve("key");
@@ -91,7 +89,7 @@ SlimeFieldWriter::traverseRecursive(const document::FieldValue & fv,
traverseRecursive(*entry.second, vi);
_currPath.pop_back();
}
- } else if (fv.getClass().inherits(document::StructuredFieldValue::classId)) {
+ } else if (clazz.inherits(document::StructuredFieldValue::classId)) {
const document::StructuredFieldValue & sfv = static_cast<const document::StructuredFieldValue &>(fv);
Cursor &o = inserter.insertObject();
for (const document::Field & entry : sfv) {
@@ -105,10 +103,10 @@ SlimeFieldWriter::traverseRecursive(const document::FieldValue & fv,
}
}
} else {
- if (fv.getClass().inherits(document::LiteralFieldValueB::classId)) {
+ if (clazz.inherits(document::LiteralFieldValueB::classId)) {
const document::LiteralFieldValueB & lfv = static_cast<const document::LiteralFieldValueB &>(fv);
inserter.insertString(lfv.getValueRef());
- } else if (fv.getClass().inherits(document::NumericFieldValueBase::classId)) {
+ } else if (clazz.inherits(document::NumericFieldValueBase::classId)) {
switch (fv.getDataType()->getId()) {
case document::DataType::T_BYTE:
case document::DataType::T_SHORT:
@@ -125,6 +123,9 @@ SlimeFieldWriter::traverseRecursive(const document::FieldValue & fv,
default:
inserter.insertString(fv.getAsString());
}
+ } else if (clazz.inherits(document::BoolFieldValue::classId)) {
+ const auto & bfv = static_cast<const document::BoolFieldValue &>(fv);
+ inserter.insertBool(bfv.getValue());
} else {
inserter.insertString(fv.toString());
}
@@ -134,7 +135,7 @@ SlimeFieldWriter::traverseRecursive(const document::FieldValue & fv,
bool
SlimeFieldWriter::explorePath(vespalib::stringref candidate)
{
- if (_inputFields == NULL) {
+ if (_inputFields == nullptr) {
return true;
}
// find out if we should explore the current path
@@ -161,18 +162,18 @@ SlimeFieldWriter::explorePath(vespalib::stringref candidate)
SlimeFieldWriter::SlimeFieldWriter() :
_rbuf(4096),
_slime(),
- _inputFields(NULL),
+ _inputFields(nullptr),
_currPath()
{
}
-SlimeFieldWriter::~SlimeFieldWriter() {}
+SlimeFieldWriter::~SlimeFieldWriter() = default;
void
SlimeFieldWriter::convert(const document::FieldValue & fv)
{
if (LOG_WOULD_LOG(debug)) {
- if (_inputFields != NULL) {
+ if (_inputFields != nullptr) {
for (size_t i = 0; i < _inputFields->size(); ++i) {
LOG(debug, "write: input field path [%zd] '%s'", i, toString((*_inputFields)[i].getPath()).c_str());
}
diff --git a/vsm/src/vespa/vsm/vsm/slimefieldwriter.h b/vsm/src/vespa/vsm/vsm/slimefieldwriter.h
index 505c2a46377..aea1f47bca7 100644
--- a/vsm/src/vespa/vsm/vsm/slimefieldwriter.h
+++ b/vsm/src/vespa/vsm/vsm/slimefieldwriter.h
@@ -17,7 +17,7 @@ namespace vsm {
class SlimeFieldWriter
{
private:
- search::RawBuf _rbuf;
+ search::RawBuf _rbuf;
vespalib::Slime _slime;
const DocsumFieldSpec::FieldIdentifierVector * _inputFields;
std::vector<vespalib::string> _currPath;
@@ -49,7 +49,7 @@ public:
void clear() {
_rbuf.Reuse();
- _inputFields = NULL;
+ _inputFields = nullptr;
_currPath.clear();
}
};