summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-03-16 17:36:04 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2022-03-16 18:06:45 +0000
commitcea11eaf40659b879d143f99eee2f6b78e427761 (patch)
tree88a81f4697a51d889af52daf1b581eeb3ee6385e /searchlib
parentfd26131762bf938c033178637604df97076ffcdf (diff)
Avoid requiring identifiable for FieldValue
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/vespa/searchlib/attribute/attributevector.hpp19
-rw-r--r--searchlib/src/vespa/searchlib/expression/documentfieldnode.cpp53
-rw-r--r--searchlib/src/vespa/searchlib/memoryindex/field_inverter.cpp23
-rw-r--r--searchlib/src/vespa/searchlib/memoryindex/url_field_inverter.cpp47
4 files changed, 59 insertions, 83 deletions
diff --git a/searchlib/src/vespa/searchlib/attribute/attributevector.hpp b/searchlib/src/vespa/searchlib/attribute/attributevector.hpp
index 623e10ef052..c75f7788467 100644
--- a/searchlib/src/vespa/searchlib/attribute/attributevector.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/attributevector.hpp
@@ -10,23 +10,6 @@
namespace search {
-template <typename T>
-inline bool myIsNan(T v) { (void)v; return false; }
-
-template <>
-inline bool
-myIsNan<float>(float v)
-{
- return std::isnan(v);
-}
-
-template <>
-inline bool
-myIsNan<double>(double v)
-{
- return std::isnan(v);
-}
-
template<typename T>
bool
AttributeVector::adjustWeight(ChangeVectorT< ChangeTemplate<T> > & changes, DocId doc, const T & v,
@@ -70,7 +53,7 @@ AttributeVector::adjustWeight(ChangeVectorT< ChangeTemplate<T> >& changes, DocId
size_t oldSz(changes.size());
if (wu.hasValue()) {
const FieldValue &wv = wu.getValue();
- if (wv.inherits(document::IntFieldValue::classId)) {
+ if (wv.isA(FieldValue::Type::INT)) {
changes.push_back(ChangeTemplate<T>(ChangeBase::SETWEIGHT, doc, v, wv.getAsInt()));
} else {
retval = false;
diff --git a/searchlib/src/vespa/searchlib/expression/documentfieldnode.cpp b/searchlib/src/vespa/searchlib/expression/documentfieldnode.cpp
index df3d2e5b19b..d0602a89089 100644
--- a/searchlib/src/vespa/searchlib/expression/documentfieldnode.cpp
+++ b/searchlib/src/vespa/searchlib/expression/documentfieldnode.cpp
@@ -6,6 +6,7 @@
#include <vespa/document/datatype/documenttype.h>
#include <vespa/vespalib/encoding/base64.h>
#include <vespa/vespalib/locale/c.h>
+#include <vespa/vespalib/util/classname.h>
#include <vespa/log/log.h>
LOG_SETUP(".searchlib.documentfieldnode");
@@ -29,11 +30,12 @@ DocumentFieldNode::DocumentFieldNode(const DocumentFieldNode & rhs) :
_fieldPath(rhs._fieldPath),
_value(rhs._value),
_fieldName(rhs._fieldName),
- _doc(NULL)
+ _doc(nullptr)
{
}
-DocumentFieldNode & DocumentFieldNode::operator = (const DocumentFieldNode & rhs)
+DocumentFieldNode &
+DocumentFieldNode::operator = (const DocumentFieldNode & rhs)
{
if (this != &rhs) {
DocumentAccessorNode::operator=(rhs);
@@ -49,12 +51,11 @@ std::unique_ptr<ResultNode>
deduceResultNode(vespalib::stringref fieldName, const FieldValue & fv, bool preserveAccurateTypes, bool nestedMultiValue)
{
std::unique_ptr<ResultNode> value;
- const Identifiable::RuntimeClass & cInfo = fv.getClass();
- if (cInfo.inherits(ByteFieldValue::classId) || cInfo.inherits(IntFieldValue::classId) || cInfo.inherits(LongFieldValue::classId)) {
+ if (fv.isA(FieldValue::Type::BYTE) || fv.isA(FieldValue::Type::INT) || fv.isA(FieldValue::Type::LONG)) {
if (preserveAccurateTypes) {
- if (cInfo.inherits(ByteFieldValue::classId)) {
+ if (fv.isA(FieldValue::Type::BYTE)) {
value.reset(nestedMultiValue ? static_cast<ResultNode *>(new Int8ResultNodeVector()) : static_cast<ResultNode *>(new Int8ResultNode()));
- } else if (cInfo.inherits(IntFieldValue::classId)) {
+ } else if (fv.isA(FieldValue::Type::INT)) {
value.reset(nestedMultiValue ? static_cast<ResultNode *>(new Int32ResultNodeVector()) : static_cast<ResultNode *>(new Int32ResultNode()));
} else {
value.reset(nestedMultiValue ? static_cast<ResultNode *>(new Int64ResultNodeVector()) : static_cast<ResultNode *>(new Int64ResultNode()));
@@ -62,22 +63,20 @@ deduceResultNode(vespalib::stringref fieldName, const FieldValue & fv, bool pres
} else {
value.reset(nestedMultiValue ? static_cast<ResultNode *>(new Int64ResultNodeVector()) : static_cast<ResultNode *>(new Int64ResultNode()));
}
- } else if (cInfo.inherits(FloatFieldValue::classId) || cInfo.inherits(DoubleFieldValue::classId)) {
+ } else if (fv.isA(FieldValue::Type::FLOAT) || fv.isA(FieldValue::Type::DOUBLE)) {
value.reset(nestedMultiValue ? static_cast<ResultNode *>(new FloatResultNodeVector()) : static_cast<ResultNode *>(new FloatResultNode()));
- } else if (cInfo.inherits(BoolFieldValue::classId)) {
+ } else if (fv.isA(FieldValue::Type::BOOL)) {
value.reset(nestedMultiValue ? static_cast<ResultNode *>(new BoolResultNodeVector()) : static_cast<ResultNode *>(new BoolResultNode()));
- } else if (cInfo.inherits(StringFieldValue::classId)) {
+ } else if (fv.isA(FieldValue::Type::STRING)) {
value.reset(nestedMultiValue ? static_cast<ResultNode *>(new StringResultNodeVector()) : static_cast<ResultNode *>(new StringResultNode()));
- } else if (cInfo.inherits(RawFieldValue::classId)) {
+ } else if (fv.isA(FieldValue::Type::RAW)) {
value.reset(nestedMultiValue ? static_cast<ResultNode *>(new RawResultNodeVector()) : static_cast<ResultNode *>(new RawResultNode()));
- } else if (cInfo.inherits(CollectionFieldValue::classId) || cInfo.inherits(MapFieldValue::classId)) {
- if (cInfo.inherits(CollectionFieldValue::classId)) {
+ } else if (fv.isCollection() || fv.isA(FieldValue::Type::MAP)) {
+ if (fv.isCollection()) {
value = deduceResultNode(fieldName, *static_cast<const CollectionFieldValue &>(fv).createNested(), preserveAccurateTypes, nestedMultiValue);
- } else if (cInfo.inherits(MapFieldValue::classId)) {
- value = deduceResultNode(fieldName, *static_cast<const MapFieldValue &>(fv).createValue(), preserveAccurateTypes, nestedMultiValue);
} else {
- throw std::runtime_error(make_string("Can not deduce correct resultclass for documentfield '%s' in based on class '%s'",
- vespalib::string(fieldName).c_str(), cInfo.name()));
+ assert(fv.isA(FieldValue::Type::MAP));
+ value = deduceResultNode(fieldName, *static_cast<const MapFieldValue &>(fv).createValue(), preserveAccurateTypes, nestedMultiValue);
}
const Identifiable::RuntimeClass & rInfo = value->getClass();
if (rInfo.inherits(ResultNodeVector::classId)) {
@@ -100,16 +99,17 @@ deduceResultNode(vespalib::stringref fieldName, const FieldValue & fv, bool pres
value.reset(new RawResultNodeVector());
} else {
throw std::runtime_error(make_string("Can not deduce correct resultclass for documentfield '%s' in based on class '%s'. It nests down to %s which is not expected",
- vespalib::string(fieldName).c_str(), cInfo.name(), rInfo.name()));
+ vespalib::string(fieldName).c_str(), vespalib::getClassName(fv).c_str(), rInfo.name()));
}
} else {
throw std::runtime_error(make_string("Can not deduce correct resultclass for documentfield '%s' in based on class '%s'",
- vespalib::string(fieldName).c_str(), cInfo.name()));
+ vespalib::string(fieldName).c_str(), vespalib::getClassName(fv).c_str()));
}
return value;
}
-void DocumentFieldNode::onPrepare(bool preserveAccurateTypes)
+void
+DocumentFieldNode::onPrepare(bool preserveAccurateTypes)
{
LOG(debug, "DocumentFieldNode::onPrepare(this=%p)", this);
@@ -118,8 +118,8 @@ void DocumentFieldNode::onPrepare(bool preserveAccurateTypes)
for(document::FieldPath::const_iterator it(_fieldPath.begin()), mt(_fieldPath.end()); !nestedMultiValue && (it != mt); it++) {
const FieldPathEntry & fpe = **it;
if (fpe.getType() == document::FieldPathEntry::STRUCT_FIELD) {
- const vespalib::Identifiable::RuntimeClass & cInfo(fpe.getFieldValueToSet().getClass());
- nestedMultiValue = cInfo.inherits(CollectionFieldValue::classId) || cInfo.inherits(MapFieldValue::classId);
+ const FieldValue & fv = fpe.getFieldValueToSet();
+ nestedMultiValue = fv.isCollection() || fv.isA(FieldValue::Type::MAP);
}
}
const document::FieldPathEntry & endOfPath(_fieldPath.back());
@@ -127,9 +127,9 @@ void DocumentFieldNode::onPrepare(bool preserveAccurateTypes)
const FieldValue& fv = endOfPath.getFieldValueToSet();
_value.reset(deduceResultNode(_fieldName, fv, preserveAccurateTypes, nestedMultiValue).release());
if (_value->inherits(ResultNodeVector::classId)) {
- _handler.reset(new MultiHandler(static_cast<ResultNodeVector &>(*_value)));
+ _handler = std::make_unique<MultiHandler>(static_cast<ResultNodeVector &>(*_value));
} else {
- _handler.reset(new SingleHandler(*_value));
+ _handler = std::make_unique<SingleHandler>(*_value);
}
} else {
if (endOfPath.getDataType().isStructured()) {
@@ -222,10 +222,10 @@ DocumentFieldNode::Handler::onCollectionStart(const Content & c)
{
const document::FieldValue & fv = c.getValue();
LOG(spam, "onCollectionStart: field value '%s'", fv.toString().c_str());
- if (fv.inherits(document::ArrayFieldValue::classId)) {
+ if (fv.isA(FieldValue::Type::ARRAY)) {
const document::ArrayFieldValue & afv = static_cast<const document::ArrayFieldValue &>(fv);
LOG(spam, "onCollectionStart: Array size = '%zu'", afv.size());
- } else if (fv.inherits(document::WeightedSetFieldValue::classId)) {
+ } else if (fv.isA(FieldValue::Type::WSET)) {
const document::WeightedSetFieldValue & wsfv = static_cast<const document::WeightedSetFieldValue &>(fv);
LOG(spam, "onCollectionStart: WeightedSet size = '%zu'", wsfv.size());
}
@@ -253,9 +253,6 @@ DocumentFieldNode::visitMembers(vespalib::ObjectVisitor &visitor) const
{
visit(visitor, "fieldName", _fieldName);
visit(visitor, "value", _value);
- visitor.openStruct("fieldPath", "FieldPath");
- _fieldPath.visitMembers(visitor);
- visitor.closeStruct();
}
class String2ResultNode : public ResultNode
diff --git a/searchlib/src/vespa/searchlib/memoryindex/field_inverter.cpp b/searchlib/src/vespa/searchlib/memoryindex/field_inverter.cpp
index a443e994559..d79465885f1 100644
--- a/searchlib/src/vespa/searchlib/memoryindex/field_inverter.cpp
+++ b/searchlib/src/vespa/searchlib/memoryindex/field_inverter.cpp
@@ -18,6 +18,7 @@
#include <vespa/searchlib/util/url.h>
#include <vespa/vespalib/text/utf8.h>
#include <vespa/vespalib/util/stringfmt.h>
+#include <vespa/vespalib/util/classname.h>
#include <vespa/vespalib/stllike/hash_map.hpp>
#include <stdexcept>
@@ -271,7 +272,7 @@ FieldInverter::saveWord(const vespalib::stringref word)
uint32_t
FieldInverter::saveWord(const document::FieldValue &fv)
{
- assert(fv.getClass().id() == StringFieldValue::classId);
+ assert(fv.isA(FieldValue::Type::STRING));
using RawRef = std::pair<const char*, size_t>;
RawRef sRef = fv.getAsRaw();
return saveWord(vespalib::stringref(sRef.first, sRef.second));
@@ -303,8 +304,7 @@ FieldInverter::endDoc()
}
_calculator.add_field_length(field_length);
uint32_t newPosSize = static_cast<uint32_t>(_positions.size());
- _pendingDocs.insert({ _docId,
- { _oldPosSize, newPosSize - _oldPosSize } });
+ _pendingDocs.insert({ _docId, { _oldPosSize, newPosSize - _oldPosSize } });
_docId = 0;
_oldPosSize = newPosSize;
}
@@ -324,7 +324,7 @@ FieldInverter::processNormalDocArrayTextField(const ArrayFieldValue &field)
uint32_t ele = field.size();
for (;el < ele; ++el) {
const FieldValue &elfv = field[el];
- assert(elfv.getClass().id() == StringFieldValue::classId);
+ assert(elfv.isA(FieldValue::Type::STRING));
const auto &element = static_cast<const StringFieldValue &>(elfv);
startElement(1);
processAnnotations(element);
@@ -338,8 +338,8 @@ FieldInverter::processNormalDocWeightedSetTextField(const WeightedSetFieldValue
for (const auto & el : field) {
const FieldValue &key = *el.first;
const FieldValue &xweight = *el.second;
- assert(key.getClass().id() == StringFieldValue::classId);
- assert(xweight.getClass().id() == IntFieldValue::classId);
+ assert(key.isA(FieldValue::Type::STRING));
+ assert(xweight.isA(FieldValue::Type::INT));
const auto &element = static_cast<const StringFieldValue &>(key);
int32_t weight = xweight.getAsInt();
startElement(weight);
@@ -457,18 +457,17 @@ FieldInverter::startDoc(uint32_t docId) {
void
FieldInverter::invertNormalDocTextField(const FieldValue &val)
{
- const vespalib::Identifiable::RuntimeClass & cInfo(val.getClass());
const Schema::IndexField &field = _schema.getIndexField(_fieldId);
switch (field.getCollectionType()) {
case CollectionType::SINGLE:
- if (cInfo.id() == StringFieldValue::classId) {
+ if (val.isA(FieldValue::Type::STRING)) {
processNormalDocTextField(static_cast<const StringFieldValue &>(val));
} else {
throw std::runtime_error(make_string("Expected DataType::STRING, got '%s'", val.getDataType()->getName().c_str()));
}
break;
case CollectionType::WEIGHTEDSET:
- if (cInfo.id() == WeightedSetFieldValue::classId) {
+ if (val.isA(FieldValue::Type::WSET)) {
const auto &wset = static_cast<const WeightedSetFieldValue &>(val);
if (wset.getNestedType() == *DataType::STRING) {
processNormalDocWeightedSetTextField(wset);
@@ -476,11 +475,11 @@ FieldInverter::invertNormalDocTextField(const FieldValue &val)
throw std::runtime_error(make_string("Expected DataType::STRING, got '%s'", wset.getNestedType().getName().c_str()));
}
} else {
- throw std::runtime_error(make_string("Expected weighted set, got '%s'", cInfo.name()));
+ throw std::runtime_error(make_string("Expected weighted set, got '%s'", vespalib::getClassName(val).c_str()));
}
break;
case CollectionType::ARRAY:
- if (cInfo.id() == ArrayFieldValue::classId) {
+ if (val.isA(FieldValue::Type::ARRAY)) {
const auto &arr = static_cast<const ArrayFieldValue&>(val);
if (arr.getNestedType() == *DataType::STRING) {
processNormalDocArrayTextField(arr);
@@ -488,7 +487,7 @@ FieldInverter::invertNormalDocTextField(const FieldValue &val)
throw std::runtime_error(make_string("Expected DataType::STRING, got '%s'", arr.getNestedType().getName().c_str()));
}
} else {
- throw std::runtime_error(make_string("Expected Array, got '%s'", cInfo.name()));
+ throw std::runtime_error(make_string("Expected Array, got '%s'", vespalib::getClassName(val).c_str()));
}
break;
default:
diff --git a/searchlib/src/vespa/searchlib/memoryindex/url_field_inverter.cpp b/searchlib/src/vespa/searchlib/memoryindex/url_field_inverter.cpp
index 326b7b0967a..69120c901f7 100644
--- a/searchlib/src/vespa/searchlib/memoryindex/url_field_inverter.cpp
+++ b/searchlib/src/vespa/searchlib/memoryindex/url_field_inverter.cpp
@@ -6,7 +6,6 @@
#include <vespa/document/fieldvalue/arrayfieldvalue.h>
#include <vespa/document/fieldvalue/stringfieldvalue.h>
#include <vespa/document/fieldvalue/weightedsetfieldvalue.h>
-#include <vespa/searchlib/common/sort.h>
#include <vespa/searchlib/util/url.h>
#include <vespa/vespalib/text/lowercase.h>
#include <vespa/vespalib/text/utf8.h>
@@ -122,7 +121,7 @@ UrlFieldInverter::processUrlSubField(FieldInverter *inverter,
if (!sfv) {
return;
}
- if (!sfv->inherits(IDENTIFIABLE_CLASSID(StringFieldValue))) {
+ if (!sfv->isA(FieldValue::Type::STRING)) {
LOG(error,
"Illegal field type %s for URL subfield %s, expected string",
sfv->getDataType()->getName().c_str(),
@@ -155,13 +154,13 @@ UrlFieldInverter::processAnnotatedUrlField(const StructFieldValue & field)
void
UrlFieldInverter::processUrlField(const FieldValue &url_field)
{
- if (url_field.inherits(IDENTIFIABLE_CLASSID(StringFieldValue))) {
+ if (url_field.isA(FieldValue::Type::STRING)) {
const vespalib::string &url_str =
static_cast<const StringFieldValue &>(url_field).getValue();
processUrlOldStyle(url_str);
return;
}
- assert(url_field.getClass().id() == StructFieldValue::classId);
+ assert(url_field.type() == FieldValue::Type::STRUCT);
const auto &field = static_cast<const StructFieldValue &>(url_field);
const FieldValue::UP all_val = field.getValue("all");
@@ -173,7 +172,7 @@ UrlFieldInverter::processUrlField(const FieldValue &url_field)
return;
}
- if (!all_val->inherits(IDENTIFIABLE_CLASSID(StringFieldValue))) {
+ if (!all_val->isA(FieldValue::Type::STRING)) {
LOG(error,
"Illegal field type %s for URL subfield all, expected string",
all_val->getDataType()->getName().c_str());
@@ -275,7 +274,7 @@ UrlFieldInverter::processWeightedSetUrlField(const WeightedSetFieldValue &field)
for (const auto & el : field) {
const FieldValue &key = *el.first;
const FieldValue &xweight = *el.second;
- assert(xweight.getClass().id() == IntFieldValue::classId);
+ assert(xweight.type() == FieldValue::Type::INT);
int32_t weight = xweight.getAsInt();
startElement(weight);
processUrlField(key);
@@ -298,7 +297,6 @@ isUriType(const DataType &type)
void
UrlFieldInverter::invertUrlField(const FieldValue &val)
{
- const vespalib::Identifiable::RuntimeClass & cInfo(val.getClass());
switch (_collectionType) {
case CollectionType::SINGLE:
if (isUriType(*val.getDataType())) {
@@ -309,30 +307,29 @@ UrlFieldInverter::invertUrlField(const FieldValue &val)
throw std::runtime_error(make_string("Expected URI struct, got '%s'", val.getDataType()->getName().c_str()));
}
break;
- case CollectionType::WEIGHTEDSET:
- if (cInfo.id() == WeightedSetFieldValue::classId) {
- const auto &wset = static_cast<const WeightedSetFieldValue &>(val);
- if (isUriType(wset.getNestedType())) {
- processWeightedSetUrlField(wset);
- } else {
- throw std::runtime_error(make_string("Expected wset of URI struct, got '%s'", wset.getNestedType().getName().c_str()));
- }
+ case CollectionType::WEIGHTEDSET: {
+ assert(val.isA(FieldValue::Type::WSET));
+ const auto &wset = static_cast<const WeightedSetFieldValue &>(val);
+ if (isUriType(wset.getNestedType())) {
+ processWeightedSetUrlField(wset);
} else {
- throw std::runtime_error(make_string("Expected weighted set, got '%s'", cInfo.name()));
+ throw std::runtime_error(
+ make_string("Expected wset of URI struct, got '%s'", wset.getNestedType().getName().c_str()));
}
break;
- case CollectionType::ARRAY:
- if (cInfo.id() == ArrayFieldValue::classId) {
- const auto &arr = static_cast<const ArrayFieldValue&>(val);
- if (isUriType(arr.getNestedType())) {
- processArrayUrlField(arr);
- } else {
- throw std::runtime_error(make_string("Expected array of URI struct, got '%s' (%s)", arr.getNestedType().getName().c_str(), arr.getNestedType().toString(true).c_str()));
- }
+ }
+ case CollectionType::ARRAY: {
+ assert(val.isA(FieldValue::Type::ARRAY));
+ const auto &arr = static_cast<const ArrayFieldValue &>(val);
+ if (isUriType(arr.getNestedType())) {
+ processArrayUrlField(arr);
} else {
- throw std::runtime_error(make_string("Expected Array, got '%s'", cInfo.name()));
+ throw std::runtime_error(
+ make_string("Expected array of URI struct, got '%s' (%s)", arr.getNestedType().getName().c_str(),
+ arr.getNestedType().toString(true).c_str()));
}
break;
+ }
default:
break;
}