summaryrefslogtreecommitdiffstats
path: root/searchcommon
diff options
context:
space:
mode:
authorGeir Storli <geirst@yahooinc.com>2022-03-29 14:35:56 +0000
committerGeir Storli <geirst@yahooinc.com>2022-03-29 14:37:01 +0000
commitf11ab47d3ab497a63cad4538cb82d9492bc871af (patch)
treea7d8f62a1d3bbca9186379e8f6197c960de29f03 /searchcommon
parentf18559088933e5c7309c33455fbe222fdbb476ab (diff)
Add APIs that provide read access to raw data stored in multi-value attributes.
Diffstat (limited to 'searchcommon')
-rw-r--r--searchcommon/src/vespa/searchcommon/attribute/i_multi_value_attribute.h32
-rw-r--r--searchcommon/src/vespa/searchcommon/attribute/i_multi_value_read_view.h41
-rw-r--r--searchcommon/src/vespa/searchcommon/attribute/iattributevector.h8
3 files changed, 81 insertions, 0 deletions
diff --git a/searchcommon/src/vespa/searchcommon/attribute/i_multi_value_attribute.h b/searchcommon/src/vespa/searchcommon/attribute/i_multi_value_attribute.h
new file mode 100644
index 00000000000..5831380eaae
--- /dev/null
+++ b/searchcommon/src/vespa/searchcommon/attribute/i_multi_value_attribute.h
@@ -0,0 +1,32 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include "i_multi_value_read_view.h"
+
+namespace search::attribute {
+
+/**
+ * Interface that provides read views for different multi-value attribute types.
+ *
+ * The type-safe down-cast functions only return a valid pointer when that particular type is supported.
+ * Otherwise a nullptr is returned.
+ */
+class IMultiValueAttribute {
+ virtual ~IMultiValueAttribute() {}
+ virtual const IArrayReadView<int8_t>* as_int8_array() const = 0;
+ virtual const IArrayReadView<int32_t>* as_int32_array() const = 0;
+ virtual const IArrayReadView<int64_t>* as_int64_array() const = 0;
+ virtual const IArrayReadView<float>* as_float_array() const = 0;
+ virtual const IArrayReadView<double>* as_double_array() const = 0;
+
+ virtual const IWeightedSetReadView<int8_t>* as_int8_wset() const = 0;
+ virtual const IWeightedSetReadView<int32_t>* as_int32_wset() const = 0;
+ virtual const IWeightedSetReadView<int64_t>* as_int64_wset() const = 0;
+ virtual const IWeightedSetReadView<float>* as_float_wset() const = 0;
+ virtual const IWeightedSetReadView<double>* as_double_wset() const = 0;
+
+ virtual const IWeightedSetEnumReadView* as_enum_wset() const = 0;
+};
+
+}
diff --git a/searchcommon/src/vespa/searchcommon/attribute/i_multi_value_read_view.h b/searchcommon/src/vespa/searchcommon/attribute/i_multi_value_read_view.h
new file mode 100644
index 00000000000..df69c5cfde8
--- /dev/null
+++ b/searchcommon/src/vespa/searchcommon/attribute/i_multi_value_read_view.h
@@ -0,0 +1,41 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include "multivalue.h"
+#include <vespa/vespalib/datastore/atomic_entry_ref.h>
+#include <vespa/vespalib/util/arrayref.h>
+
+namespace search::attribute {
+
+/**
+ * Read view for the raw data stored in a multi-value attribute.
+ * @tparam MultiValueType The multi-value type of the raw data to access.
+ */
+template <typename MultiValueType>
+class IMultiValueReadView {
+public:
+ virtual ~IMultiValueReadView() {}
+ virtual vespalib::ConstArrayRef<MultiValueType> get_raw_values(uint32_t docid) const = 0;
+};
+
+/**
+ * Read view for the raw data stored in an array attribute.
+ * @tparam T The value type of the raw data to access.
+ */
+template <typename T>
+using IArrayReadView = IMultiValueReadView<multivalue::Value<T>>;
+
+/**
+ * Read view for the raw data stored in a weighted set attribute.
+ * @tparam T The value type of the raw data to access.
+ */
+template <typename T>
+using IWeightedSetReadView = IMultiValueReadView<multivalue::WeightedValue<T>>;
+
+/**
+ * Read view for the raw data stored in an enumerated weighted set attribute.
+ */
+using IWeightedSetEnumReadView = IMultiValueReadView<multivalue::WeightedValue<vespalib::datastore::AtomicEntryRef>>;
+
+};
diff --git a/searchcommon/src/vespa/searchcommon/attribute/iattributevector.h b/searchcommon/src/vespa/searchcommon/attribute/iattributevector.h
index b28855ae4f4..fa91f301b92 100644
--- a/searchcommon/src/vespa/searchcommon/attribute/iattributevector.h
+++ b/searchcommon/src/vespa/searchcommon/attribute/iattributevector.h
@@ -19,6 +19,7 @@ namespace search::tensor {
namespace search::attribute {
+class IMultiValueAttribute;
class ISearchContext;
class SearchContextParams;
@@ -308,6 +309,13 @@ public:
virtual const tensor::ITensorAttribute *asTensorAttribute() const = 0;
/**
+ * Type-safe down-cast to a multi-value attribute.
+ *
+ * @return multi-value attribute or nullptr if not supported.
+ */
+ virtual const IMultiValueAttribute* as_multi_value_attribute() const = 0;
+
+ /**
* Returns the basic type of this attribute vector.
*
* @return basic type